def render_gs_anchor(pdf: PDF, variant, score=0): ''' Renders the gs anchor box for a given question/question part. -1: Empty box. Intended for template variants. 0: Completely incorrect answer. < 1: Partially correct answer. 1: Completely correct answer. ''' if score == -1: a_cfg = get_cfg('gsAnchor', 'blank') elif score == 0: a_cfg = get_cfg('gsAnchor', 'incorrect') elif score < 1: a_cfg = get_cfg('gsAnchor', 'partial') elif score == 1: a_cfg = get_cfg('gsAnchor', 'correct') else: return fill = a_cfg['fill'] text = f'{a_cfg["text"]}: {score}' if score > -1 else a_cfg['text'] pdf.set_font(cfg['font']['body']['font']) pdf.set_fill_color(fill['r'], fill['g'], fill['b']) pdf.cell(lineWidth, h=get_cfg('gsAnchor', 'height'), txt=text, fill=True) pdf.ln()
def draw_line(pdf: PDF, width=lineWidth, color=get_cfg('font', 'header', 'line', default={"r": 0, "b": 0, "g": 0})): ''' draws a line on the page. by default, the line is the page width. ''' pdf.ln(6) pdf.set_line_width(0.5) pdf.set_draw_color(color['r'], color['b'], color['g']) pdf.line(10, pdf.get_y(), 12 + width, pdf.get_y()) pdf.ln(6)
def render_ans(self, pdf: PDF): pdf.cell(lineWidth, lineHeight, txt=f'{self.key}: {self.val}') pdf.ln() pdf.cell(lineWidth, lineHeight, txt=f'Variables: {self.vars}')