Beispiel #1
0
 def test_howto_example_drawing_text(self):
     """tests the first canvas example from howto"""
     test_image = get_image("canvas_2.png")
     o = get_mock_output()
     c = Canvas(o, name=c_name)
     c.text("Hello world", (0, 0))
     assert(imgs_are_equal(c.get_image(), test_image))
Beispiel #2
0
 def test_howto_example_invert_region(self):
     """tests the sixth canvas example from howto"""
     test_image = get_image("canvas_6.png")
     o = get_mock_output()
     c = Canvas(o, name=c_name)
     c.text("Hello world", (5, 5))
     c.invert_rect((35, 5, 80, 17))
     assert(imgs_are_equal(c.get_image(), test_image))
Beispiel #3
0
 def test_invert_rgb(self):
     """tests that rgb canvas inversion doesn't fail with RGB displays and returns a valid RGB image"""
     test_image = get_image("canvas_10.png")
     o = get_mock_output(mode="RGB")
     c = Canvas(o, name=c_name)
     c.text("Hello world", (5, 5))
     c.invert()
     assert (c.get_image().mode == o.device_mode)
     assert (imgs_are_equal(c.get_image(), test_image.convert("RGB")))
Beispiel #4
0
 def test_paste(self):
     test_image = get_image("canvas_13.png")
     image_to_paste = get_image("canvas_14.png")
     o = get_mock_output(mode="RGB")
     c = Canvas(o, name=c_name)
     c.text("Hello world", (16, 16))
     c.paste(image_to_paste)
     assert (c.get_image().mode == o.device_mode)
     assert (imgs_are_equal(c.get_image(), test_image.convert("RGB")))
Beispiel #5
0
 def test_invert(self):
     """tests that inversion works with default display"""
     test_image = get_image("canvas_10.png")
     o = get_mock_output()
     c = Canvas(o, name=c_name)
     c.text("Hello world", (5, 5))
     c.invert()
     assert (c.get_image().mode == o.device_mode)
     assert (imgs_are_equal(c.get_image(), test_image))
Beispiel #6
0
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()
Beispiel #7
0
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()
Beispiel #8
0
def show(lines):
    if len(lines) < 4:
        max = len(lines)
    else:
        max = 4
    index = values.get_index()
    if index == 1:
        index = 2  # row 3
    c = Canvas(o)
    for n in range(max):
        y = n * char_height
        c.text(lines[n], (0, y), font=font1)
        if n == index and blink.isSet():  # row 0 or 3 && blink
            c.invert_rect(
                (127 - 8, y + char_height - 4, 127, y + char_height - 1))
    c.display()
Beispiel #9
0
 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))
Beispiel #10
0
 def refresh(self):
     c = Canvas(self.o)
     charwidth = 20
     charheight = 32
     font = c.load_font("Fixedsys62.ttf", charheight)
     pin_width = len(self.pin) * charwidth
     x_offset = (self.o.width - pin_width) / 2
     y_offset = 15
     c.line((x_offset, y_offset + charheight, str(-x_offset),
             y_offset + charheight))
     c.line((x_offset, y_offset + charheight, x_offset,
             y_offset + charheight - 5))
     for x in range(len(self.pin)):
         i = x + 1
         if x in range(len(self.value)):
             c.text("*", (x_offset + charwidth * x, y_offset), font=font)
         c.line((x_offset + charwidth * i, y_offset + charheight,
                 x_offset + charwidth * i, y_offset + charheight - 5))
     self.o.display_image(c.get_image())
Beispiel #11
0
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
Beispiel #12
0
 def refresh(self):
     now = datetime.now()
     hhmm = now.strftime("%H:%M")
     ss = now.strftime("%S")
     ddmmyy = now.strftime("%d%m%y")
     c = Canvas(self.o)
     #c.line((0, 8, c.width, 8), fill="white")
     c.text(hhmm, (5, 8), font=("Fixedsys62.ttf", 32))
     c.text(ss, (87, 23))
     c.text(ddmmyy, (90, 12))
     c.text("0 notifications", (10, 39))
     self.draw_battery_icon(c)
     self.draw_network_icon(c)
     image = c.get_image()
     self.p.runcall( self.o.display_image, image )
Beispiel #13
0
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
Beispiel #14
0
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
Beispiel #15
0
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
Beispiel #16
0
 def learn_about_help_icon(self):
     o = HelpOverlay("test")
     c = Canvas(self.o)
     c.text("See this icon?->", (1, 1))
     c.text("When it appears,", (3, 10))
     c.text("press F5 to get help", (3, 19))
     c.text("Try now, or", (3, 28))
     c.text("press ENTER to skip", (3, 37))
     if not is_emulator():
         c.text("F5:", (5, 51))
         c.paste(local_path("f5_button_location.png"), (30, 50),
                 invert=True)
     o.draw_icon(c)
     Refresher(c.get_image,
               self.i,
               self.o,
               keymap={
                   "KEY_ENTER": "deactivate",
                   "KEY_F5": self.on_help_button_press
               }).activate()
     return True
Beispiel #17
0
    def learn_about_5_buttons(self):
        c = Canvas(self.o)
        c.centered_text(
            "Let's go through\nthe main buttons\nand their meanings")
        GraphicsPrinter(c.get_image(), self.i, self.o, 5, invert=False)
        c.clear()
        c.centered_text("Press the buttons\nto test\nThen ENTER\nto continue")
        GraphicsPrinter(c.get_image(), self.i, self.o, 5, invert=False)
        c.clear()
        # First, show the left/right/up/down buttons
        # TODO: different behaviour for ZP and emulator?
        c.text("Enter", (48, 22))
        c.text("Continue", (39, 30))
        c.text("Left", (2, 18))
        c.text("Back", (2, 26))
        c.text("Cancel", (2, 34))
        c.text("Right", (92, 22))
        c.text("Option", (90, 30))
        c.text("Up", (56, 5))
        c.text("Down", (52, "-18"))
        image = c.get_image()

        def process_key(key, state):
            # invert/deinvert areas on the canvas when buttons are pressed/released
            # on drivers that don't support key states, will toggle inversion on every press
            # on drivers that support key states, will "highlight" the buttons pressed
            print(key, state)
            if state != KEY_HELD:
                if key == "KEY_UP":
                    c.invert_rect((64 - 20, 2, 64 + 20, 22))
                elif key == "KEY_DOWN":
                    c.invert_rect((64 - 20, "-2", 64 + 20, "-22"))
                elif key == "KEY_LEFT":
                    c.invert_rect((2, 32 - 15, 38, 32 + 15))
                elif key == "KEY_RIGHT":
                    c.invert_rect(("-2", 32 - 10, "-40", 32 + 10))

        keys = ["KEY_UP", "KEY_DOWN", "KEY_LEFT", "KEY_RIGHT"]
        keymap = {"KEY_ENTER": "deactivate"}
        for key in keys:
            cb = cb_needs_key_state(lambda st, x=key: process_key(x, st))
            keymap[key] = cb
        Refresher(c.get_image,
                  self.i,
                  self.o,
                  override_left=False,
                  keymap=keymap).activate()
        return True
Beispiel #18
0
 def learn_about_zeromenu(self):
     c = Canvas(self.o)
     if is_emulator():
         c.text("Press F11 to get", (1, 1))
     else:
         c.text("Press PROG2 to get", (1, 1))
     c.text("a shortcut menu -", (3, 10))
     c.text("ZeroMenu. You can", (3, 19))
     c.text("add apps to it", (3, 28))
     c.text("for quick launch", (3, 37))
     if not is_emulator():
         c.text("PROG2:", (5, 51))
         c.paste(local_path("prog2_button_location.png"), (40, 50),
                 invert=True)
     Refresher(c.get_image,
               self.i,
               self.o,
               keymap={
                   "KEY_ENTER": "deactivate",
                   "KEY_PROG2": self.on_zeromenu_button_press
               }).activate()
     return True