Skip to content

Commit

Permalink
fixup! fixup! docs(core): Layout lifecycle documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
obrusvit committed Oct 17, 2024
1 parent dfd23b0 commit 8157645
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/src/trezor/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def is_running(self) -> bool:
"""True if the layout is in RUNNING state."""
return CURRENT_LAYOUT is self

def is_stopped(self) -> bool:
"""True if the layout is in STOPPED state."""
def is_finished(self) -> bool:
"""True if the layout is in FINISHED state."""
return CURRENT_LAYOUT is not self and not self.result_box.is_empty()

def is_layout_attached(self) -> bool:
Expand All @@ -187,7 +187,7 @@ def is_layout_attached(self) -> bool:
def start(self) -> None:
"""Start the layout, stopping any other RUNNING layout.
If the layout is already RUNNING, do nothing. If the layout is STOPPED, fail.
If the layout is already RUNNING, do nothing. If the layout is FINISHED, fail.
"""
global CURRENT_LAYOUT

Expand Down Expand Up @@ -227,7 +227,7 @@ def stop(self, _kill_taker: bool = True) -> None:
current layout.
The resulting state is either READY (if there is no result to be picked up) or
STOPPED.
FINISHED.
When called externally, this kills any tasks that wait for the result, assuming
that the external `stop()` is a kill. When called internally, `_kill_taker` is
Expand Down Expand Up @@ -263,7 +263,7 @@ async def get_result(self) -> T:
"""Wait for, and return, the result of this UI layout."""
if self.is_ready():
self.start()
# else we are (a) still running or (b) already stopped
# else we are (a) still running or (b) already finished
try:
if self.context is not None and self.result_box.is_empty():
self._start_task(self._handle_usb_iface())
Expand Down Expand Up @@ -297,7 +297,6 @@ def _event(self, event_call: Callable[..., LayoutState | None], *args: Any) -> N
elif __debug__:
self.notify_debuglink(self)


if state is not None:
self.state = state

Expand Down Expand Up @@ -424,7 +423,10 @@ async def _handle_usb_iface(self) -> None:
ButtonAck,
)

if self. button_request_ack_pending and self.state is LayoutState.TRANSITIONING:
if (
self.button_request_ack_pending
and self.state is LayoutState.TRANSITIONING
):
self.button_request_ack_pending = False
self.state = LayoutState.ATTACHED
if __debug__:
Expand Down

0 comments on commit 8157645

Please sign in to comment.