1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 13:58:08 +00:00

feat(core): create progress.py

This commit is contained in:
grdddj 2023-05-04 14:38:31 +02:00 committed by Martin Milata
parent 127e399d28
commit 264b92e11c
9 changed files with 85 additions and 71 deletions

View File

@ -153,6 +153,8 @@ trezor.ui.layouts.fido
import trezor.ui.layouts.fido
trezor.ui.layouts.homescreen
import trezor.ui.layouts.homescreen
trezor.ui.layouts.progress
import trezor.ui.layouts.progress
trezor.ui.layouts.recovery
import trezor.ui.layouts.recovery
trezor.ui.layouts.reset
@ -165,6 +167,8 @@ trezor.ui.layouts.tt_v2.fido
import trezor.ui.layouts.tt_v2.fido
trezor.ui.layouts.tt_v2.homescreen
import trezor.ui.layouts.tt_v2.homescreen
trezor.ui.layouts.tt_v2.progress
import trezor.ui.layouts.tt_v2.progress
trezor.ui.layouts.tt_v2.recovery
import trezor.ui.layouts.tt_v2.recovery
trezor.ui.layouts.tt_v2.reset

View File

@ -111,7 +111,7 @@ class Progress:
def report_init(self) -> None:
from trezor import workflow
from trezor.ui.layouts import bitcoin_progress, coinjoin_progress
from trezor.ui.layouts.progress import bitcoin_progress, coinjoin_progress
progress_layout = bitcoin_progress
if self.is_coinjoin:

View File

@ -97,7 +97,7 @@ _progress_obj: ProgressLayout | None = None
def _start_progress() -> None:
from trezor import workflow
from trezor.ui.layouts import progress
from trezor.ui.layouts.progress import progress
global _progress_obj

View File

@ -11,7 +11,7 @@ _progress_obj: ProgressLayout | None = None
async def get_firmware_hash(ctx: Context, msg: GetFirmwareHash) -> FirmwareHash:
from trezor.messages import FirmwareHash
from trezor.utils import firmware_hash
from trezor.ui.layouts import progress
from trezor.ui.layouts.progress import progress
from trezor import wire, workflow
workflow.close_others()

View File

@ -1,9 +1,8 @@
from typing import TYPE_CHECKING
from trezor.enums import ButtonRequestType
from trezor.ui.layouts import ( # noqa: F401
confirm_action,
confirm_metadata,
from trezor.ui.layouts import confirm_action, confirm_metadata # noqa: F401
from trezor.ui.layouts.progress import ( # noqa: F401
monero_keyimage_sync_progress,
monero_live_refresh_progress,
monero_transaction_progress_inner,

View File

@ -25,7 +25,7 @@ def allow_all_loader_messages() -> None:
def render_empty_loader(message: str, description: str) -> None:
"""Render empty loader to prevent the screen appear to be frozen."""
from trezor.ui.layouts import pin_progress
from trezor.ui.layouts.progress import pin_progress
global _progress_layout
global _started_with_empty_loader
@ -37,7 +37,7 @@ def render_empty_loader(message: str, description: str) -> None:
def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
from trezor.ui.layouts import pin_progress
from trezor.ui.layouts.progress import pin_progress
# Possibility to ignore certain messages - not showing loader for them
if message in _ignore_loader_messages:

View File

@ -0,0 +1 @@
from .tt_v2.progress import * # noqa: F401,F403

View File

@ -12,7 +12,7 @@ if TYPE_CHECKING:
from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar
from trezor.wire import GenericContext, Context
from ..common import PropertyType, ExceptionType, ProgressLayout
from ..common import PropertyType, ExceptionType
T = TypeVar("T")
@ -1256,65 +1256,3 @@ async def confirm_set_new_pin(
description="\n\n".join(information),
br_code=br_code,
)
class RustProgress:
def __init__(
self,
layout: Any,
):
self.layout = layout
ui.backlight_fade(ui.style.BACKLIGHT_DIM)
ui.display.clear()
self.layout.attach_timer_fn(self.set_timer)
self.layout.paint()
ui.backlight_fade(ui.style.BACKLIGHT_NORMAL)
def set_timer(self, token: int, deadline: int) -> None:
raise RuntimeError # progress layouts should not set timers
def report(self, value: int, description: str | None = None):
msg = self.layout.progress_event(value, description or "")
assert msg is None
self.layout.paint()
ui.refresh()
def progress(
message: str = "PLEASE WAIT",
description: str | None = None,
indeterminate: bool = False,
) -> ProgressLayout:
return RustProgress(
layout=trezorui2.show_progress(
title=message.upper(),
indeterminate=indeterminate,
description=description or "",
)
)
def bitcoin_progress(message: str) -> ProgressLayout:
return progress(message)
def coinjoin_progress(message: str) -> ProgressLayout:
return RustProgress(
layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False)
)
def pin_progress(message: str, description: str) -> ProgressLayout:
return progress(message, description=description)
def monero_keyimage_sync_progress() -> ProgressLayout:
return progress("SYNCING")
def monero_live_refresh_progress() -> ProgressLayout:
return progress("REFRESHING", indeterminate=True)
def monero_transaction_progress_inner() -> ProgressLayout:
return progress("SIGNING TRANSACTION")

View File

@ -0,0 +1,72 @@
from typing import TYPE_CHECKING
from trezor import ui
import trezorui2
if TYPE_CHECKING:
from typing import Any
from ..common import ProgressLayout
class RustProgress:
def __init__(
self,
layout: Any,
):
self.layout = layout
ui.backlight_fade(ui.style.BACKLIGHT_DIM)
ui.display.clear()
self.layout.attach_timer_fn(self.set_timer)
self.layout.paint()
ui.backlight_fade(ui.style.BACKLIGHT_NORMAL)
def set_timer(self, token: int, deadline: int) -> None:
raise RuntimeError # progress layouts should not set timers
def report(self, value: int, description: str | None = None):
msg = self.layout.progress_event(value, description or "")
assert msg is None
self.layout.paint()
ui.refresh()
def progress(
message: str = "PLEASE WAIT",
description: str | None = None,
indeterminate: bool = False,
) -> ProgressLayout:
return RustProgress(
layout=trezorui2.show_progress(
title=message.upper(),
indeterminate=indeterminate,
description=description or "",
)
)
def bitcoin_progress(message: str) -> ProgressLayout:
return progress(message)
def coinjoin_progress(message: str) -> ProgressLayout:
return RustProgress(
layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False)
)
def pin_progress(message: str, description: str) -> ProgressLayout:
return progress(message, description=description)
def monero_keyimage_sync_progress() -> ProgressLayout:
return progress("SYNCING")
def monero_live_refresh_progress() -> ProgressLayout:
return progress("REFRESHING", indeterminate=True)
def monero_transaction_progress_inner() -> ProgressLayout:
return progress("SIGNING TRANSACTION")