mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
refactor(core): call super().__init__() in Component and Layout subclasses
This commit is contained in:
parent
76eb54b6f8
commit
fa1566cb71
@ -6,11 +6,11 @@ class HomescreenBase(ui.Layout):
|
||||
RENDER_SLEEP = loop.SLEEP_FOREVER
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.label = storage.device.get_label() or "My Trezor"
|
||||
self.image = storage.device.get_homescreen() or res.load(
|
||||
"apps/homescreen/res/bg.toif"
|
||||
)
|
||||
self.repaint = True
|
||||
|
||||
def on_tap(self) -> None:
|
||||
"""Called when the user taps the screen."""
|
||||
|
@ -87,8 +87,8 @@ class InputButton(Button):
|
||||
|
||||
class Prompt(ui.Component):
|
||||
def __init__(self, prompt: str) -> None:
|
||||
super().__init__()
|
||||
self.prompt = prompt
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
@ -99,6 +99,7 @@ class Prompt(ui.Component):
|
||||
|
||||
class Bip39Keyboard(ui.Layout):
|
||||
def __init__(self, prompt: str) -> None:
|
||||
super().__init__()
|
||||
self.prompt = Prompt(prompt)
|
||||
|
||||
icon_back = res.load(ui.ICON_BACK)
|
||||
|
@ -90,8 +90,8 @@ class InputButton(Button):
|
||||
|
||||
class Prompt(ui.Component):
|
||||
def __init__(self, prompt: str) -> None:
|
||||
super().__init__()
|
||||
self.prompt = prompt
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
@ -102,6 +102,7 @@ class Prompt(ui.Component):
|
||||
|
||||
class Slip39Keyboard(ui.Layout):
|
||||
def __init__(self, prompt: str) -> None:
|
||||
super().__init__()
|
||||
self.prompt = Prompt(prompt)
|
||||
|
||||
icon_back = res.load(ui.ICON_BACK)
|
||||
|
@ -206,10 +206,10 @@ async def show_group_threshold_reached(ctx: wire.GenericContext) -> None:
|
||||
|
||||
class RecoveryHomescreen(ui.Component):
|
||||
def __init__(self, text: str, subtext: str = None):
|
||||
super().__init__()
|
||||
self.text = text
|
||||
self.subtext = subtext
|
||||
self.dry_run = storage.recovery.is_dry_run()
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if not self.repaint:
|
||||
|
@ -524,10 +524,10 @@ class Slip39NumInput(ui.Component):
|
||||
SET_GROUP_THRESHOLD = object()
|
||||
|
||||
def __init__(self, step, count, min_count, max_count, group_id=None):
|
||||
super().__init__()
|
||||
self.step = step
|
||||
self.input = NumInput(count, min_count=min_count, max_count=max_count)
|
||||
self.input.on_change = self.on_change
|
||||
self.repaint = True
|
||||
self.group_id = group_id
|
||||
|
||||
def dispatch(self, event, x, y):
|
||||
@ -605,6 +605,7 @@ class MnemonicWordSelect(ui.Layout):
|
||||
NUM_OF_CHOICES = 3
|
||||
|
||||
def __init__(self, words, share_index, word_index, count, group_index=None):
|
||||
super().__init__()
|
||||
self.words = words
|
||||
self.share_index = share_index
|
||||
self.word_index = word_index
|
||||
|
@ -143,6 +143,7 @@ async def _require_confirm_unlock_time(ctx, unlock_time):
|
||||
|
||||
class TransactionStep(ui.Component):
|
||||
def __init__(self, state, info):
|
||||
super().__init__()
|
||||
self.state = state
|
||||
self.info = info
|
||||
|
||||
@ -159,6 +160,7 @@ class TransactionStep(ui.Component):
|
||||
|
||||
class KeyImageSyncStep(ui.Component):
|
||||
def __init__(self, current, total_num):
|
||||
super().__init__()
|
||||
self.current = current
|
||||
self.total_num = total_num
|
||||
|
||||
@ -172,6 +174,7 @@ class KeyImageSyncStep(ui.Component):
|
||||
|
||||
class LiveRefreshStep(ui.Component):
|
||||
def __init__(self, current):
|
||||
super().__init__()
|
||||
self.current = current
|
||||
|
||||
def on_render(self):
|
||||
|
@ -16,6 +16,7 @@ if False:
|
||||
|
||||
class ConfirmAddCredential(ConfirmInfo):
|
||||
def __init__(self, cred: Fido2Credential):
|
||||
super().__init__()
|
||||
self._cred = cred
|
||||
self.load_icon(cred.rp_id_hash)
|
||||
|
||||
|
@ -34,8 +34,8 @@ class ConfirmInfo:
|
||||
|
||||
class ConfirmContent(ui.Component):
|
||||
def __init__(self, info: ConfirmInfo) -> None:
|
||||
super().__init__()
|
||||
self.info = info
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
|
@ -18,6 +18,7 @@ if False:
|
||||
|
||||
class ConfirmRemoveCredential(ConfirmInfo):
|
||||
def __init__(self, cred: Fido2Credential):
|
||||
super().__init__()
|
||||
self._cred = cred
|
||||
self.load_icon(cred.rp_id_hash)
|
||||
|
||||
|
@ -238,6 +238,9 @@ class Component:
|
||||
an instance of `Result`.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.repaint = True
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
if event is RENDER:
|
||||
self.on_render()
|
||||
|
@ -133,6 +133,7 @@ class Button(ui.Component):
|
||||
content: ButtonContent,
|
||||
style: ButtonStyleType = ButtonDefault,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
if isinstance(content, str):
|
||||
self.text = content
|
||||
self.icon = b""
|
||||
@ -146,7 +147,6 @@ class Button(ui.Component):
|
||||
self.active_style = style.active
|
||||
self.disabled_style = style.disabled
|
||||
self.state = _INITIAL
|
||||
self.repaint = True
|
||||
|
||||
def enable(self) -> None:
|
||||
if self.state is not _INITIAL:
|
||||
|
@ -15,11 +15,11 @@ _CHECKLIST_OFFSET_X_ICON = const(0)
|
||||
|
||||
class Checklist(ui.Component):
|
||||
def __init__(self, title: str, icon: str) -> None:
|
||||
super().__init__()
|
||||
self.title = title
|
||||
self.icon = icon
|
||||
self.items = [] # type: List[ChecklistItem]
|
||||
self.active = 0
|
||||
self.repaint = True
|
||||
|
||||
def add(self, item: ChecklistItem) -> None:
|
||||
self.items.append(item)
|
||||
|
@ -38,6 +38,7 @@ class Confirm(ui.Layout):
|
||||
cancel_style: ButtonStyleType = DEFAULT_CANCEL_STYLE,
|
||||
major_confirm: bool = False,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.content = content
|
||||
|
||||
if confirm is not None:
|
||||
@ -192,6 +193,7 @@ class InfoConfirm(ui.Layout):
|
||||
info: ButtonContent = DEFAULT_INFO,
|
||||
info_style: ButtonStyleType = DEFAULT_INFO_STYLE,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.content = content
|
||||
|
||||
self.confirm = Button(ui.grid(14), confirm, confirm_style)
|
||||
@ -243,6 +245,7 @@ class HoldToConfirm(ui.Layout):
|
||||
loader_style: LoaderStyleType = DEFAULT_LOADER_STYLE,
|
||||
cancel: bool = True,
|
||||
):
|
||||
super().__init__()
|
||||
self.content = content
|
||||
|
||||
self.loader = Loader(loader_style)
|
||||
|
@ -6,6 +6,7 @@ if False:
|
||||
|
||||
class Container(ui.Component):
|
||||
def __init__(self, *children: ui.Component):
|
||||
super().__init__()
|
||||
self.children = children
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
|
@ -35,6 +35,7 @@ class InfoConfirm(ui.Layout):
|
||||
confirm: ButtonContent = DEFAULT_CONFIRM,
|
||||
style: InfoConfirmStyleType = DEFAULT_STYLE,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.text = text.split()
|
||||
self.style = style
|
||||
panel_area = ui.grid(0, n_x=1, n_y=1)
|
||||
@ -42,7 +43,6 @@ class InfoConfirm(ui.Layout):
|
||||
confirm_area = ui.grid(4, n_x=1)
|
||||
self.confirm = Button(confirm_area, confirm, style.button)
|
||||
self.confirm.on_click = self.on_confirm # type: ignore
|
||||
self.repaint = True
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
if event == ui.RENDER:
|
||||
|
@ -39,6 +39,7 @@ _TARGET_MS = const(1000)
|
||||
|
||||
class Loader(ui.Component):
|
||||
def __init__(self, style: LoaderStyleType = LoaderDefault) -> None:
|
||||
super().__init__()
|
||||
self.normal_style = style.normal
|
||||
self.active_style = style.active
|
||||
self.target_ms = _TARGET_MS
|
||||
@ -98,6 +99,7 @@ class Loader(ui.Component):
|
||||
|
||||
class LoadingAnimation(ui.Layout):
|
||||
def __init__(self, style: LoaderStyleType = LoaderDefault) -> None:
|
||||
super().__init__()
|
||||
self.loader = Loader(style)
|
||||
self.loader.on_finish = self.on_finish # type: ignore
|
||||
self.loader.start()
|
||||
|
@ -5,6 +5,7 @@ from trezor.ui.text import LABEL_CENTER, Label
|
||||
|
||||
class NumInput(ui.Component):
|
||||
def __init__(self, count: int = 5, max_count: int = 16, min_count: int = 1) -> None:
|
||||
super().__init__()
|
||||
self.count = count
|
||||
self.max_count = max_count
|
||||
self.min_count = min_count
|
||||
|
@ -115,8 +115,8 @@ class Input(Button):
|
||||
|
||||
class Prompt(ui.Component):
|
||||
def __init__(self, text: str) -> None:
|
||||
super().__init__()
|
||||
self.text = text
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
@ -130,6 +130,7 @@ CANCELLED = object()
|
||||
|
||||
class PassphraseKeyboard(ui.Layout):
|
||||
def __init__(self, prompt: str, max_length: int, page: int = 1) -> None:
|
||||
super().__init__()
|
||||
self.prompt = Prompt(prompt)
|
||||
self.max_length = max_length
|
||||
self.page = page
|
||||
|
@ -32,10 +32,10 @@ def generate_digits() -> Iterable[int]:
|
||||
|
||||
class PinInput(ui.Component):
|
||||
def __init__(self, prompt: str, subprompt: Optional[str], pin: str) -> None:
|
||||
super().__init__()
|
||||
self.prompt = prompt
|
||||
self.subprompt = subprompt
|
||||
self.pin = pin
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
|
@ -6,6 +6,7 @@ if False:
|
||||
|
||||
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
|
||||
|
@ -3,11 +3,11 @@ from trezor import ui
|
||||
|
||||
class Qr(ui.Component):
|
||||
def __init__(self, data: str, x: int, y: int, scale: int):
|
||||
super().__init__()
|
||||
self.data = data
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.scale = scale
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
|
@ -51,10 +51,10 @@ class Paginated(ui.Layout):
|
||||
def __init__(
|
||||
self, pages: List[ui.Component], page: int = 0, one_by_one: bool = False
|
||||
):
|
||||
super().__init__()
|
||||
self.pages = pages
|
||||
self.page = page
|
||||
self.one_by_one = one_by_one
|
||||
self.repaint = True
|
||||
|
||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||
pages = self.pages
|
||||
@ -131,6 +131,7 @@ class PageWithButtons(ui.Component):
|
||||
index: int,
|
||||
count: int,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.content = content
|
||||
self.paginated = paginated
|
||||
self.index = index
|
||||
@ -188,6 +189,7 @@ class PaginatedWithButtons(ui.Layout):
|
||||
def __init__(
|
||||
self, pages: List[ui.Component], page: int = 0, one_by_one: bool = False
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.pages = [
|
||||
PageWithButtons(p, self, i, len(pages)) for i, p in enumerate(pages)
|
||||
]
|
||||
|
@ -19,6 +19,7 @@ _SWIPE_TRESHOLD = const(30)
|
||||
|
||||
class Swipe(ui.Component):
|
||||
def __init__(self, directions: int = SWIPE_ALL, area: ui.Area = None) -> None:
|
||||
super().__init__()
|
||||
if area is None:
|
||||
area = (0, 0, ui.WIDTH, ui.HEIGHT)
|
||||
self.area = area
|
||||
|
@ -129,13 +129,13 @@ class Text(ui.Component):
|
||||
max_lines: int = TEXT_MAX_LINES,
|
||||
new_lines: bool = True,
|
||||
):
|
||||
super().__init__()
|
||||
self.header_text = header_text
|
||||
self.header_icon = header_icon
|
||||
self.icon_color = icon_color
|
||||
self.max_lines = max_lines
|
||||
self.new_lines = new_lines
|
||||
self.content = [] # type: List[TextContent]
|
||||
self.repaint = True
|
||||
|
||||
def normal(self, *content: TextContent) -> None:
|
||||
self.content.append(ui.NORMAL)
|
||||
@ -187,11 +187,11 @@ class Label(ui.Component):
|
||||
align: int = LABEL_LEFT,
|
||||
style: int = ui.NORMAL,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.area = area
|
||||
self.content = content
|
||||
self.align = align
|
||||
self.style = style
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
|
@ -10,6 +10,7 @@ if False:
|
||||
|
||||
class WordSelector(ui.Layout):
|
||||
def __init__(self, content: ui.Component) -> None:
|
||||
super().__init__()
|
||||
self.content = content
|
||||
self.w12 = Button(ui.grid(6, n_y=4), "12")
|
||||
self.w12.on_click = self.on_w12 # type: ignore
|
||||
|
Loading…
Reference in New Issue
Block a user