Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screenshot Generator] Add explicit Toast duration, additional code comments #613

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/seedsigner/gui/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ def run(self):


class RemoveSDCardToastManagerThread(BaseToastOverlayManagerThread):
def __init__(self, activation_delay=3):
def __init__(self, activation_delay: int = 3, duration: int = 1e6):
# Note: activation_delay is configurable so the screenshot generator can get the
# toast to immediately render.
# `duration` gives the screenshot generator explicit control over the Toast's
# lifespan.
super().__init__(
activation_delay=activation_delay, # seconds
duration=1e6, # seconds ("forever")
duration=duration, # seconds (1e6 default = "forever")
)


Expand Down
7 changes: 5 additions & 2 deletions tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def add_op_return_to_psbt(psbt: PSBT, raw_payload_data: bytes):
MainMenuView,
(MainMenuView, {}, 'MainMenuView_SDCardStateChangeToast_removed', SDCardStateChangeToastManagerThread(action=MicroSD.ACTION__REMOVED)),
(MainMenuView, {}, 'MainMenuView_SDCardStateChangeToast_inserted', SDCardStateChangeToastManagerThread(action=MicroSD.ACTION__INSERTED)),
(MainMenuView, {}, 'MainMenuView_RemoveSDCardToast', RemoveSDCardToastManagerThread(activation_delay=0)),
(MainMenuView, {}, 'MainMenuView_RemoveSDCardToast', RemoveSDCardToastManagerThread(activation_delay=0, duration=0)),
PowerOptionsView,
RestartView,
PowerOffView,
Expand Down Expand Up @@ -300,10 +300,13 @@ def screencap_view(view_cls: View, view_args: dict = {}, view_name: str = None,
try:
view_cls(**view_args).run()
except ScreenshotComplete:
# The target View has run and its Screen has rendered what it needs to
if toast_thread is not None:
# Now run the Toast so it can render on top of the current image buffer
controller.activate_toast(toast_thread)
while controller.toast_notification_thread.is_alive():
time.sleep(0.1)
# Give the Toast a moment to complete its work
time.sleep(0.01)
raise ScreenshotComplete()
except ScreenshotComplete:
# Slightly hacky way to exit ScreenshotRenderer as expected
Expand Down
Loading