diff --git a/src/seedsigner/gui/toast.py b/src/seedsigner/gui/toast.py index d21ff02c..dbe3e19b 100644 --- a/src/seedsigner/gui/toast.py +++ b/src/seedsigner/gui/toast.py @@ -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") ) diff --git a/tests/screenshot_generator/generator.py b/tests/screenshot_generator/generator.py index 4c0c092a..ba3f073a 100644 --- a/tests/screenshot_generator/generator.py +++ b/tests/screenshot_generator/generator.py @@ -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, @@ -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