diff --git a/src/apps/management/confirm.py b/src/apps/management/confirm.py index 8332aab4..81f62097 100644 --- a/src/apps/management/confirm.py +++ b/src/apps/management/confirm.py @@ -3,13 +3,13 @@ from trezor.utils import unimport @unimport -async def confirm(session_id, content=None, code=None, **kwargs): +async def confirm(session_id, content=None, code=None, *args, **kwargs): from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequestType import Other from trezor.messages.wire_types import ButtonAck - dialog = ConfirmDialog(content, **kwargs) + dialog = ConfirmDialog(content, *args, **kwargs) dialog.render() if code is None: @@ -19,7 +19,7 @@ async def confirm(session_id, content=None, code=None, **kwargs): @unimport -async def hold_to_confirm(session_id, code=None): +async def hold_to_confirm(session_id, content=None, code=None, *args, **kwargs): from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE from trezor.ui.confirm import HoldToConfirmDialog, CONFIRMED from trezor.messages.ButtonRequest import ButtonRequest @@ -29,7 +29,7 @@ async def hold_to_confirm(session_id, code=None): button = Button((0, 240 - 48, 240, 48), 'Hold to confirm', normal_style=CONFIRM_BUTTON, active_style=CONFIRM_BUTTON_ACTIVE) - dialog = HoldToConfirmDialog(button) + dialog = HoldToConfirmDialog(button, content, *args, **kwargs) if code is None: code = Other diff --git a/src/apps/management/layout_wipe_device.py b/src/apps/management/layout_wipe_device.py index 829dd61c..213d6857 100644 --- a/src/apps/management/layout_wipe_device.py +++ b/src/apps/management/layout_wipe_device.py @@ -5,18 +5,18 @@ from trezor.utils import unimport @unimport async def layout_wipe_device(message, session_id): from trezor.messages.Success import Success + from trezor.ui.text import Text from .confirm import hold_to_confirm from .storage import clear_storage ui.clear() - ui.display.text(10, 30, 'Wiping device', ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) - ui.display.text(10, 74, 'Do you really want to', - ui.BOLD, ui.WHITE, ui.BLACK) - ui.display.text(10, 104, 'wipe the device?', ui.BOLD, ui.WHITE, ui.BLACK) - ui.display.text(10, 164, 'All data will be lost.', - ui.NORMAL, ui.WHITE, ui.BLACK) - await hold_to_confirm(session_id) + content = Text('Wiping device', + (ui.BOLD, 'Do you really want to'), + (ui.BOLD, 'wipe the device?'), + (ui.NORMAL, ''), + (ui.NORMAL, 'All data will be lost.')) + await hold_to_confirm(session_id, content) clear_storage(session_id) diff --git a/src/trezor/ui/confirm.py b/src/trezor/ui/confirm.py index dea98164..2beb188e 100644 --- a/src/trezor/ui/confirm.py +++ b/src/trezor/ui/confirm.py @@ -1,8 +1,8 @@ -import utime from .button import Button, BTN_CLICKED, BTN_STARTED from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE -from trezor import loop, ui +from .loader import Loader +from trezor import loop CONFIRMED = const(1) @@ -43,59 +43,6 @@ class ConfirmDialog(): return result -DEFAULT_LOADER = { - 'bg-color': ui.BLACK, - 'fg-color': ui.WHITE, - 'icon': None, - 'icon-fg-color': None, -} -DEFAULT_LOADER_ACTIVE = { - 'bg-color': ui.BLACK, - 'fg-color': ui.LIGHT_GREEN, - 'icon': None, - 'icon-fg-color': None, -} - -LOADER_MSEC = const(1000) - - -class Loader(): - - def __init__(self, normal_style=None, active_style=None): - self.start_ticks_ms = None - self.normal_style = normal_style or DEFAULT_LOADER - self.active_style = active_style or DEFAULT_LOADER_ACTIVE - - def start(self): - self.start_ticks_ms = utime.ticks_ms() - - def stop(self): - ticks_diff = utime.ticks_ms() - self.start_ticks_ms - self.start_ticks_ms = None - return ticks_diff >= LOADER_MSEC - - def render(self): - if self.start_ticks_ms is None: - return False - - progress = min(utime.ticks_ms() - self.start_ticks_ms, LOADER_MSEC) - if progress == LOADER_MSEC: - style = self.active_style - else: - style = self.normal_style - - if style['icon'] is None: - ui.display.loader(progress, style['fg-color'], style['bg-color']) - elif style['icon-fg-color'] is None: - ui.display.loader( - progress, style['fg-color'], style['bg-color'], style['icon']) - else: - ui.display.loader( - progress, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color']) - - return True - - class HoldToConfirmDialog(): def __init__(self, button, content=None, *args, **kwargs): @@ -107,13 +54,9 @@ class HoldToConfirmDialog(): if not self.loader.render(): if self.content is not None: self.content.render() - else: - ui.display.bar(0, 0, 240, 240 - 48, ui.BLACK) self.button.render() def send(self, event, pos): - if self.content is not None: - self.content.send(pos) button = self.button was_started = button.state & BTN_STARTED button.send(event, pos) @@ -125,7 +68,8 @@ class HoldToConfirmDialog(): if was_started: if self.loader.stop(): return CONFIRMED - return None + if self.content is not None: + return self.content.send(event, pos) async def __iter__(self): await loop.Wait([self._render_loop(), diff --git a/src/trezor/ui/loader.py b/src/trezor/ui/loader.py new file mode 100644 index 00000000..6131067d --- /dev/null +++ b/src/trezor/ui/loader.py @@ -0,0 +1,57 @@ +import utime +from trezor import ui + + +DEFAULT_LOADER = { + 'bg-color': ui.BLACK, + 'fg-color': ui.WHITE, + 'icon': None, + 'icon-fg-color': None, +} +DEFAULT_LOADER_ACTIVE = { + 'bg-color': ui.BLACK, + 'fg-color': ui.LIGHT_GREEN, + 'icon': None, + 'icon-fg-color': None, +} + +LOADER_MSEC = const(1000) + + +class Loader(): + + def __init__(self, normal_style=None, active_style=None): + self.start_ticks_ms = None + self.normal_style = normal_style or DEFAULT_LOADER + self.active_style = active_style or DEFAULT_LOADER_ACTIVE + + def start(self): + self.start_ticks_ms = utime.ticks_ms() + ui.display.bar(0, 0, 240, 240 - 48, ui.BLACK) + + def stop(self): + ui.display.bar(0, 0, 240, 240 - 48, ui.BLACK) + ticks_diff = utime.ticks_ms() - self.start_ticks_ms + self.start_ticks_ms = None + return ticks_diff >= LOADER_MSEC + + def render(self): + if self.start_ticks_ms is None: + return False + + progress = min(utime.ticks_ms() - self.start_ticks_ms, LOADER_MSEC) + if progress == LOADER_MSEC: + style = self.active_style + else: + style = self.normal_style + + if style['icon'] is None: + ui.display.loader(progress, style['fg-color'], style['bg-color']) + elif style['icon-fg-color'] is None: + ui.display.loader( + progress, style['fg-color'], style['bg-color'], style['icon']) + else: + ui.display.loader( + progress, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color']) + + return True diff --git a/src/trezor/ui/text.py b/src/trezor/ui/text.py new file mode 100644 index 00000000..2a212572 --- /dev/null +++ b/src/trezor/ui/text.py @@ -0,0 +1,25 @@ +from trezor import ui + +TEXT_HEADER_HEIGHT = const(44) +TEXT_LINE_HEIGHT = const(30) +TEXT_MARGIN_LEFT = const(10) + + +class Text: + + def __init__(self, header, *lines): + self.header = header + self.lines = lines + + def render(self): + offset = TEXT_LINE_HEIGHT + ui.display.text(TEXT_MARGIN_LEFT, offset, + self.header, ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) + offset += TEXT_HEADER_HEIGHT + for style, line in self.lines: + ui.display.text(TEXT_MARGIN_LEFT, offset, + line, style, ui.WHITE, ui.BLACK) + offset += TEXT_LINE_HEIGHT + + def send(self, event, pos): + pass