From 37bd99928b8bce8e4ae608b68e5535a26e98fa69 Mon Sep 17 00:00:00 2001 From: kdmukai Date: Fri, 22 Sep 2023 20:07:51 -0500 Subject: [PATCH] hold and reset animated QRs on brightness tip --- src/seedsigner/gui/screens/screen.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/seedsigner/gui/screens/screen.py b/src/seedsigner/gui/screens/screen.py index 59fd24d9c..9c1e5800e 100644 --- a/src/seedsigner/gui/screens/screen.py +++ b/src/seedsigner/gui/screens/screen.py @@ -670,7 +670,7 @@ def __init__(self, qr_encoder: BaseQrEncoder, qr_brightness: ThreadsafeCounter, self.tips_start_time = tips_start_time - def add_brightness_tips(self, image: Image.Image) -> None: + def render_brightness_tip(self, image: Image.Image) -> None: # TODO: Refactor ToastOverlay to support two lines of icon + text and use # that instead of this more manual approach. @@ -745,19 +745,29 @@ def run(self): from seedsigner.models.settings import Settings settings = Settings.get_instance() cur_brightness_setting = settings.get_value(SettingsConstants.SETTING__QR_BRIGHTNESS_TIPS) - show_brightness_tips = cur_brightness_setting == SettingsConstants.OPTION__ENABLED + is_brightness_tip_enabled = cur_brightness_setting == SettingsConstants.OPTION__ENABLED + pending_encoder_restart = False # Loop whether the QR is a single frame or animated; each loop might adjust # brightness setting. while self.keep_running: # convert the self.qr_brightness integer (31-255) into hex triplets hex_color = (hex(self.qr_brightness.cur_count).split('x')[1]) * 3 - image = self.qr_encoder.next_part_image(240, 240, border=2, background_color=hex_color) # Display the brightness tips toast duration = 10 ** 9 * 1.2 # 1.2 seconds - if show_brightness_tips and time.time_ns() - self.tips_start_time.cur_count < duration: - self.add_brightness_tips(image) + if is_brightness_tip_enabled and time.time_ns() - self.tips_start_time.cur_count < duration: + image = self.qr_encoder.part_to_image(self.qr_encoder.cur_part(), 240, 240, border=2, background_color=hex_color) + self.render_brightness_tip(image) + pending_encoder_restart = True + else: + # Only advance the QR animation when the brightness tip is not displayed + if pending_encoder_restart: + # Animated QRs should restart their frame sequence after the + # brightness tip is stowed. + self.qr_encoder.restart() + pending_encoder_restart = False + image = self.qr_encoder.next_part_image(240, 240, border=2, background_color=hex_color) with self.renderer.lock: self.renderer.show_image(image)