parent
021f41c23a
commit
b08a6fe2c1
@ -1,21 +0,0 @@
|
||||
try:
|
||||
from .resources import load_resource
|
||||
except ImportError:
|
||||
raise RuntimeError("Please regenerate resources via 'make templates'")
|
||||
|
||||
|
||||
def load(name: str) -> bytes:
|
||||
"""
|
||||
Loads resource of a given name as bytes.
|
||||
"""
|
||||
return load_resource(name)
|
||||
|
||||
|
||||
def gettext(message: str) -> str:
|
||||
"""
|
||||
Returns localized string. This function is aliased to _.
|
||||
"""
|
||||
return message
|
||||
|
||||
|
||||
_ = gettext
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,62 +0,0 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from trezor import ui, wire
|
||||
|
||||
import trezorui2
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Callable, Any, Awaitable, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
CONFIRMED = trezorui2.CONFIRMED
|
||||
CANCELLED = trezorui2.CANCELLED
|
||||
INFO = trezorui2.INFO
|
||||
|
||||
|
||||
def is_confirmed(x: Any) -> bool:
|
||||
return x is CONFIRMED
|
||||
|
||||
|
||||
async def raise_if_cancelled(a: Awaitable[T], exc: Any = wire.ActionCancelled) -> T:
|
||||
result = await a
|
||||
if result is CANCELLED:
|
||||
raise exc
|
||||
return result
|
||||
|
||||
|
||||
async def is_confirmed_info(
|
||||
ctx: wire.GenericContext,
|
||||
dialog: ui.Layout,
|
||||
info_func: Callable,
|
||||
) -> bool:
|
||||
while True:
|
||||
result = await ctx.wait(dialog)
|
||||
|
||||
if result is INFO:
|
||||
await info_func(ctx)
|
||||
else:
|
||||
return is_confirmed(result)
|
||||
|
||||
|
||||
class Pageable:
|
||||
def __init__(self) -> None:
|
||||
self._page = 0
|
||||
|
||||
def page(self) -> int:
|
||||
return self._page
|
||||
|
||||
def page_count(self) -> int:
|
||||
raise NotImplementedError
|
||||
|
||||
def is_first(self) -> bool:
|
||||
return self._page == 0
|
||||
|
||||
def is_last(self) -> bool:
|
||||
return self._page == self.page_count() - 1
|
||||
|
||||
def next(self) -> None:
|
||||
self._page = min(self._page + 1, self.page_count() - 1)
|
||||
|
||||
def prev(self) -> None:
|
||||
self._page = max(self._page - 1, 0)
|
@ -1,132 +0,0 @@
|
||||
import utime
|
||||
from micropython import const
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from trezor import res, ui, utils
|
||||
from trezor.ui import display
|
||||
|
||||
|
||||
class LoaderDefault:
|
||||
class normal:
|
||||
bg_color = ui.BG
|
||||
fg_color = ui.GREEN
|
||||
icon: str | None = None
|
||||
icon_fg_color: int | None = None
|
||||
|
||||
class active(normal):
|
||||
bg_color = ui.BG
|
||||
fg_color = ui.GREEN
|
||||
icon: str | None = ui.ICON_CHECK
|
||||
icon_fg_color: int | None = ui.WHITE
|
||||
|
||||
|
||||
class LoaderNeutral(LoaderDefault):
|
||||
class normal(LoaderDefault.normal):
|
||||
fg_color = ui.FG
|
||||
|
||||
class active(LoaderDefault.active):
|
||||
fg_color = ui.FG
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
LoaderStyleType = type[LoaderDefault]
|
||||
|
||||
|
||||
_TARGET_MS = const(1000)
|
||||
_OFFSET_Y = const(-24)
|
||||
_REVERSE_SPEEDUP = const(2)
|
||||
|
||||
|
||||
class Loader(ui.Component):
|
||||
def __init__(
|
||||
self,
|
||||
style: LoaderStyleType = LoaderDefault,
|
||||
target_ms: int = _TARGET_MS,
|
||||
offset_y: int = _OFFSET_Y,
|
||||
reverse_speedup: int = _REVERSE_SPEEDUP,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.normal_style = style.normal
|
||||
self.active_style = style.active
|
||||
self.target_ms = target_ms
|
||||
self.start_ms: int | None = None
|
||||
self.stop_ms: int | None = None
|
||||
self.offset_y = offset_y
|
||||
self.reverse_speedup = reverse_speedup
|
||||
|
||||
def start(self) -> None:
|
||||
if self.start_ms is not None and self.stop_ms is not None:
|
||||
self.start_ms = utime.ticks_ms() - self.elapsed_ms()
|
||||
else:
|
||||
self.start_ms = utime.ticks_ms()
|
||||
self.stop_ms = None
|
||||
self.on_start()
|
||||
|
||||
def stop(self) -> None:
|
||||
self.stop_ms = utime.ticks_ms()
|
||||
|
||||
def elapsed_ms(self) -> int:
|
||||
start = self.start_ms
|
||||
stop = self.stop_ms
|
||||
now = utime.ticks_ms()
|
||||
if start is None:
|
||||
return 0
|
||||
elif stop is not None:
|
||||
return max(stop - start + (stop - now) * self.reverse_speedup, 0)
|
||||
else:
|
||||
return min(now - start, self.target_ms)
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.start_ms is None:
|
||||
return
|
||||
target = self.target_ms
|
||||
r = self.elapsed_ms()
|
||||
if r != target:
|
||||
s = self.normal_style
|
||||
else:
|
||||
s = self.active_style
|
||||
|
||||
progress = r * 1000 // target # scale to 0-1000
|
||||
if s.icon is None:
|
||||
display.loader(progress, False, self.offset_y, s.fg_color, s.bg_color)
|
||||
else:
|
||||
display.loader(
|
||||
progress,
|
||||
False,
|
||||
self.offset_y,
|
||||
s.fg_color,
|
||||
s.bg_color,
|
||||
res.load(s.icon),
|
||||
s.icon_fg_color,
|
||||
)
|
||||
if (r == 0) and (self.stop_ms is not None):
|
||||
self.start_ms = None
|
||||
self.stop_ms = None
|
||||
self.on_start()
|
||||
if r == target:
|
||||
self.on_finish()
|
||||
|
||||
def on_start(self) -> None:
|
||||
pass
|
||||
|
||||
def on_finish(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class LoadingAnimation(ui.Layout):
|
||||
def __init__(self, style: LoaderStyleType = LoaderDefault) -> None:
|
||||
super().__init__()
|
||||
self.loader = Loader(style)
|
||||
self.loader.on_finish = self.on_finish
|
||||
self.loader.start()
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
if not self.loader.elapsed_ms():
|
||||
self.loader.start()
|
||||
self.loader.dispatch(event, x, y)
|
||||
|
||||
if utils.DISABLE_ANIMATION:
|
||||
self.on_finish()
|
||||
|
||||
def on_finish(self) -> None:
|
||||
raise ui.Result(None)
|
@ -1,21 +0,0 @@
|
||||
from trezor import loop, ui, utils
|
||||
|
||||
|
||||
class Popup(ui.Layout):
|
||||
def __init__(self, content: ui.Component, time_ms: int = 0) -> None:
|
||||
super().__init__()
|
||||
self.content = content
|
||||
if utils.DISABLE_ANIMATION:
|
||||
self.time_ms = 0
|
||||
else:
|
||||
self.time_ms = time_ms
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
self.content.dispatch(event, x, y)
|
||||
|
||||
def create_tasks(self) -> tuple[loop.Task, ...]:
|
||||
return self.handle_input(), self.handle_rendering(), self.handle_timeout()
|
||||
|
||||
def handle_timeout(self) -> loop.Task: # type: ignore [awaitable-is-generator]
|
||||
yield loop.sleep(self.time_ms)
|
||||
raise ui.Result(None)
|
Loading…
Reference in new issue