async def info_confirm( ctx: wire.GenericContext, content: ui.Component, info_func: Callable, code: EnumTypeButtonRequestType = ButtonRequestType.Other, confirm: ButtonContent = InfoConfirm.DEFAULT_CONFIRM, confirm_style: ButtonStyleType = InfoConfirm.DEFAULT_CONFIRM_STYLE, cancel: ButtonContent = InfoConfirm.DEFAULT_CANCEL, cancel_style: ButtonStyleType = InfoConfirm.DEFAULT_CANCEL_STYLE, info: ButtonContent = InfoConfirm.DEFAULT_INFO, info_style: ButtonStyleType = InfoConfirm.DEFAULT_INFO_STYLE, ) -> bool: await ctx.call(ButtonRequest(code=code), ButtonAck) dialog = InfoConfirm(content, confirm, confirm_style, cancel, cancel_style, info, info_style) while True: if __debug__: result = await ctx.wait(dialog, confirm_signal()) else: result = await ctx.wait(dialog) if result is INFO: await info_func(ctx) else: return result is CONFIRMED
async def hold_to_confirm( ctx: wire.Context, content: ui.Layout, code: EnumTypeButtonRequestType = ButtonRequestType.Other, confirm: str = HoldToConfirm.DEFAULT_CONFIRM, confirm_style: ButtonStyleType = HoldToConfirm.DEFAULT_CONFIRM_STYLE, loader_style: LoaderStyleType = HoldToConfirm.DEFAULT_LOADER_STYLE, ) -> bool: await ctx.call(ButtonRequest(code=code), ButtonAck) if content.__class__.__name__ == "Paginated": # The following works because asserts are omitted in non-debug builds. # IOW if the assert runs, that means __debug__ is True and Paginated is imported assert isinstance(content, Paginated) content.pages[-1] = HoldToConfirm(content.pages[-1], confirm, confirm_style, loader_style) dialog = content # type: ui.Layout else: dialog = HoldToConfirm(content, confirm, confirm_style, loader_style) if __debug__: return await ctx.wait(dialog, confirm_signal()) is CONFIRMED else: return await ctx.wait(dialog) is CONFIRMED
async def confirm( ctx: wire.GenericContext, content: ui.Component, code: EnumTypeButtonRequestType = ButtonRequestType.Other, confirm: Optional[ButtonContent] = Confirm.DEFAULT_CONFIRM, confirm_style: ButtonStyleType = Confirm.DEFAULT_CONFIRM_STYLE, cancel: Optional[ButtonContent] = Confirm.DEFAULT_CANCEL, cancel_style: ButtonStyleType = Confirm.DEFAULT_CANCEL_STYLE, major_confirm: bool = False, ) -> bool: await ctx.call(ButtonRequest(code=code), ButtonAck) if content.__class__.__name__ == "Paginated": # The following works because asserts are omitted in non-debug builds. # IOW if the assert runs, that means __debug__ is True and Paginated is imported assert isinstance(content, Paginated) content.pages[-1] = Confirm( content.pages[-1], confirm, confirm_style, cancel, cancel_style, major_confirm, ) dialog = content # type: ui.Layout else: dialog = Confirm(content, confirm, confirm_style, cancel, cancel_style, major_confirm) if __debug__: return await ctx.wait(dialog, confirm_signal()) is CONFIRMED else: return await ctx.wait(dialog) is CONFIRMED
async def confirm( ctx: wire.Context, content: ui.Component, code: int = ButtonRequestType.Other, confirm: ButtonContent = Confirm.DEFAULT_CONFIRM, confirm_style: ButtonStyleType = Confirm.DEFAULT_CONFIRM_STYLE, cancel: ButtonContent = Confirm.DEFAULT_CANCEL, cancel_style: ButtonStyleType = Confirm.DEFAULT_CANCEL_STYLE, major_confirm: bool = False, ) -> bool: await ctx.call(ButtonRequest(code=code), ButtonAck) if content.__class__.__name__ == "Paginated": content.pages[-1] = Confirm( content.pages[-1], confirm, confirm_style, cancel, cancel_style, major_confirm, ) dialog = content else: dialog = Confirm(content, confirm, confirm_style, cancel, cancel_style, major_confirm) if __debug__: return await ctx.wait(dialog, confirm_signal()) is CONFIRMED else: return await ctx.wait(dialog) is CONFIRMED
async def naive_pagination(ctx, lines, title, icon=ui.ICON_RESET, icon_color=ui.ORANGE, per_page=5): from trezor.ui.scroll import CANCELLED, CONFIRMED, PaginatedWithButtons pages = [] page_lines = paginate_lines(lines, per_page) for i, lines in enumerate(page_lines): if len(page_lines) > 1: paging = "%s/%s" % (i + 1, len(page_lines)) else: paging = "" text = Text("%s %s" % (title, paging), icon, icon_color) text.normal(*lines) pages.append(text) paginated = PaginatedWithButtons(pages, one_by_one=True) while True: await ctx.call(ButtonRequest(code=ButtonRequestType.SignTx), ButtonAck) if __debug__: result = await loop.race(paginated, confirm_signal()) else: result = await paginated if result is CONFIRMED: return True if result is CANCELLED: return False
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]: from apps.debug import confirm_signal, input_signal return ( self.handle_timers(), self.handle_input_and_rendering(), self.handle_swipe(), confirm_signal(), input_signal(), )
def create_tasks(self) -> Tuple[loop.Task, ...]: tasks: Tuple[loop.Task, ...] = ( self.handle_input(), self.handle_rendering(), self.handle_paging(), ) if __debug__: # XXX This isn't strictly correct, as it allows *any* Paginated layout to be # shut down by a DebugLink confirm, even if used outside of a confirm() call # But we don't have any such usages in the codebase, and it doesn't actually # make much sense to use a Paginated without a way to confirm it. return tasks + (confirm_signal(), ) else: return tasks
async def show_keyboard_info(ctx: wire.Context) -> None: # TODO: do not send ButtonRequestType.Other await ctx.call(ButtonRequest(code=ButtonRequestType.Other), ButtonAck) info = InfoConfirm( "Did you know? " "You can type the letters " "one by one or use it like " "a T9 keyboard.", "Great!", ) if __debug__: await ctx.wait(info, confirm_signal()) else: await ctx.wait(info)
async def hold_to_confirm( ctx: wire.Context, content: ui.Component, code: int = ButtonRequestType.Other, confirm: ButtonContent = HoldToConfirm.DEFAULT_CONFIRM, confirm_style: ButtonStyleType = HoldToConfirm.DEFAULT_CONFIRM_STYLE, loader_style: LoaderStyleType = HoldToConfirm.DEFAULT_LOADER_STYLE, ) -> bool: await ctx.call(ButtonRequest(code=code), ButtonAck) if content.__class__.__name__ == "Paginated": content.pages[-1] = HoldToConfirm(content.pages[-1], confirm, confirm_style, loader_style) dialog = content else: dialog = HoldToConfirm(content, confirm, confirm_style, loader_style) if __debug__: return await ctx.wait(dialog, confirm_signal()) is CONFIRMED else: return await ctx.wait(dialog) is CONFIRMED
def create_tasks(self) -> tuple[loop.Task, ...]: from apps.debug import confirm_signal return super().create_tasks() + (confirm_signal(), )
def create_tasks(self) -> Tuple[loop.Task, ...]: return super().create_tasks() + (confirm_signal(), )