def start_btn_init(self):
        """
        Initialize the Start/Stop button on the screen
        """
        this = self

        def start_btn_hander(obj, event):
            if event == lv.EVENT.CLICKED:
                if this.has_started:  # Clicked to stop the process
                    # popup to let user confirm the stop action
                    this.popup_confirm_stop()
                else:  # Clicked to start the process
                    this.set_reflow_process_on(True)

        start_btn = lv.btn(self.main_scr)
        start_btn.set_size(140, 60)
        start_btn.set_event_cb(start_btn_hander)
        start_btn.align(self.timer_label, lv.ALIGN.IN_TOP_RIGHT, 190, 0)
        style_start = lv.style_t()
        lv.style_copy(style_start, lv.style_btn_rel)
        style_start.text.font = lv.font_roboto_28
        start_label = lv.label(start_btn)
        start_label.set_text(lv.SYMBOL.PLAY + ' Start')
        start_label.set_style(lv.label.STYLE.MAIN, style_start)
        return start_btn, start_label
Exemple #2
0
 def create_style(self, colour=(0x00, 0x3b, 0x75), width=3, rounded=1):
     style_line = lv.style_t()
     lv.style_copy(style_line, lv.style_plain)
     style_line.line.color = lv.color_make(colour[0], colour[1], colour[2])
     style_line.line.width = width
     style_line.line.rounded = rounded
     return style_line
Exemple #3
0
def add_mnemonic_table(mnemonic, y=PADDING, scr=None):
    if scr is None:
        scr = lv.scr_act()

    cell_style = lv.style_t()
    lv.style_copy(cell_style, styles["theme"].style.label.prim)
    cell_style.body.opa = 0
    cell_style.text.font = lv.font_roboto_22

    num_style = lv.style_t()
    lv.style_copy(num_style, cell_style)
    num_style.text.opa = lv.OPA._40

    table = lv.table(scr)
    table.set_col_cnt(4)
    table.set_row_cnt(12)
    table.set_col_width(0, 50)
    table.set_col_width(2, 50)
    table.set_col_width(1, 150)
    table.set_col_width(3, 150)

    table.set_style(lv.page.STYLE.BG, cell_style)
    table.set_style(lv.table.STYLE.CELL1, cell_style)
    table.set_style(lv.table.STYLE.CELL2, num_style)

    for i in range(12):
        table.set_cell_value(i, 0, "%d" % (i + 1))
        table.set_cell_value(i, 2, "%d" % (i + 13))
        table.set_cell_type(i, 0, lv.table.STYLE.CELL2)
        table.set_cell_type(i, 2, lv.table.STYLE.CELL2)
    table.align(scr, lv.ALIGN.IN_TOP_MID, 0, y)

    table_set_mnemonic(table, mnemonic)

    return table
Exemple #4
0
 def _set_custom_style(self):
     style = lv.style_t()
     lv.style_copy(style, self.lv_obj.get_style(lv.cont.STYLE.MAIN))
     style.body.main_color = lv.color_make(0xC0, 0xC0, 0xC0)
     style.body.grad_color = lv.color_make(0x4F, 0x52, 0x57)
     style.body.radius = 0
     self.lv_obj.set_style(lv.cont.STYLE.MAIN, style)
Exemple #5
0
def prompt_tx(title, data, ok=None, cancel=None):
    message = ""
    scr = prompt(title, message, ok=ok, cancel=cancel)
    obj = scr.message
    obj.set_y(0)
    style = lv.style_t()
    lv.style_copy(style, scr.message.get_style(0))
    style.text.font = lv.font_roboto_mono_28

    for out in data["send_outputs"]:
        addr = format_addr(
                    format_addr(
                        out["address"], letters=6, separator=" "
                    ), 
                    letters=21, separator="\n"
                )
        lbl = add_label("%u sat ( %g BTC ) to" % (out["value"], out["value"]/1e8), scr=scr)
        lbl.align(obj, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
        addrlbl = add_label(addr, scr=scr)
        addrlbl.set_style(0, style)
        addrlbl.align(lbl, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
        obj = addrlbl

    lbl = lv.label(scr)
    lbl.set_text("Fee: %u satoshi - %.1f" % (data["fee"], 100*data["fee"]/data["spending"]) + "%")
    lbl.align(obj, lv.ALIGN.OUT_BOTTOM_MID, 0, 50)
    return scr
    def __init__(self, wallet, network, idx=None, branch_index=0):
        self.wallet = wallet
        self.network = network
        self.idx = wallet.unused_recv
        addr, gap = wallet.get_address(self.idx,
                                       network=network,
                                       branch_index=branch_index)
        super().__init__(
            "    " + wallet.name + "  #708092 " + lv.SYMBOL.EDIT,
            format_addr(addr, words=4),
            "bitcoin:" + addr,
            qr_width=350,
        )
        self.title.set_recolor(True)
        self.title.set_click(True)
        self.title.set_event_cb(on_release(self.rename))
        self.policy = add_label(wallet.policy, y=55, style="hint", scr=self)

        style = lv.style_t()
        lv.style_copy(style, self.message.get_style(0))
        style.text.font = lv.font_roboto_mono_22
        self.message.set_style(0, style)

        # index
        self.branch_index = branch_index
        self.note = add_label("%s address #%d" % (self.prefix, self.idx),
                              y=80,
                              style="hint",
                              scr=self)
        self.qr.align(self.note, lv.ALIGN.OUT_BOTTOM_MID, 0, 15)
        self.message.align(self.qr, lv.ALIGN.OUT_BOTTOM_MID, 0, 15)

        # warning label for address gap limit
        self.warning = add_label("", scr=self)
        self.warning.align(self.message, lv.ALIGN.OUT_BOTTOM_MID, 0, 15)
        style = lv.style_t()
        lv.style_copy(style, self.note.get_style(0))
        style.text.color = lv.color_hex(0xFF9A00)
        self.warning.set_style(0, style)

        # delbtn = add_button("Delete wallet", on_release(cb_del), y=610)
        self.prv = add_button(lv.SYMBOL.LEFT, on_release(self.prev), scr=self)
        self.nxt = add_button(lv.SYMBOL.RIGHT, on_release(self.next), scr=self)
        if self.idx <= 0:
            self.prv.set_state(lv.btn.STATE.INA)
        self.prv.set_width(70)
        self.prv.align(self.qr, lv.ALIGN.OUT_LEFT_MID, -20, 0)
        self.prv.set_x(0)
        self.nxt.set_width(70)
        self.nxt.align(self.qr, lv.ALIGN.OUT_RIGHT_MID, 20, 0)
        self.nxt.set_x(HOR_RES - 70)

        self.menubtn = add_button(lv.SYMBOL.SETTINGS + " Settings",
                                  on_release(self.show_menu),
                                  scr=self)
        self.menubtn.align(self.close_button, lv.ALIGN.OUT_TOP_MID, 0, -20)

        if idx is not None:
            self.idx = idx
            self.update_address()
Exemple #7
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        style = lv.style_t()
        lv.style_copy(style, qr_style)
        style.text.font = lv.font_roboto_16
        style.text.color = lv.color_hex(0x192432)

        self._autoplay = True

        self.qr = lvqr.QRCode(self)
        self._text = "Text"
        self.version = self.QR_VERSION

        self._original_size = None
        self._press_start = None

        self.create_density_controls(style)
        self.create_playback_controls(style)

        self.note = lv.label(self)
        self.note.set_style(0, style)
        self.note.set_text("")
        self.note.set_align(lv.label.ALIGN.CENTER)

        self.set_text(self._text)
        self.task = asyncio.create_task(self.animate())
        self.set_event_cb(self.cb)
 def set_text(self, text="Text"):
     if self._text != text:
         print("QR on screen:", text)
     self._text = text
     qr = qrcode.encode_to_string(text)
     size = int(math.sqrt(len(qr))) # + 4 clear space on every side
     width = self.get_width()
     scale = width//size
     sizes = range(1,10)
     fontsize = [s for s in sizes if s < scale or s == 1][-1]
     font = getattr(lv, "square%d" % fontsize)
     style = lv.style_t()
     lv.style_copy(style, qr_style)
     style.text.font = font
     pad = 4*fontsize
     style.body.radius = fontsize
     style.body.padding.top = pad
     style.body.padding.left = pad
     style.body.padding.right = pad
     style.body.padding.bottom = pad-fontsize # there is \n at the end
     self.set_style(lv.label.STYLE.MAIN, style)
     self.set_body_draw(True)
     super().set_text(qr)
     del qr
     gc.collect()
    def popup_confirm_stop(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_stop = lv.mbox(bg)
        popup_stop.set_text(
            'Do you really want to stop the soldering process?')
        btns = ['OK', 'Cancel', '']
        popup_stop.add_btns(btns)
        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                if popup_stop.get_active_btn() == 0:
                    this.set_reflow_process_on(False)
                else:
                    pass

                bg.del_async()
                popup_stop.start_auto_close(5)

        popup_stop.set_event_cb(event_handler)
        popup_stop.align(None, lv.ALIGN.CENTER, 0, 0)
Exemple #10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.words = [""]
        # styles
        cell_style = lv.style_t()
        lv.style_copy(cell_style, styles["theme"].style.label.prim)
        cell_style.body.opa = 0
        cell_style.text.font = lv.font_roboto_22

        num_style = lv.style_t()
        lv.style_copy(num_style, cell_style)
        num_style.text.opa = lv.OPA._40

        self.set_col_cnt(4)
        self.set_row_cnt(12)
        self.set_col_width(0, 50)
        self.set_col_width(2, 50)
        self.set_col_width(1, 150)
        self.set_col_width(3, 150)

        self.set_style(lv.page.STYLE.BG, cell_style)
        self.set_style(lv.table.STYLE.CELL1, cell_style)
        self.set_style(lv.table.STYLE.CELL2, num_style)

        for i in range(12):
            self.set_cell_value(i, 0, "%d" % (i+1))
            self.set_cell_value(i, 2, "%d" % (i+13))
            self.set_cell_type(i, 0, lv.table.STYLE.CELL2)
            self.set_cell_type(i, 2, lv.table.STYLE.CELL2)
Exemple #11
0
 def __init__(self, parent, style=None):
     super().__init__(parent)
     if style is None:
         style = lv.style_t()
         lv.style_copy(style, lv.style_transp)
     self.set_style(lv.cont.STYLE.MAIN, style)
     self.set_layout(lv.LAYOUT.COL_L)
     self.set_fit(lv.FIT.FILL)
Exemple #12
0
    def __init__(self, parent, width, height, x, y):
        super().__init__(parent)
        self.set_size(width, height)
        self.set_pos(x, y)

        self.circle_style = lv.style_t()
        lv.style_copy(self.circle_style, lv.style_plain)
        self.circle_style.body.radius = lv.RADIUS.CIRCLE
        self.set_style(self.circle_style)
Exemple #13
0
    def __init__(self, title="Enter your PIN code", note=None, get_word=None, subtitle=None):
        super().__init__()
        self.title = add_label(title, scr=self, y=PADDING, style="title")
        if subtitle is not None:
            lbl = add_label(subtitle, scr=self, style="hint")
            lbl.set_recolor(True)
            lbl.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
        if note is not None:
            lbl = add_label(note, scr=self, style="hint")
            lbl.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 180)
        self.get_word = get_word
        if get_word is not None:
            self.words = add_label(get_word(b""), scr=self)
            self.words.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 210)
        btnm = lv.btnm(self)
        # shuffle numbers to make sure
        # no constant fingerprints left on screen
        buttons = ["%d" % i for i in range(0, 10)]
        btnmap = []
        for j in range(3):
            for i in range(3):
                v = rng.get_random_bytes(1)[0] % len(buttons)
                btnmap.append(buttons.pop(v))
            btnmap.append("\n")
        btnmap = btnmap + [lv.SYMBOL.CLOSE, buttons.pop(), lv.SYMBOL.OK, ""]
        btnm.set_map(btnmap)
        btnm.set_width(HOR_RES)
        btnm.set_height(HOR_RES)
        btnm.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
        # increase font size
        style = lv.style_t()
        lv.style_copy(style, btnm.get_style(lv.btnm.STYLE.BTN_REL))
        style.text.font = lv.font_roboto_28
        # remove feedback on press to avoid sidechannels
        btnm.set_style(lv.btnm.STYLE.BTN_REL, style)
        btnm.set_style(lv.btnm.STYLE.BTN_PR, style)

        self.pin = lv.ta(self)
        self.pin.set_text("")
        self.pin.set_pwd_mode(True)
        style = lv.style_t()
        lv.style_copy(style, styles["theme"].style.ta.oneline)
        style.text.font = lv.font_roboto_28
        style.text.color = styles["theme"].style.scr.text.color
        style.text.letter_space = 15
        self.pin.set_style(lv.label.STYLE.MAIN, style)
        self.pin.set_width(HOR_RES - 2 * PADDING)
        self.pin.set_x(PADDING)
        self.pin.set_y(PADDING + 50)
        self.pin.set_cursor_type(lv.CURSOR.HIDDEN)
        self.pin.set_one_line(True)
        self.pin.set_text_align(lv.label.ALIGN.CENTER)
        self.pin.set_pwd_show_time(0)
        self.pin.align(btnm, lv.ALIGN.OUT_TOP_MID, 0, -150)

        btnm.set_event_cb(feed_rng(self.cb))
Exemple #14
0
 def __init__(self, parent, width, height, x, y):
     self.x = x
     self.board = Button(parent, x=x, y=y, width=width, height=height)
     self.board_style = lv.style_t()
     lv.style_copy(self.board_style,
                   self.board.lv_obj.get_style(lv.label.STYLE.MAIN))
     self.board_style.body.main_color = lv.color_hex(0x000000)
     self.board_style.body.grad_color = lv.color_hex(0x000000)
     self.board_style.body.shadow.width = 0
     self.board.lv_obj.set_style(lv.label.STYLE.MAIN, self.board_style)
    def __init__(self, dev=False, usb=False, note=None):
        super().__init__("Device settings", "")
        if note is not None:
            self.note = add_label(note, style="hint", scr=self)
            self.note.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
        y = 70
        usb_label = add_label("USB communication", y, scr=self.page)
        usb_hint = add_label(
            "If USB is enabled the device will be able "
            "to talk to your computer. This increases "
            "attack surface but sometimes makes it "
            "more convenient to use.",
            y + 40,
            scr=self.page,
            style="hint",
        )
        self.usb_switch = lv.sw(self.page)
        self.usb_switch.align(usb_hint, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
        lbl = add_label(" OFF                              ON  ",
                        scr=self.page)
        lbl.align(self.usb_switch, lv.ALIGN.CENTER, 0, 0)
        if usb:
            self.usb_switch.on(lv.ANIM.OFF)

        # y += 200
        # dev_label = add_label("Developer mode", y, scr=self.page)
        # dev_hint = add_label(
        #     "In developer mode internal flash will "
        #     "be mounted to your computer so you could "
        #     "edit files, but your secrets will be visible as well. "
        #     "Also enables interactive shell through miniUSB port.",
        #     y + 40,
        #     scr=self.page,
        #     style="hint",
        # )
        # self.dev_switch = lv.sw(self.page)
        # self.dev_switch.align(dev_hint, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
        # lbl = add_label(" OFF                              ON  ", scr=self.page)
        # lbl.align(self.dev_switch, lv.ALIGN.CENTER, 0, 0)
        # if dev:
        #     self.dev_switch.on(lv.ANIM.OFF)
        self.confirm_button.set_event_cb(on_release(self.update))
        self.cancel_button.set_event_cb(
            on_release(lambda: self.set_value(None)))

        self.wipebtn = add_button(lv.SYMBOL.TRASH + " Wipe device",
                                  on_release(self.wipe),
                                  scr=self)
        self.wipebtn.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, -140)
        style = lv.style_t()
        lv.style_copy(style, self.wipebtn.get_style(lv.btn.STYLE.REL))
        style.body.main_color = lv.color_hex(0x951E2D)
        style.body.grad_color = lv.color_hex(0x951E2D)
        self.wipebtn.set_style(lv.btn.STYLE.REL, style)
    def popup_calibration(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_cali = lv.mbox(bg)
        popup_cali.set_text('What would you like to calibrate?')
        btns = ['Temp Sensor', '\n', 'Touch Screen', '\n', 'Cancel', '']
        popup_cali.add_btns(btns)

        lv.cont.set_fit(popup_cali, lv.FIT.NONE)
        mbox_style = popup_cali.get_style(popup_cali.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 96
        popup_cali.set_style(popup_cali.STYLE.BTN_REL, popup_cali_style)

        popup_cali.set_height(186)

        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_cali.get_active_btn_text()
                tim = machine.Timer(-1)
                if active_btn_text == 'Temp Sensor':
                    this.config['has_calibrated'] = False
                    with open('config.json', 'w') as f:
                        ujson.dump(this.config, f)
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Touch Screen':
                    uos.remove(this.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                else:
                    tim.deinit()

                bg.del_async()
                popup_cali.start_auto_close(5)

        popup_cali.set_event_cb(event_handler)
        popup_cali.align(None, lv.ALIGN.CENTER, 0, 0)
        self.popup_cali = popup_cali
        return self.popup_cali
Exemple #17
0
 def __init__(self, parent, width, height, x, y):
     super().__init__(parent, width, height, x, y)
     lv.style_copy(self.circle_style, lv.style_plain)
     self.circle_style.body.radius = lv.RADIUS.CIRCLE
     # self.circle_style.body.grad_color = lv.color_hex(0xff0000)
     # self.circle_style.body.main_color = lv.color_hex(0xff0000)
     # self.circle_style.body.border.color = lv.color_hex(0x0000ff)
     self.circle_style.body.main_color = lv.color_hex(0xffffff)
     self.circle_style.body.grad_color = lv.color_hex(0xc0c0c0)
     self.circle_style.body.border.color = lv.color_hex(0x000000)
     self.circle_style.body.border.width = 2
     self.set_style(self.circle_style)
Exemple #18
0
    def __init__(self,
                 buttons=[],
                 title="What do you want to do?",
                 note=None,
                 y0=60,
                 last=None):
        super().__init__()
        y = y0
        self.title = add_label(title, style="title", scr=self)
        if note is not None:
            self.note = add_label(note, style="hint", scr=self)
            self.note.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
            y += self.note.get_height()
        self.page = lv.page(self)
        h = 800 - y - 20
        self.page.set_size(480, h)
        self.page.set_y(y)
        y = 0
        self.buttons = []
        # value, text, enable, color
        for value, text, *args in buttons:
            if text is not None:
                if value is not None:
                    enable = len(args) == 0 or args[0]
                    if enable:
                        cb = on_release(cb_with_args(self.set_value, value))
                    else:
                        cb = None
                    btn = add_button(text, cb, y=y, scr=self.page)
                    if not enable:
                        btn.set_state(lv.btn.STATE.INA)
                    # color
                    if len(args) > 1:
                        color = args[1]
                        style = lv.style_t()
                        lv.style_copy(style, btn.get_style(lv.btn.STYLE.REL))
                        style.body.main_color = lv.color_hex(color)
                        style.body.grad_color = lv.color_hex(color)
                        btn.set_style(lv.btn.STYLE.REL, style)

                    self.buttons.append(btn)
                    y += 85
                else:
                    add_label(text.upper(),
                              y=y + 10,
                              style="hint",
                              scr=self.page)
                    y += 50
            else:
                y += 40
        if last is not None:
            self.add_back_button(*last)
            self.page.set_height(h - 100)
    def popup_settings(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_settings = lv.mbox(bg)
        popup_settings.set_text('Settings')
        btns = ['Set PID Params', '\n', 'Calibrate Touch', '\n', 'Close', '']
        popup_settings.add_btns(btns)

        lv.cont.set_fit(popup_settings, lv.FIT.NONE)
        mbox_style = popup_settings.get_style(popup_settings.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 115
        popup_settings.set_style(popup_settings.STYLE.BTN_REL,
                                 popup_cali_style)
        popup_settings.set_height(186)

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_settings.get_active_btn_text()
                tim = machine.Timer(-1)
                # Note: With PID, temp calibration no longer needed
                # if active_btn_text == 'Temp Sensor':
                #     this.config['has_calibrated'] = False
                #     with open('config.json', 'w') as f:
                #         ujson.dump(this.config, f)
                #     tim.init(period=500, mode=machine.Timer.ONE_SHOT, callback=lambda t:machine.reset())
                # elif active_btn_text == 'Touch Screen':
                if active_btn_text == 'Calibrate Touch':
                    uos.remove(self.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Set PID Params':
                    tim.init(period=50,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: self.popup_pid_params())
                else:
                    tim.deinit()
                bg.del_async()
                popup_settings.start_auto_close(5)

        popup_settings.set_event_cb(event_handler)
        popup_settings.align(None, lv.ALIGN.CENTER, 0, 0)
 def oven_title_init(self):
     """
     Initialize the oven title on the screen.
     """
     style_title = lv.style_t()
     lv.style_copy(style_title, lv.style_transp_fit)
     style_title.text.font = lv.font_roboto_28
     title_label = lv.label(self.main_scr)
     title_label.set_style(lv.label.STYLE.MAIN, style_title)
     title_label.set_text(self.config.get('title'))
     title_label.align(lv.scr_act(), lv.ALIGN.IN_TOP_LEFT, 8, 3)
     return title_label
 def draw_profile_line(self, points):
     """
     Draw reflow temp profile over the chart per selection
     """
     style_line = lv.style_t()
     lv.style_copy(style_line, lv.style_transp)
     style_line.line.color = lv.color_make(0, 0x80, 0)
     style_line.line.width = 3
     style_line.line.rounded = 1
     style_line.line.opa = lv.OPA._40
     line = lv.line(self.chart)
     line.set_points(points, len(points))  # Set the points
     line.set_style(lv.line.STYLE.MAIN, style_line)
     line.align(self.chart, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
     line.set_y_invert(True)
     return line
Exemple #22
0
def show_wallet(wallet, delete_cb=None):
    idx = 0
    addr = wallet.address(idx)
    # dirty hack: add \n at the end to increase title size
    #             to skip realigning of the qr code
    scr = qr_alert("Wallet \"%s\"\n" % wallet.name,
                   "bitcoin:" + addr,
                   format_addr(addr),
                   ok_text="Close",
                   width=300)
    style = lv.style_t()
    lv.style_copy(style, scr.message.get_style(0))
    style.text.font = lv.font_roboto_mono_22
    scr.message.set_style(0, style)

    lbl = add_label("Receiving address #%d" % (idx + 1), y=80)

    def cb_update(delta):
        idx = int(lbl.get_text().split("#")[1]) - 1
        if idx + delta >= 0:
            idx += delta
        addr = wallet.address(idx)
        scr.message.set_text(format_addr(addr))
        scr.qr.set_text("bitcoin:" + addr)
        lbl.set_text("Receiving address #%d" % (idx + 1))
        if idx > 0:
            prv.set_state(lv.btn.STATE.REL)
        else:
            prv.set_state(lv.btn.STATE.INA)

    def cb_next():
        cb_update(1)

    def cb_prev():
        cb_update(-1)

    def cb_del():
        scr.close()
        delete_cb(wallet)

    delbtn = add_button("Delete wallet", on_release(cb_del), y=610)
    prv, nxt = add_button_pair("Previous",
                               on_release(cb_prev),
                               "Next",
                               on_release(cb_next),
                               y=520)
    prv.set_state(lv.btn.STATE.INA)
Exemple #23
0
def init():
    """
    GUI initialization function. 
    Should be called once in the very beginning.
    """

    # init the gui library
    lv.init()
    # init the hardware library
    SDL.init()

    # Register SDL display driver
    disp_buf1 = lv.disp_buf_t()
    buf1_1 = bytearray(HOR_RES*10)
    lv.disp_buf_init(disp_buf1,buf1_1, None, len(buf1_1)//4)
    disp_drv = lv.disp_drv_t()
    lv.disp_drv_init(disp_drv)
    disp_drv.buffer = disp_buf1
    disp_drv.flush_cb = SDL.monitor_flush
    disp_drv.hor_res = HOR_RES
    disp_drv.ver_res = VER_RES
    lv.disp_drv_register(disp_drv)

    # Regsiter SDL mouse driver
    indev_drv = lv.indev_drv_t()
    lv.indev_drv_init(indev_drv) 
    indev_drv.type = lv.INDEV_TYPE.POINTER;
    indev_drv.read_cb = SDL.mouse_read;
    lv.indev_drv_register(indev_drv);

    # Set up material theme
    # First argument (210) is a hue - theme color shift,
    # Second - default font to use. Builtin: roboto_16, roboto_28
    th = lv.theme_material_init(210, lv.font_roboto_22)
    lv.theme_set_current(th)

    # Create a screen and load it
    # To access active screen use lv.scr_act()
    scr = lv.obj()
    lv.scr_load(scr)

    # Initialize the styles
    styles["title"] = lv.style_t()
    # Title style - just a default style with larger font
    lv.style_copy(styles["title"], lv.style_plain)
    styles["title"].text.font = lv.font_roboto_28
Exemple #24
0
    def __init__(self):
        super().__init__()
        self.waiting = True
        self._value = None

        if type(self).network in type(self).COLORS:
            self.topbar = lv.obj(self)
            s = lv.style_t()
            lv.style_copy(s, styles["theme"].style.btn.rel)
            s.body.main_color = type(self).COLORS[type(self).network]
            s.body.grad_color = type(self).COLORS[type(self).network]
            s.body.opa = 200
            s.body.radius = 0
            s.body.border.width = 0
            self.topbar.set_style(s)
            self.topbar.set_size(HOR_RES, 5)
            self.topbar.set_pos(0, 0)
Exemple #25
0
 def _set_text(self, text):
     qr = qrcode.encode_to_string(text).strip()
     size = int(math.sqrt(len(qr))) # + 4 clear space on every side
     width = self.get_width()
     scale = width//size
     sizes = range(1,10)
     fontsize = [s for s in sizes if s < scale or s == 1][-1]
     font = getattr(lv, "square%d" % fontsize)
     style = lv.style_t()
     lv.style_copy(style, qr_style)
     style.text.font = font
     style.body.radius = fontsize
     self.set_style(style)
     self.label.set_text(qr)
     self.label.align(self, lv.ALIGN.CENTER, 0, 0)
     self.note.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
     del qr
     gc.collect()
Exemple #26
0
    def __init__(self, parent, *args, **kwargs):
        # Create a base object for the modal background
        super().__init__(parent, *args, **kwargs)

        # Create a full-screen background
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        # Set the background's style
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50

        self.set_style(modal_style)
        self.set_pos(0, 0)
        self.set_size(parent.get_width(), parent.get_height())

        self.mbox = lv.mbox(self)
        self.mbox.set_width(400)
        self.mbox.align(None, lv.ALIGN.IN_TOP_MID, 0, 200)
Exemple #27
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.label = lv.label(self)
        self._text = "Text"
        self.label.set_long_mode(lv.label.LONG.BREAK)
        self.label.set_align(lv.label.ALIGN.CENTER)

        self.note = lv.label(self)
        style = lv.style_t()
        lv.style_copy(style, qr_style)
        style.text.font = lv.font_roboto_16
        style.text.color = lv.color_hex(0x192432)
        self.note.set_style(0, style)
        self.note.set_text("")
        self.note.set_align(lv.label.ALIGN.CENTER)

        self.set_text(self._text)
        self.task = asyncio.create_task(self.animate())
        self.set_event_cb(self.cb)
Exemple #28
0
def init():
    display.init()

    # Set up material theme
    # First argument (210) is a hue - theme color shift,
    # Second - default font to use. Builtin: roboto_16, roboto_28
    th = lv.theme_material_init(210, lv.font_roboto_22)
    lv.theme_set_current(th)

    # Create a screen and load it
    # To access active screen use lv.scr_act()
    scr = lv.obj()
    lv.scr_load(scr)

    # Initialize the styles
    styles["title"] = lv.style_t()
    # Title style - just a default style with larger font
    lv.style_copy(styles["title"], lv.style_plain)
    styles["title"].text.font = lv.font_roboto_28
 def led_init(self):
     """
     Initialize the LED on the screen
     """
     style_led = lv.style_t()
     lv.style_copy(style_led, lv.style_pretty_color)
     style_led.body.radius = 800  # large enough to draw a circle
     style_led.body.main_color = lv.color_make(0xb5, 0x0f, 0x04)
     style_led.body.grad_color = lv.color_make(0x50, 0x07, 0x02)
     style_led.body.border.color = lv.color_make(0xfa, 0x0f, 0x00)
     style_led.body.border.width = 3
     style_led.body.border.opa = lv.OPA._30
     style_led.body.shadow.color = lv.color_make(0xb5, 0x0f, 0x04)
     style_led.body.shadow.width = 5
     led = lv.led(self.main_scr)
     led.set_style(lv.led.STYLE.MAIN, style_led)
     led.align(lv.scr_act(), lv.ALIGN.IN_TOP_RIGHT, -10, 5)
     led.off()
     return led
 def stage_init(self):
     # Stage Container
     stage_cont = lv.cont(self.main_scr)
     stage_cont.set_size(140, 38)
     # stage_cont.set_auto_realign(True)
     stage_cont.align(self.start_btn, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 5)
     stage_cont.set_fit(lv.FIT.NONE)
     stage_cont.set_layout(lv.LAYOUT.CENTER)
     style_stage = lv.style_t()
     lv.style_copy(style_stage, lv.style_plain)
     style_stage.text.font = lv.font_roboto_22
     stage_cont.set_style(lv.label.STYLE.MAIN, style_stage)
     stage_label = lv.label(stage_cont)
     stage_label.set_style(lv.label.STYLE.MAIN, style_stage)
     stage_label.set_recolor(True)
     stage_label.set_long_mode(lv.label.LONG.SROLL)
     stage_label.set_width(128)
     stage_label.set_text('')
     return stage_cont, stage_label