def fill_head(self): with self.canvas.fill(color=rgb(149, 119, 73)) as head_filler: head_filler.move_to(112, 103) head_filler.line_to(112, 113) head_filler.ellipse(73, 114, 39, 47, 0, 0, math.pi) head_filler.line_to(35, 84) head_filler.arc(65, 84, 30, math.pi, 3 * math.pi / 2) head_filler.arc(82, 84, 30, 3 * math.pi / 2, 2 * math.pi)
def draw_text(self): x = 32 y = 185 font = toga.Font(family=SANS_SERIF, size=20) width, height = font.measure('Tiberius', tight=True) with self.canvas.stroke(line_width=4.0) as rect_stroker: rect_stroker.rect(x - 10, y - height + 2, width, height + 2) with self.canvas.fill(color=rgb(149, 119, 73)) as text_filler: text_filler.write_text('Tiberius', x, y, font)
def draw_horns(self): with self.canvas.context() as r_horn: with r_horn.fill(color=rgb(212, 212, 212)) as r_horn_filler: r_horn_filler.move_to(112, 99) r_horn_filler.quadratic_curve_to(145, 65, 139, 36) r_horn_filler.quadratic_curve_to(130, 60, 109, 75) with r_horn.stroke(line_width=4.0) as r_horn_stroker: r_horn_stroker.move_to(112, 99) r_horn_stroker.quadratic_curve_to(145, 65, 139, 36) r_horn_stroker.quadratic_curve_to(130, 60, 109, 75) with self.canvas.context() as l_horn: with l_horn.fill(color=rgb(212, 212, 212)) as l_horn_filler: l_horn_filler.move_to(35, 99) l_horn_filler.quadratic_curve_to(2, 65, 6, 36) l_horn_filler.quadratic_curve_to(17, 60, 37, 75) with l_horn.stroke(line_width=4.0) as l_horn_stroker: l_horn_stroker.move_to(35, 99) l_horn_stroker.quadratic_curve_to(2, 65, 6, 36) l_horn_stroker.quadratic_curve_to(17, 60, 37, 75)
def test_stroke_modify(self): with self.testing_canvas.stroke(color=BLANCHEDALMOND, line_width=5.0) as stroker: stroker.color = REBECCAPURPLE stroker.line_width = 1 self.testing_canvas.redraw() self.assertActionPerformedWith(self.testing_canvas, "stroke", color=rgb(102, 51, 153), line_width=1)
def draw_nostrils(self): with self.canvas.fill(color=rgb(212, 212, 212)) as nose_filler: nose_filler.move_to(45, 145) nose_filler.bezier_curve_to(51, 123, 96, 123, 102, 145) nose_filler.ellipse(73, 114, 39, 47, 0, math.pi / 4, 3 * math.pi / 4) with self.canvas.fill() as nostril_filler: nostril_filler.arc(63, 140, 3) nostril_filler.arc(83, 140, 3) with self.canvas.stroke(line_width=4.0) as nose_stroker: nose_stroker.move_to(45, 145) nose_stroker.bezier_curve_to(51, 123, 96, 123, 102, 145)
def test_fill_modify(self): with self.testing_canvas.fill( color="rgb(0, 255, 0)", fill_rule="nonzero", preserve=False ) as filler: filler.color = REBECCAPURPLE filler.fill_rule = "evenodd" filler.preserve = True self.testing_canvas.redraw() self.assertActionPerformedWith( self.testing_canvas, "fill", color=rgb(102, 51, 153), fill_rule="evenodd", preserve=True, )
def test_set_background_color(self): color = '#ffffff' root = TestNode('app', style=Pack(background_color=color)) root.style.reapply() root._impl.set_background_color.assert_called_once_with( rgb(255, 255, 255))