mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 05:28:40 +00:00
chore(core): delete unused code from micropython UI
[no changelog]
This commit is contained in:
parent
021f41c23a
commit
b08a6fe2c1
@ -572,7 +572,6 @@ if FROZEN:
|
||||
SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py')
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/res/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/common/*.py'))
|
||||
|
@ -524,7 +524,6 @@ if FROZEN:
|
||||
SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py')
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/res/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/common/*.py'))
|
||||
|
@ -137,18 +137,12 @@ trezor.pin
|
||||
import trezor.pin
|
||||
trezor.protobuf
|
||||
import trezor.protobuf
|
||||
trezor.res
|
||||
import trezor.res
|
||||
trezor.res.resources
|
||||
import trezor.res.resources
|
||||
trezor.sdcard
|
||||
import trezor.sdcard
|
||||
trezor.strings
|
||||
import trezor.strings
|
||||
trezor.ui
|
||||
import trezor.ui
|
||||
trezor.ui.components.common.confirm
|
||||
import trezor.ui.components.common.confirm
|
||||
trezor.ui.layouts
|
||||
import trezor.ui.layouts
|
||||
trezor.ui.layouts.common
|
||||
@ -173,10 +167,6 @@ trezor.ui.layouts.tt_v2.recovery
|
||||
import trezor.ui.layouts.tt_v2.recovery
|
||||
trezor.ui.layouts.tt_v2.reset
|
||||
import trezor.ui.layouts.tt_v2.reset
|
||||
trezor.ui.loader
|
||||
import trezor.ui.loader
|
||||
trezor.ui.popup
|
||||
import trezor.ui.popup
|
||||
trezor.ui.style
|
||||
import trezor.ui.style
|
||||
trezor.utils
|
||||
|
@ -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.
@ -4,7 +4,7 @@ from micropython import const
|
||||
from trezorui import Display
|
||||
from typing import TYPE_CHECKING, Any, Awaitable, Generator
|
||||
|
||||
from trezor import io, loop, res, utils, workflow
|
||||
from trezor import io, loop, utils, workflow
|
||||
|
||||
# all rendering is done through a singleton of `Display`
|
||||
display = Display()
|
||||
@ -50,10 +50,6 @@ if utils.EMULATOR or utils.MODEL in ("1", "R"):
|
||||
loop.after_step_hook = refresh
|
||||
|
||||
|
||||
def rgb(r: int, g: int, b: int) -> int:
|
||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3)
|
||||
|
||||
|
||||
# import style later to avoid circular dep
|
||||
from trezor.ui import style # isort:skip
|
||||
|
||||
@ -102,45 +98,6 @@ def backlight_fade(val: int, delay: int = 14000, step: int = 15) -> None:
|
||||
display.backlight(val)
|
||||
|
||||
|
||||
def header(
|
||||
title: str,
|
||||
icon: str = style.ICON_DEFAULT,
|
||||
fg: int = style.FG,
|
||||
bg: int = style.BG,
|
||||
ifg: int = style.GREEN,
|
||||
) -> None:
|
||||
if icon is not None:
|
||||
display.icon(14, 15, res.load(icon), ifg, bg)
|
||||
display.text(44, 35, title, BOLD, fg, bg)
|
||||
|
||||
|
||||
# Common for both header functions
|
||||
MODEL_HEADER_HEIGHTS = {"1": 12, "R": 15, "T": 30}
|
||||
MODEL_Y_BASELINES = {"1": 10, "R": 11, "T": 22}
|
||||
|
||||
|
||||
def header_warning(message: str) -> None:
|
||||
height = MODEL_HEADER_HEIGHTS[utils.MODEL]
|
||||
y_baseline = MODEL_Y_BASELINES[utils.MODEL]
|
||||
|
||||
display.bar(0, 0, WIDTH, height, style.YELLOW)
|
||||
display.text_center(
|
||||
WIDTH // 2, y_baseline, message, BOLD, style.BLACK, style.YELLOW
|
||||
)
|
||||
|
||||
|
||||
def header_error(message: str) -> None:
|
||||
height = MODEL_HEADER_HEIGHTS[utils.MODEL]
|
||||
y_baseline = MODEL_Y_BASELINES[utils.MODEL]
|
||||
|
||||
display.bar(0, 0, WIDTH, height, style.RED)
|
||||
display.text_center(WIDTH // 2, y_baseline, message, BOLD, style.WHITE, style.RED)
|
||||
|
||||
|
||||
def get_header_height() -> int:
|
||||
return MODEL_HEADER_HEIGHTS[utils.MODEL]
|
||||
|
||||
|
||||
# Component events. Should be different from `io.TOUCH_*` events.
|
||||
# Event dispatched when components should draw to the display, if they are
|
||||
# marked for re-paint.
|
||||
|
@ -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)
|
@ -6,7 +6,6 @@ from trezor.utils import DISABLE_ANIMATION
|
||||
|
||||
import trezorui2
|
||||
|
||||
from ...components.common.confirm import is_confirmed
|
||||
from ..common import button_request, interact
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -19,6 +18,10 @@ if __debug__:
|
||||
trezorui2.disable_animation(bool(DISABLE_ANIMATION))
|
||||
|
||||
|
||||
def is_confirmed(x: Any) -> bool:
|
||||
return x is trezorui2.CONFIRMED
|
||||
|
||||
|
||||
class RustLayout(ui.Layout):
|
||||
# pylint: disable=super-init-not-called
|
||||
def __init__(self, layout: Any):
|
||||
@ -256,10 +259,6 @@ async def confirm_blob(
|
||||
raise wire.ActionCancelled
|
||||
|
||||
|
||||
def draw_simple_text(title: str, description: str = "") -> None:
|
||||
log.error(__name__, "draw_simple_text not implemented")
|
||||
|
||||
|
||||
async def request_pin_on_device(
|
||||
ctx: wire.GenericContext,
|
||||
prompt: str,
|
||||
|
@ -562,9 +562,7 @@ async def confirm_payment_request(
|
||||
recipient_name: str,
|
||||
amount: str,
|
||||
memos: list[str],
|
||||
) -> Any:
|
||||
from ...components.common import confirm
|
||||
|
||||
) -> bool:
|
||||
result = await interact(
|
||||
ctx,
|
||||
RustLayout(
|
||||
@ -579,10 +577,13 @@ async def confirm_payment_request(
|
||||
"confirm_payment_request",
|
||||
ButtonRequestType.ConfirmOutput,
|
||||
)
|
||||
|
||||
# When user pressed INFO, returning False, which gets processed in higher function
|
||||
# to differentiate it from CONFIRMED. Raising otherwise.
|
||||
if result is CONFIRMED:
|
||||
return confirm.CONFIRMED
|
||||
return True
|
||||
elif result is INFO:
|
||||
return confirm.INFO
|
||||
return False
|
||||
else:
|
||||
raise ActionCancelled
|
||||
|
||||
@ -663,7 +664,7 @@ async def _confirm_ask_pagination(
|
||||
paginated.request_complete_repaint()
|
||||
|
||||
result = await interact(ctx, paginated, br_type, br_code)
|
||||
assert result in (trezorui2.CONFIRMED, trezorui2.CANCELLED)
|
||||
assert result in (CONFIRMED, CANCELLED)
|
||||
|
||||
assert False
|
||||
|
||||
@ -1060,10 +1061,6 @@ async def show_popup(
|
||||
)
|
||||
|
||||
|
||||
def draw_simple_text(title: str, description: str = "") -> None:
|
||||
log.error(__name__, "draw_simple_text not implemented")
|
||||
|
||||
|
||||
def request_passphrase_on_host() -> None:
|
||||
draw_simple(
|
||||
trezorui2.show_info(
|
||||
|
@ -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)
|
@ -1,31 +1,8 @@
|
||||
from micropython import const
|
||||
|
||||
from trezor.ui import rgb
|
||||
|
||||
# backlight brightness
|
||||
BACKLIGHT_NORMAL = const(150)
|
||||
BACKLIGHT_LOW = const(45)
|
||||
BACKLIGHT_DIM = const(5)
|
||||
BACKLIGHT_NONE = const(0)
|
||||
BACKLIGHT_MAX = const(255)
|
||||
|
||||
# color palette
|
||||
RED = rgb(0xFF, 0x00, 0x00)
|
||||
BLUE = rgb(0x21, 0x96, 0xF3)
|
||||
GREEN = rgb(0x00, 0xAE, 0x0B)
|
||||
YELLOW = rgb(0xFF, 0xEB, 0x3B)
|
||||
BLACK = rgb(0x00, 0x00, 0x00)
|
||||
WHITE = rgb(0xFA, 0xFA, 0xFA)
|
||||
|
||||
TITLE_GREY = rgb(0x9B, 0x9B, 0x9B)
|
||||
|
||||
# common color styles
|
||||
BG = BLACK
|
||||
FG = WHITE
|
||||
|
||||
# icons
|
||||
ICON_CONFIG = "trezor/res/header_icons/cog.toif"
|
||||
ICON_SEND = "trezor/res/header_icons/send.toif"
|
||||
ICON_CLICK = "trezor/res/click.toif"
|
||||
ICON_CHECK = "trezor/res/check.toif"
|
||||
ICON_DEFAULT = ICON_CONFIG
|
||||
|
Loading…
Reference in New Issue
Block a user