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