def isp_pinouts_page(o): isp = [['miso', 'vcc'], ['sck', 'mosi'], ['rst', 'gnd']] c = Canvas(o) headline = "ISP header pinout" ctb = c.get_centered_text_bounds(headline) c.text(headline, (ctb.left, 2)) c = draw_pinout(c, o, isp, lo=2) c = draw_pinout(c, o, isp, lo=2, reversed=True) ctb = c.get_centered_text_bounds("cable") c.text("board", (ctb.left / 2 - 5, "-15")) c.text("cable", (ctb.left / 2 + c.width / 2 - 5, "-15")) return c
def uap_pinouts_page(o): uap = [['mosi', 'vcc'], ['nc', 'txd'], ['rst', 'rxd'], ['sck', 'nc'], ['miso', 'gnd']] c = Canvas(o) headline = "USBASP pinout" ctb = c.get_centered_text_bounds(headline) c.text(headline, (ctb.left, 0)) c = draw_pinout(c, o, uap, lo=2, ph=8, tto=-1) c = draw_pinout(c, o, uap, lo=2, ph=8, tto=-1, reversed=True) ctb = c.get_centered_text_bounds("cable") c.text("board", (ctb.left / 2 - 5, str(-o.char_height - 2))) c.text("cable", (ctb.left / 2 + c.width / 2 - 5, str(-o.char_height - 2))) return c
def zp_pinouts_page(o): zpp = [['vcc'], ['gnd'], ['mosi'], ['miso'], ['sck'], ['rst']] c = Canvas(o) headline = "ZeroPhone" ctb = c.get_centered_text_bounds(headline) c.text(headline, (ctb.left + 10, 2)) c.text("Gamma pinout", (ctb.left + 10, 12)) c.text("(side header)", (ctb.left + 10, 22)) c = draw_pinout(c, o, zpp, lo=5) return c
def test_howto_example_drawing_centered_text(self): """tests the third text canvas example from howto""" test_image = get_image("canvas_8.png") o = get_mock_output() c = Canvas(o, name=c_name) ctc = c.get_centered_text_bounds("a") c.text("a", (ctc.left, 0)) c.text("b", (str(ctc.left-ctc.right), ctc.top)) c.text("c", (ctc.left, str(ctc.top-ctc.bottom))) c.text("d", (0, ctc.top)) assert(imgs_are_equal(c.get_image(), test_image))
def render_totp(name, secret): c = Canvas(o) totp_font = ("Fixedsys62.ttf", 32) try: totp_value = pyotp.TOTP(secret).now() except TypeError: totp_font = ("Fixedsys62.ttf", 16) totp_value = "Incorrect\nsecret!" c.centered_text(totp_value, font=totp_font) left_coord = c.get_centered_text_bounds(name).left c.text(name, (left_coord, 5)) return c.get_image()
def pk2_pinouts_page(o): pkp = [['rst'], ['vcc'], ['gnd'], ['miso'], ['sck'], ['mosi']] c = Canvas(o) headline = "PICkit2" ctb = c.get_centered_text_bounds(headline) c.text(headline, (ctb.left + 10, 2)) c.text("pinout", (ctb.left + 10, 12)) c = draw_pinout(c, o, pkp, lo=5) return c pk2 = [['mosi', 'vcc'], ['nc', 'txd'], ['rst', 'rxd'], ['sck', 'nc'], ['miso', 'gnd']] c = Canvas(o) headline = "PicKit2 pinout" ctb = c.get_centered_text_bounds(headline) c.text(headline, (ctb.left, 0)) c = draw_pinout(c, o, uap, lo=2, ph=8, tto=-1) c = draw_pinout(c, o, uap, lo=2, ph=8, tto=-1, reversed=True) ctb = c.get_centered_text_bounds("cable") c.text("board", (ctb.left / 2 - 5, str(-o.char_height - 2))) c.text("cable", (ctb.left / 2 + c.width / 2 - 5, str(-o.char_height - 2))) return c
def test_drawing_custom_shape_text(self): """tests the custom shape text drawing""" test_image = get_image("canvas_8.png") o = get_mock_output() c = Canvas(o, name=c_name) ctc = c.get_centered_text_bounds("a") def coords_cb(i, ch): return [(ctc.left, 0), (str(ctc.left - ctc.right), ctc.top), (ctc.left, str(ctc.top - ctc.bottom)), (0, ctc.top)][i] c.custom_shape_text("abcd", coords_cb) assert (imgs_are_equal(c.get_image(), test_image))
def make_image_from_status(o, status, success_message=None): c = Canvas(o) if status[0] == "Success": c.bitmap((44, 3), get_yes_icon(), fill=c.default_color) if success_message: status.append(success_message) else: c.bitmap((44, 3), get_no_icon(), fill=c.default_color) top_start = 45 top_increment = 10 for i, s in enumerate(status[1:]): ctb = c.get_centered_text_bounds(s) c.text(s, (ctb.left, top_start + top_increment * i)) return c.get_image()