mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 23:40:58 +00:00
core/ui: introduce draw_simple
This commit is contained in:
parent
d5763d9cab
commit
aa6988a556
@ -2,6 +2,7 @@ import storage.device
|
||||
from trezor import ui, utils, workflow
|
||||
from trezor.crypto import bip39, slip39
|
||||
from trezor.messages import BackupType
|
||||
from trezor.ui.text import Text
|
||||
|
||||
if False:
|
||||
from typing import Optional, Tuple
|
||||
@ -59,11 +60,8 @@ def _start_progress() -> None:
|
||||
# should make sure that no other layout is running. At this point, only
|
||||
# the homescreen should be on, so shut it down.
|
||||
workflow.kill_default()
|
||||
ui.backlight_fade(ui.BACKLIGHT_DIM)
|
||||
ui.display.clear()
|
||||
ui.header("Please wait")
|
||||
ui.refresh()
|
||||
ui.backlight_fade(ui.BACKLIGHT_NORMAL)
|
||||
t = Text("Please wait", ui.ICON_CONFIG)
|
||||
ui.draw_simple(t)
|
||||
|
||||
|
||||
def _render_progress(progress: int, total: int) -> None:
|
||||
|
@ -7,9 +7,8 @@ from trezor.messages.ButtonAck import ButtonAck
|
||||
from trezor.messages.ButtonRequest import ButtonRequest
|
||||
from trezor.messages.PassphraseAck import PassphraseAck
|
||||
from trezor.messages.PassphraseRequest import PassphraseRequest
|
||||
from trezor.ui import ICON_CONFIG
|
||||
from trezor.ui import ICON_CONFIG, draw_simple
|
||||
from trezor.ui.passphrase import CANCELLED, PassphraseKeyboard
|
||||
from trezor.ui.popup import Popup
|
||||
from trezor.ui.text import Text
|
||||
|
||||
if __debug__:
|
||||
@ -24,12 +23,12 @@ def is_enabled() -> bool:
|
||||
|
||||
async def get(ctx: wire.Context) -> str:
|
||||
if is_enabled():
|
||||
return await request_from_user(ctx)
|
||||
return await _request_from_user(ctx)
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
async def request_from_user(ctx: wire.Context) -> str:
|
||||
async def _request_from_user(ctx: wire.Context) -> str:
|
||||
passphrase = await _get_from_user(ctx)
|
||||
if len(passphrase) > _MAX_PASSPHRASE_LEN:
|
||||
raise wire.DataError("Maximum passphrase length is %d" % _MAX_PASSPHRASE_LEN)
|
||||
@ -39,16 +38,19 @@ async def request_from_user(ctx: wire.Context) -> str:
|
||||
|
||||
async def _get_from_user(ctx: wire.Context) -> str:
|
||||
if storage.device.get_passphrase_always_on_device():
|
||||
return await request_from_user_on_device(ctx)
|
||||
return await _request_from_user_on_device(ctx)
|
||||
return await _request_from_host(ctx)
|
||||
|
||||
await _entry_dialog()
|
||||
|
||||
async def _request_from_host(ctx: wire.Context) -> str:
|
||||
_entry_dialog()
|
||||
|
||||
request = PassphraseRequest()
|
||||
ack = await ctx.call(request, PassphraseAck)
|
||||
if ack.on_device:
|
||||
if ack.passphrase is not None:
|
||||
raise wire.DataError("Passphrase provided when it should not be")
|
||||
return await request_from_user_on_device(ctx)
|
||||
return await _request_from_user_on_device(ctx)
|
||||
|
||||
if ack.passphrase is None:
|
||||
raise wire.DataError(
|
||||
@ -57,7 +59,7 @@ async def _get_from_user(ctx: wire.Context) -> str:
|
||||
return ack.passphrase
|
||||
|
||||
|
||||
async def request_from_user_on_device(ctx: wire.Context) -> str:
|
||||
async def _request_from_user_on_device(ctx: wire.Context) -> str:
|
||||
await ctx.call(ButtonRequest(code=ButtonRequestType.PassphraseEntry), ButtonAck)
|
||||
|
||||
keyboard = PassphraseKeyboard("Enter passphrase", _MAX_PASSPHRASE_LEN)
|
||||
@ -73,10 +75,7 @@ async def request_from_user_on_device(ctx: wire.Context) -> str:
|
||||
return passphrase
|
||||
|
||||
|
||||
async def _entry_dialog() -> None:
|
||||
def _entry_dialog() -> None:
|
||||
text = Text("Passphrase entry", ICON_CONFIG)
|
||||
text.normal("Please type your", "passphrase on the", "connected host.")
|
||||
# no need to specify timeout, because it hangs till PassphraseAck is received
|
||||
# TODO ask: not sure this is correct. If we change the behaviour of Popup
|
||||
# (e.g. to be redrawn after the timeout expires) this will no longer display the dialog
|
||||
await Popup(text)
|
||||
draw_simple(text)
|
||||
|
@ -160,6 +160,14 @@ def header_error(message: str, clear: bool = True) -> None:
|
||||
display.bar(0, 30, WIDTH, HEIGHT - 30, style.BG)
|
||||
|
||||
|
||||
def draw_simple(t: Component) -> None: # noqa: F405
|
||||
backlight_fade(style.BACKLIGHT_DIM)
|
||||
display.clear()
|
||||
t.on_render()
|
||||
refresh()
|
||||
backlight_fade(style.BACKLIGHT_NORMAL)
|
||||
|
||||
|
||||
def grid(
|
||||
i: int, # i-th cell of the table of which we wish to return Area (snake-like starting with 0)
|
||||
n_x: int = 3, # number of rows in the table
|
||||
|
Loading…
Reference in New Issue
Block a user