parent
44479b38d0
commit
3f4365eda6
@ -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
|
@ -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