1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-14 18:48:10 +00:00
trezor-firmware/core/src/apps/debug/show_text.py
Martin Milata f1382bf892 refactor(core): model-dependent UI component directories
They now live under trezor.ui.components.tt. Later
trezor.ui.components.t1 will be added and application code will be
rewritten to not use them directly in order to work on both TT and T1.
2021-02-10 13:57:19 +01:00

50 lines
1.6 KiB
Python

import trezor.messages.DebugLinkShowTextStyle as S
from trezor import ui, wire
from trezor.messages.DebugLinkShowText import DebugLinkShowText
from trezor.messages.Success import Success
from trezor.ui import style, text
from trezor.ui.components.tt.text import Text
from apps.common.confirm import confirm
STYLES = {
S.NORMAL: ui.NORMAL,
S.BOLD: ui.BOLD,
S.MONO: ui.MONO,
S.BR: text.BR,
S.BR_HALF: text.BR_HALF,
}
async def show_text(ctx: wire.Context, msg: DebugLinkShowText) -> Success:
if msg.header_icon is not None:
icon_name = "ICON_" + msg.header_icon
icon = getattr(style, icon_name)
if not isinstance(icon, str):
raise wire.DataError("Invalid icon name: {}".format(msg.header_icon))
else:
icon = style.ICON_DEFAULT
if msg.icon_color is not None:
color = getattr(style, msg.icon_color)
if not isinstance(color, int):
raise wire.DataError("Invalid color name: {}".format(msg.icon_color))
else:
color = style.ORANGE_ICON
dlg = Text(msg.header_text, icon, color, new_lines=False)
for item in msg.body_text:
if item.style in STYLES:
dlg.content.append(STYLES[item.style])
elif item.style == S.SET_COLOR:
color = getattr(style, item.content)
if not isinstance(color, int):
raise wire.DataError("Invalid color name: {}".format(item.content))
dlg.content.append(color)
elif item.content is not None:
dlg.content.append(item.content)
await confirm(ctx, dlg)
return Success("text shown")