mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
add Text, move Loader to ui.loader
This commit is contained in:
parent
44479b38d0
commit
3f4365eda6
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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(),
|
||||
|
57
src/trezor/ui/loader.py
Normal file
57
src/trezor/ui/loader.py
Normal file
@ -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
|
25
src/trezor/ui/text.py
Normal file
25
src/trezor/ui/text.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user