mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 20:11:00 +00:00
ui: render some wrapper components synchronously
This makes the wrappers (like Scrollpage and HoldToConfirmDialog) a bit weaker, as they won't support child components with custom event loop, but making the render/touch steps synchronous has other benefits. For example, io-heavy task of one child won't stall the other children.
This commit is contained in:
parent
139ca3ced4
commit
305a364e73
@ -46,6 +46,9 @@ async def tx_dialog(
|
||||
|
||||
await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck)
|
||||
|
||||
if scroll_tuple and scroll_tuple[1] > 1:
|
||||
content = Scrollpage(content, scroll_tuple[0], scroll_tuple[1])
|
||||
|
||||
dialog = ConfirmDialog(
|
||||
content,
|
||||
cancel=cancel_btn,
|
||||
@ -53,9 +56,6 @@ async def tx_dialog(
|
||||
cancel_style=cancel_style,
|
||||
confirm_style=confirm_style,
|
||||
)
|
||||
if scroll_tuple and scroll_tuple[1] > 1:
|
||||
dialog = Scrollpage(dialog, scroll_tuple[0], scroll_tuple[1])
|
||||
|
||||
return await ctx.wait(dialog)
|
||||
|
||||
|
||||
|
@ -66,6 +66,11 @@ class HoldToConfirmDialog(Widget):
|
||||
self.button = Button(ui.grid(4, n_x=1), hold, style=button_style)
|
||||
self.loader = Loader(style=loader_style)
|
||||
|
||||
if content.__class__.__iter__ is not Widget.__iter__:
|
||||
raise TypeError(
|
||||
"HoldToConfirmDialog does not support widgets with custom event loop"
|
||||
)
|
||||
|
||||
def taint(self):
|
||||
super().taint()
|
||||
self.button.taint()
|
||||
@ -73,6 +78,8 @@ class HoldToConfirmDialog(Widget):
|
||||
|
||||
def render(self):
|
||||
self.button.render()
|
||||
if not self.loader.is_active():
|
||||
self.content.render()
|
||||
|
||||
def touch(self, event, pos):
|
||||
button = self.button
|
||||
@ -94,12 +101,15 @@ class HoldToConfirmDialog(Widget):
|
||||
result = None
|
||||
while result is None or result < 0: # _STARTED or _STOPPED
|
||||
if self.loader.is_active():
|
||||
content_loop = self.loader
|
||||
else:
|
||||
content_loop = self.content
|
||||
confirm_loop = super().__iter__() # default loop (render on touch)
|
||||
if __debug__:
|
||||
result = await loop.spawn(content_loop, confirm_loop, confirm_signal)
|
||||
result = await loop.spawn(
|
||||
self.loader, super().__iter__(), confirm_signal
|
||||
)
|
||||
else:
|
||||
result = await loop.spawn(content_loop, confirm_loop)
|
||||
result = await loop.spawn(self.loader, super().__iter__())
|
||||
else:
|
||||
if __debug__:
|
||||
result = await loop.spawn(super().__iter__(), confirm_signal)
|
||||
else:
|
||||
result = await super().__iter__()
|
||||
return result
|
||||
|
@ -75,6 +75,11 @@ class Scrollpage(ui.Widget):
|
||||
self.page = page
|
||||
self.page_count = page_count
|
||||
|
||||
if content.__class__.__iter__ is not ui.Widget.__iter__:
|
||||
raise TypeError(
|
||||
"Scrollpage does not support widgets with custom event loop"
|
||||
)
|
||||
|
||||
def taint(self):
|
||||
super().taint()
|
||||
self.content.taint()
|
||||
@ -83,5 +88,5 @@ class Scrollpage(ui.Widget):
|
||||
self.content.render()
|
||||
render_scrollbar(self.page, self.page_count)
|
||||
|
||||
async def __iter__(self):
|
||||
return await loop.spawn(super().__iter__(), self.content)
|
||||
def touch(self, event, pos):
|
||||
return self.content.touch(event, pos)
|
||||
|
Loading…
Reference in New Issue
Block a user