async def request_pin(code: int = None) -> str: from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.pin import PinMatrix label = _get_label(code) def onchange(): c = dialog.cancel if matrix.pin: c.content = res.load(ui.ICON_CLEAR) else: c.content = res.load(ui.ICON_LOCK) c.taint() c.render() ui.display.clear() matrix = PinMatrix(label, with_zero=True) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: result = await dialog if result == CONFIRMED: return matrix.pin elif result != CONFIRMED and matrix.pin: matrix.change('') continue else: raise PinCancelled()
def __init__( self, content, confirm=DEFAULT_CONFIRM, confirm_style=DEFAULT_CONFIRM_STYLE, cancel=DEFAULT_CANCEL, cancel_style=DEFAULT_CANCEL_STYLE, ): self.content = content if confirm is not None: if cancel is None: area = ui.grid(4, n_x=1) else: area = ui.grid(9, n_x=2) self.confirm = Button(area, confirm, confirm_style) self.confirm.on_click = self.on_confirm else: self.confirm = None if cancel is not None: if confirm is None: area = ui.grid(4, n_x=1) else: area = ui.grid(8, n_x=2) self.cancel = Button(area, cancel, cancel_style) self.cancel.on_click = self.on_cancel else: self.cancel = None
def generate_buttons(start, end, page, pad): start = start + (_ITEMS_PER_PAGE + 1) * page - page end = min(end, (_ITEMS_PER_PAGE + 1) * (page + 1) - page) digits = list(range(start, end)) buttons = [NumButton(i, d, pad) for i, d in enumerate(digits)] area = ui.grid(_PLUS_BUTTON_POSITION + 3) plus = Button(area, str(end) + "+", ButtonMonoDark) plus.on_click = pad.on_plus area = ui.grid(_BACK_BUTTON_POSITION + 3) back = Button(area, res.load(ui.ICON_BACK), ButtonMonoDark) back.on_click = pad.on_back if len(digits) == _ITEMS_PER_PAGE: # move the tenth button to its proper place and make place for the back button buttons[-1].area = ui.grid(_PLUS_BUTTON_POSITION - 1 + 3) buttons.append(plus) if page == 0: back.disable() buttons.append(back) return buttons
def __init__( self, content: ui.Component, confirm: str = DEFAULT_CONFIRM, confirm_style: ButtonStyleType = DEFAULT_CONFIRM_STYLE, loader_style: LoaderStyleType = DEFAULT_LOADER_STYLE, cancel: bool = True, ): super().__init__() self.content = content self.loader = Loader(loader_style) self.loader.on_start = self._on_loader_start # type: ignore if cancel: self.confirm = Button(ui.grid(17, n_x=4, cells_x=3), confirm, confirm_style) else: self.confirm = Button(ui.grid(4, n_x=1), confirm, confirm_style) self.confirm.on_press_start = self._on_press_start # type: ignore self.confirm.on_press_end = self._on_press_end # type: ignore self.confirm.on_click = self._on_click # type: ignore self.cancel = None if cancel: self.cancel = Button( ui.grid(16, n_x=4), res.load(ui.ICON_CANCEL), ButtonAbort ) self.cancel.on_click = self.on_cancel # type: ignore
def __init__(self, prompt: str, subprompt: str, allow_cancel: bool = True, maxlength: int = 9) -> None: self.maxlength = maxlength self.input = PinInput(prompt, subprompt, "") icon_confirm = res.load(ui.ICON_CONFIRM) self.confirm_button = Button(ui.grid(14), icon_confirm, ButtonConfirm) self.confirm_button.on_click = self.on_confirm # type: ignore self.confirm_button.disable() icon_back = res.load(ui.ICON_BACK) self.reset_button = Button(ui.grid(12), icon_back, ButtonClear) self.reset_button.on_click = self.on_reset # type: ignore if allow_cancel: icon_lock = res.load(ui.ICON_LOCK) self.cancel_button = Button(ui.grid(12), icon_lock, ButtonCancel) self.cancel_button.on_click = self.on_cancel # type: ignore else: self.cancel_button = Button(ui.grid(12), "") self.cancel_button.disable() self.pin_buttons = [ PinButton(i, d, self) for i, d in enumerate(generate_digits()) ]
def __init__( self, prompt: str, subprompt: str | None, allow_cancel: bool = True, maxlength: int = 50, ) -> None: super().__init__() self.maxlength = maxlength self.input = PinInput(prompt, subprompt, "") icon_confirm = res.load(ui.ICON_CONFIRM) self.confirm_button = Button(ui.grid(14), icon_confirm, ButtonConfirm) self.confirm_button.on_click = self.on_confirm self.confirm_button.disable() icon_back = res.load(ui.ICON_BACK) self.reset_button = Button(ui.grid(12), icon_back, ButtonClear) self.reset_button.on_click = self.on_reset if allow_cancel: icon_lock = res.load( ui.ICON_CANCEL if config.is_unlocked() else ui.ICON_LOCK) self.cancel_button = Button(ui.grid(12), icon_lock, ButtonCancel) self.cancel_button.on_click = self.on_cancel else: self.cancel_button = Button(ui.grid(12), "") self.cancel_button.disable() self.pin_buttons = [ PinButton(i, d, self) for i, d in enumerate(generate_digits()) ]
def __init__(self, content, paginated, index, count): self.content = content self.paginated = paginated self.index = index self.count = count if self.index == 0: # first page, we can cancel or go down left = res.load(ui.ICON_CANCEL) left_style = ButtonCancel right = res.load(ui.ICON_CLICK) right_style = ButtonDefault elif self.index == count - 1: # last page, we can go up or confirm left = res.load(ui.ICON_BACK) left_style = ButtonDefault right = res.load(ui.ICON_CONFIRM) right_style = ButtonConfirm else: # somewhere in the middle, we can go up or down left = res.load(ui.ICON_BACK) left_style = ButtonDefault right = res.load(ui.ICON_CLICK) right_style = ButtonDefault self.left = Button(ui.grid(8, n_x=2), left, left_style) self.left.on_click = self.on_left self.right = Button(ui.grid(9, n_x=2), right, right_style) self.right.on_click = self.on_right
def __init__(self, content): self.content = content self.device = Button(ui.grid(8, n_y=4, n_x=4, cells_x=4), "Device") self.device.on_click = self.on_device self.host = Button(ui.grid(12, n_y=4, n_x=4, cells_x=4), "Host") self.host.on_click = self.on_host
def __init__(self, content: ui.Control) -> None: self.content = content self.device = Button(ui.grid(8, n_y=4, n_x=4, cells_x=4), "Device") self.device.on_click = self.on_device # type: ignore self.host = Button(ui.grid(12, n_y=4, n_x=4, cells_x=4), "Host") self.host.on_click = self.on_host # type: ignore
def __init__(self, content): self.content = content self.w12 = Button(ui.grid(6, n_y=4, n_x=3, cells_y=2), "12") self.w12.on_click = self.on_w12 self.w18 = Button(ui.grid(7, n_y=4, n_x=3, cells_y=2), "18") self.w18.on_click = self.on_w18 self.w24 = Button(ui.grid(8, n_y=4, n_x=3, cells_y=2), "24") self.w24.on_click = self.on_w24
def __init__(self, content): self.content = content self.w12 = Button(ui.grid(6, n_y=4, n_x=3, cells_y=2), str(_W12), style=ui.BTN_KEY) self.w18 = Button(ui.grid(7, n_y=4, n_x=3, cells_y=2), str(_W18), style=ui.BTN_KEY) self.w24 = Button(ui.grid(8, n_y=4, n_x=3, cells_y=2), str(_W24), style=ui.BTN_KEY)
def __init__(self, text, confirm=DEFAULT_CONFIRM, style=DEFAULT_STYLE): self.text = text.split() self.style = style panel_area = ui.grid(0, n_x=1, n_y=1) self.panel_area = panel_area confirm_area = ui.grid(4, n_x=1) self.confirm = Button(confirm_area, confirm, style.button) self.confirm.on_click = self.on_confirm self.repaint = True
def __init__(self, prompt: str=''): self.prompt = prompt self.input = Input(ui.grid(1, n_x=4, n_y=4, cells_x=3), '', '') self.back = Button(ui.grid(0, n_x=4, n_y=4), res.load(ui.ICON_BACK), style=ui.BTN_CLEAR) self.keys = key_buttons(MNEMONIC_KEYS) self.pbutton = None # pending key button self.pindex = 0 # index of current pending char in pbutton
def __init__(self, prompt, page=1): self.prompt = Prompt(prompt) self.page = page self.input = Input(ui.grid(0, n_x=1, n_y=6), '') self.back = Button(ui.grid(12), res.load(ui.ICON_BACK), style=ui.BTN_CLEAR) self.done = Button(ui.grid(14), res.load(ui.ICON_CONFIRM), style=ui.BTN_CONFIRM) self.keys = key_buttons(KEYBOARD_KEYS[self.page]) self.pbutton = None # pending key button self.pindex = 0 # index of current pending char in pbutton
async def request_pin(label=None, attempts_remaining=None, cancellable: bool = True) -> str: def onchange(): c = dialog.cancel if matrix.pin: back = res.load(ui.ICON_BACK) if c.content is not back: c.normal_style = ui.BTN_CLEAR["normal"] c.content = back c.enable() c.taint() else: lock = res.load(ui.ICON_LOCK) if not cancellable and c.content: c.content = "" c.disable() c.taint() elif c.content is not lock: c.normal_style = ui.BTN_CANCEL["normal"] c.content = lock c.enable() c.taint() c.render() if label is None: label = "Enter your PIN" sublabel = None if attempts_remaining: if attempts_remaining == 1: sublabel = "This is your last attempt" else: sublabel = "{} attempts remaining".format(attempts_remaining) matrix = PinMatrix(label, sublabel) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: if __debug__: result = await loop.spawn(dialog, input_signal) if isinstance(result, str): return result else: result = await dialog if result == CONFIRMED: return matrix.pin elif matrix.pin: # reset matrix.change("") continue else: # cancel raise PinCancelled()
def __init__(self, count=5, max_count=16, min_count=1): self.count = count self.max_count = max_count self.min_count = min_count self.minus = Button(ui.grid(3), "-") self.minus.on_click = self.on_minus self.plus = Button(ui.grid(5), "+") self.plus.on_click = self.on_plus self.text = Label(ui.grid(4), "", LABEL_CENTER, ui.BOLD) self.edit(count)
def __init__(self, content: ui.Component) -> None: self.content = content self.w12 = Button(ui.grid(6, n_y=4), "12") self.w12.on_click = self.on_w12 # type: ignore self.w18 = Button(ui.grid(7, n_y=4), "18") self.w18.on_click = self.on_w18 # type: ignore self.w20 = Button(ui.grid(8, n_y=4), "20") self.w20.on_click = self.on_w20 # type: ignore self.w24 = Button(ui.grid(9, n_y=4), "24") self.w24.on_click = self.on_w24 # type: ignore self.w33 = Button(ui.grid(10, n_y=4), "33") self.w33.on_click = self.on_w33 # type: ignore
def __init__(self, content): self.content = content self.w12 = Button(ui.grid(6, n_y=4), "12") self.w12.on_click = self.on_w12 self.w18 = Button(ui.grid(7, n_y=4), "18") self.w18.on_click = self.on_w18 self.w20 = Button(ui.grid(8, n_y=4), "20") self.w20.on_click = self.on_w20 self.w24 = Button(ui.grid(9, n_y=4), "24") self.w24.on_click = self.on_w24 self.w33 = Button(ui.grid(10, n_y=4), "33") self.w33.on_click = self.on_w33
def __init__(self, content): self.content = content self.w12 = Button(ui.grid(8, n_y=4, n_x=4, cells_x=2), str(_W12), style=ui.BTN_KEY) self.w15 = Button(ui.grid(10, n_y=4, n_x=4, cells_x=2), str(_W15), style=ui.BTN_KEY) self.w18 = Button(ui.grid(12, n_y=4, n_x=4, cells_x=2), str(_W18), style=ui.BTN_KEY) self.w24 = Button(ui.grid(14, n_y=4, n_x=4, cells_x=2), str(_W24), style=ui.BTN_KEY)
def __init__( self, text: str, confirm: ButtonContent = DEFAULT_CONFIRM, style: InfoConfirmStyleType = DEFAULT_STYLE, ) -> None: super().__init__() self.text = text.split() self.style = style panel_area = ui.grid(0, n_x=1, n_y=1) self.panel_area = panel_area confirm_area = ui.grid(4, n_x=1) self.confirm = Button(confirm_area, confirm, style.button) self.confirm.on_click = self.on_confirm # type: ignore
def __init__(self, count: int = 5, max_count: int = 16, min_count: int = 1) -> None: super().__init__() self.count = count self.max_count = max_count self.min_count = min_count self.minus = Button(ui.grid(3), "-") self.minus.on_click = self.on_minus # type: ignore self.plus = Button(ui.grid(5), "+") self.plus.on_click = self.on_plus # type: ignore self.text = Label(ui.grid(4), "", LABEL_CENTER, ui.BOLD) self.edit(count)
def __init__(self, content: ui.Component, button_text: str = "Show all") -> None: super().__init__() self.content = content self.button = Button(ui.grid(3, n_x=1), button_text, ButtonDefault) self.button.on_click = self.on_show_paginated_click # type: ignore
def __init__( self, words: Sequence[str], share_index: int | None, word_index: int, count: int, group_index: int | None = None, ) -> None: super().__init__() self.words = words self.share_index = share_index self.word_index = word_index self.buttons = [] for i, word in enumerate(words): area = ui.grid(i + 2, n_x=1) btn = Button(area, word) btn.on_click = self.select(word) self.buttons.append(btn) if share_index is None: self.text: ui.Component = Text("Check seed") elif group_index is None: self.text = Text(f"Check share #{share_index + 1}") else: self.text = Text( f"Check G{group_index + 1} - Share {share_index + 1}") self.text.normal(f"Select word {word_index + 1} of {count}:")
def __init__(self, content, hold='Hold to confirm', *args, **kwargs): self.content = content self.button = Button(ui.grid(4, n_x=1), hold, normal_style=ui.BTN_CONFIRM, active_style=ui.BTN_CONFIRM_ACTIVE) self.loader = Loader(*args, **kwargs)
def __init__(self, content, confirm=DEFAULT_CONFIRM, cancel=DEFAULT_CANCEL, confirm_style=ui.BTN_CONFIRM, cancel_style=ui.BTN_CANCEL): self.content = content if cancel is not None: self.confirm = Button( ui.grid(9, n_x=2), confirm, style=confirm_style) self.cancel = Button( ui.grid(8, n_x=2), cancel, style=cancel_style) else: self.confirm = Button( ui.grid(4, n_x=1), confirm, style=confirm_style) self.cancel = None
async def request_pin(label=None, cancellable: bool=True) -> str: def onchange(): c = dialog.cancel if matrix.pin: back = res.load(ui.ICON_BACK) if c.content is not back: c.normal_style = ui.BTN_CLEAR['normal'] c.content = back c.enable() c.taint() else: lock = res.load(ui.ICON_LOCK) if not cancellable and c.content: c.content = '' c.disable() c.taint() elif c.content is not lock: c.normal_style = ui.BTN_CANCEL['normal'] c.content = lock c.enable() c.taint() c.render() if label is None: label = 'Enter your PIN' matrix = PinMatrix(label) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: if __debug__: result = await loop.wait(dialog, input_signal) if isinstance(result, str): return result else: result = await dialog if result == CONFIRMED: return matrix.pin elif matrix.pin: # reset matrix.change('') continue else: # cancel raise PinCancelled()
def __init__(self, content, hold='Hold to confirm', button_style=ui.BTN_CONFIRM, loader_style=ui.LDR_DEFAULT): self.content = content self.button = Button(ui.grid(4, n_x=1), hold, style=button_style) self.loader = Loader(style=loader_style)
def __init__(self, prompt): self.prompt = Prompt(prompt) icon_back = res.load(ui.ICON_BACK) self.back = Button(ui.grid(0, n_x=4, n_y=4), icon_back, ButtonClear) self.back.on_click = self.on_back_click self.input = InputButton(ui.grid(1, n_x=4, n_y=4, cells_x=3), "", "") self.input.on_click = self.on_input_click self.keys = [ KeyButton(ui.grid(i + 3, n_y=4), k, self) for i, k in enumerate(("abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz")) ] self.pending_button = None self.pending_index = 0
def __init__(self, prompt: str, max_length: int, page: int = 1) -> None: self.prompt = Prompt(prompt) self.max_length = max_length self.page = page self.input = Input(ui.grid(0, n_x=1, n_y=6), "") self.back = Button(ui.grid(12), res.load(ui.ICON_BACK), ButtonClear) self.back.on_click = self.on_back_click # type: ignore self.back.disable() self.done = Button(ui.grid(14), res.load(ui.ICON_CONFIRM), ButtonConfirm) self.done.on_click = self.on_confirm # type: ignore self.keys = key_buttons(KEYBOARD_KEYS[self.page], self) self.pending_button = None # type: Optional[KeyButton] self.pending_index = 0
def __init__(self, prompt): self.prompt = Prompt(prompt) icon_back = res.load(ui.ICON_BACK) self.back = Button(ui.grid(0, n_x=4, n_y=4), icon_back, ButtonClear) self.back.on_click = self.on_back_click self.input = InputButton(ui.grid(1, n_x=4, n_y=4, cells_x=3), "", "") self.input.on_click = self.on_input_click self.keys = [ KeyButton(ui.grid(i + 3, n_y=4), k, self, i + 1) for i, k in enumerate(("ab", "cd", "ef", "ghij", "klm", "nopq", "rs", "tuv", "wxyz")) ] self.pending_button = None self.pending_index = 0 self.button_sequence = ""