From 771372adb278e8efdd460584fc0ce9b22df1c8f4 Mon Sep 17 00:00:00 2001 From: chren Date: Fri, 10 Jun 2016 17:07:17 +0200 Subject: [PATCH] replace scrolling to componenet, added mockup for recovery device layout --- src/apps/management/__init__.py | 9 ++++++ src/apps/management/layout_recovery_device.py | 16 ++++++++++ src/apps/management/layout_reset_device.py | 20 ++---------- src/apps/management/layout_wipe_device.py | 2 +- src/trezor/ui/scroll.py | 32 +++++++++++++++++++ 5 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 src/apps/management/layout_recovery_device.py create mode 100644 src/trezor/ui/scroll.py diff --git a/src/apps/management/__init__.py b/src/apps/management/__init__.py index 4486abed6..5968c83c3 100644 --- a/src/apps/management/__init__.py +++ b/src/apps/management/__init__.py @@ -26,6 +26,13 @@ def dispatch_WipeDevice(mtype, mbuf): return layout_wipe_device(message) +@unimport_func +def dispatch_RecoveryDevice(mtype, mbuf): + from trezor.messages.RecoveryDevice import RecoveryDevice + message = RecoveryDevice.loads(mbuf) + from .layout_recovery_device import layout_recovery_device + return layout_recovery_device(message) + def boot(): LoadDevice = 13 register(LoadDevice, dispatch_LoadDevice) @@ -33,3 +40,5 @@ def boot(): register(ResetDevice, dispatch_ResetDevice) WipeDevice = 5 register(WipeDevice, dispatch_WipeDevice) + RecoveryDevice = 45 + register(RecoveryDevice, dispatch_RecoveryDevice) \ No newline at end of file diff --git a/src/apps/management/layout_recovery_device.py b/src/apps/management/layout_recovery_device.py new file mode 100644 index 000000000..81f1b8bc3 --- /dev/null +++ b/src/apps/management/layout_recovery_device.py @@ -0,0 +1,16 @@ +from trezor import ui, loop, wire +from trezor.utils import unimport_gen + +def ord(n): + return str(n)+("th" if 4<=n%100<=20 else {1:"st",2:"nd",3:"rd"}.get(n%10, "th")) + +@unimport_gen +def layout_recovery_device(message): + + msg = 'Please enter ' + ord(message.word_count) + ' word' + + ui.clear() + ui.display.text(10, 30, 'Recovering device', ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) + ui.display.text(10, 74, msg, ui.BOLD, ui.WHITE, ui.BLACK) + ui.display.text(10, 104, 'of your mnemonic.', ui.BOLD, ui.WHITE, ui.BLACK) + yield from wire.read(None) diff --git a/src/apps/management/layout_reset_device.py b/src/apps/management/layout_reset_device.py index 77f4dfdf9..6c9740474 100644 --- a/src/apps/management/layout_reset_device.py +++ b/src/apps/management/layout_reset_device.py @@ -1,6 +1,7 @@ from trezor import wire, loop, res, ui from trezor.ui.swipe import Swipe, SWIPE_UP, SWIPE_DOWN from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE +from trezor.ui.scroll import Scroll from trezor.crypto import hashlib, random, bip39 from trezor.utils import unimport_gen @@ -62,23 +63,8 @@ def layout_reset_device(m): ui.display.text_right(40, top, '%d.' % (index + 1), ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) ui.display.text(45, top, '%s' % word, ui.BOLD, ui.WHITE, ui.BLACK) - # print side scrolling indicator - - count = len(mnemonic_words) // words_per_page # 6 - padding = 20 - screen_height = const(220) - cursor = 8 - - if count * padding > screen_height: - padding = screen_height // count - - x = 220 - y = (10 + (screen_height // 2)) - ((count // 2) * padding) - - for i in range(0, count): - if (i != page): - ui.display.bar(x, y + i * padding, cursor, cursor, ui.GREY) - ui.display.bar(x, y + page * padding, cursor, cursor, ui.WHITE) + scroll = Scroll(page=page, totale_lines=mnemonic_words, lines_per_page=words_per_page) + scroll.render() # TODO: remove swipedown icon when this button is showed diff --git a/src/apps/management/layout_wipe_device.py b/src/apps/management/layout_wipe_device.py index fd8b5d23d..e8b9d6dc3 100644 --- a/src/apps/management/layout_wipe_device.py +++ b/src/apps/management/layout_wipe_device.py @@ -8,7 +8,7 @@ from trezor.workflows.confirm import confirm def layout_wipe_device(message): ui.clear() - ui.display.text(10, 30, 'Wipe device', ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) + 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) diff --git a/src/trezor/ui/scroll.py b/src/trezor/ui/scroll.py new file mode 100644 index 000000000..956d02868 --- /dev/null +++ b/src/trezor/ui/scroll.py @@ -0,0 +1,32 @@ +from . import display +from trezor import ui, loop, res + + +class Scroll(): + + def __init__(self, page=0, totale_lines=0, lines_per_page=4): + self.page = page + self.totale_lines = totale_lines + self.lines_per_page = lines_per_page + + def render(self): + count = len(self.totale_lines) // self.lines_per_page + padding = 20 + screen_height = const(220) + cursor = 8 + + if count * padding > screen_height: + padding = screen_height // count + + x = 220 + y = (10 + (screen_height // 2)) - ((count // 2) * padding) + + for i in range(0, count): + if (i != self.page): + ui.display.bar(x, y + i * padding, cursor, cursor, ui.GREY) + ui.display.bar(x, y + self.page * padding, cursor, cursor, ui.WHITE) + + def wait(self): + while True: + self.render() +