From 0b82f43383a85ef6f485df861a828fdebcd42db9 Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 23 May 2026 18:31:56 -0700 Subject: [PATCH 1/2] fix: apply keypad brightness ratio immediately on menu select The Settings > User Pref > "Key Bright" menu wrote keypad_brightness to config but never asked main to re-apply it, so the new ratio only took effect on the next display-brightness adjustment. Add an apply_brightness post_callback that signals the existing "set_brightness" handler in main, which re-reads keypad_brightness from config and updates the keypad PWM. Co-Authored-By: Claude Opus 4.7 (1M context) --- python/PiFinder/ui/callbacks.py | 5 +++++ python/PiFinder/ui/menu_structure.py | 1 + 2 files changed, 6 insertions(+) diff --git a/python/PiFinder/ui/callbacks.py b/python/PiFinder/ui/callbacks.py index f5e6fc91..71c5190b 100644 --- a/python/PiFinder/ui/callbacks.py +++ b/python/PiFinder/ui/callbacks.py @@ -92,6 +92,11 @@ def set_exposure(ui_module: UIModule) -> None: ui_module.command_queues["camera"].put(f"set_exp:{new_exposure}") +def apply_brightness(ui_module: UIModule) -> None: + """Re-apply display + keypad brightness from current config.""" + ui_module.command_queues["ui_queue"].put("set_brightness") + + def set_auto_exposure_zero_star_handler(ui_module: UIModule) -> None: """ Sets the zero-star handler plugin for auto-exposure. diff --git a/python/PiFinder/ui/menu_structure.py b/python/PiFinder/ui/menu_structure.py index 9a0cabc0..4412aef8 100644 --- a/python/PiFinder/ui/menu_structure.py +++ b/python/PiFinder/ui/menu_structure.py @@ -586,6 +586,7 @@ def _(key: str) -> Any: "class": UITextMenu, "select": "single", "config_option": "keypad_brightness", + "post_callback": callbacks.apply_brightness, "items": [ { "name": "-4", From cea8c22a15c1702830bbd6514e0db179d3cfc5d9 Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 23 May 2026 18:32:08 -0700 Subject: [PATCH 2/2] refactor: drop dead hint-menu code from UIStatus Remove the _config_options dict and all of its associated callbacks (set_key_brightness, set_sleep_timeout, set_hint_timeout, set_screen_off_timeout, mount_switch, side_switch, wifi_switch, shutdown, restart, update_software) along with the now-unused active() method and version_txt attribute. The hint-menu system that consumed _config_options no longer exists; nothing iterates the dict and the duplicate update_software shadowed the live implementation in ui/software.py. Keep the wifi_status.txt read that seeds status_dict["WIFI"], inlined as a local. Co-Authored-By: Claude Opus 4.7 (1M context) --- python/PiFinder/ui/status.py | 182 +---------------------------------- 1 file changed, 3 insertions(+), 179 deletions(-) diff --git a/python/PiFinder/ui/status.py b/python/PiFinder/ui/status.py index 984642cc..d93403f8 100644 --- a/python/PiFinder/ui/status.py +++ b/python/PiFinder/ui/status.py @@ -22,72 +22,9 @@ class UIStatus(UIModule): __title__ = "STATUS" - _config_options = { - "Key Brit": { - "type": "enum", - "value": "", - "options": ["+3", "+2", "+1", "0", "-1", "-2", "-3", "Off"], - "callback": "set_key_brightness", - }, - "Sleep Tim": { - "type": "enum", - "value": "", - "options": ["Off", "10s", "30s", "1m"], - "callback": "set_sleep_timeout", - }, - "Screen Off": { - "type": "enum", - "value": "", - "options": ["Off", "30s", "1m", "10m", "30m"], - "callback": "set_screen_off_timeout", - }, - "Hint Time": { - "type": "enum", - "value": "2s", - "options": ["Off", "2s", "4s", "On"], - "callback": "set_hint_timeout", - }, - "WiFi Mode": { - "type": "enum", - "value": "UNK", - "options": ["AP", "Client", "CANCEL"], - "callback": "wifi_switch", - }, - "Mnt Side": { - "type": "enum", - "value": "", - "options": ["right", "left", "flat", "CANCEL"], - "callback": "side_switch", - }, - "Mnt Type": { - "type": "enum", - "value": "", - "options": ["Alt/Az", "EQ", "CANCEL"], - "callback": "mount_switch", - }, - "Shutdown": { - "type": "enum", - "value": "", - "options": ["System", "CANCEL"], - "callback": "shutdown", - }, - "Software": { - "type": "enum", - "value": "", - "options": ["Update", "CANCEL"], - "callback": "update_software", - }, - } - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.version_txt = f"{utils.pifinder_dir}/version.txt" - self.wifi_txt = f"{utils.pifinder_dir}/wifi_status.txt" self._draw_pos = (0, self.display_class.titlebar_height) - with open(self.wifi_txt, "r") as wfs: - self._config_options["WiFi Mode"]["value"] = wfs.read() - with open(self.version_txt, "r") as ver: - self._config_options["Software"]["value"] = ver.read() self.spacecalc = SpaceCalculatorFixed(self.fonts.base.line_length) self.status_dict = { "LAST SLV": "--", @@ -107,29 +44,9 @@ def __init__(self, *args, **kwargs): "CPU TMP": "--", } - if self._config_options["WiFi Mode"]["value"] == "Client": - self.status_dict["WIFI"] = "Client" - else: - self.status_dict["WIFI"] = "AP" - - self._config_options["Mnt Type"]["value"] = self.config_object.get_option( - "mount_type" - ) - self._config_options["Mnt Side"]["value"] = self.config_object.get_option( - "screen_direction" - ) - self._config_options["Sleep Tim"]["value"] = self.config_object.get_option( - "sleep_timeout" - ) - self._config_options["Screen Off"]["value"] = self.config_object.get_option( - "screen_off_timeout" - ) - self._config_options["Hint Time"]["value"] = self.config_object.get_option( - "hint_timeout" - ) - self._config_options["Key Brit"]["value"] = self.config_object.get_option( - "keypad_brightness" - ) + with open(f"{utils.pifinder_dir}/wifi_status.txt", "r") as wfs: + wifi_mode = wfs.read() + self.status_dict["WIFI"] = "Client" if wifi_mode == "Client" else "AP" self.last_temp_time = 0 self.last_IP_time = 0 @@ -143,91 +60,6 @@ def __init__(self, *args, **kwargs): available_lines=9, ) - def update_software(self, option): - if option == "CANCEL": - with open(self.version_txt, "r") as ver: - self._config_options["Software"]["value"] = ver.read() - return False - - self.message("Updating...", 10) - if sys_utils.update_software(): - self.message("Ok! Restarting", 10) - sys_utils.restart_pifinder() - else: - self.message("Error on Upd", 3) - - def set_key_brightness(self, option): - self.command_queues["ui_queue"].put("set_brightness") - self.config_object.set_option("keypad_brightness", option) - return False - - def set_sleep_timeout(self, option): - self.config_object.set_option("sleep_timeout", option) - return False - - def set_hint_timeout(self, option): - self.config_object.set_option("hint_timeout", option) - self.ui_state.set_hint_timeout(option) - return False - - def set_screen_off_timeout(self, option): - self.config_object.set_option("screen_off_timeout", option) - return False - - def mount_switch(self, option): - if option == "CANCEL": - self._config_options["Mnt Type"]["value"] = self.config_object.get_option( - "mount_type" - ) - return False - - self.message("Ok! Restarting", 10) - self.config_object.set_option("mount_type", option) - sys_utils.restart_pifinder() - - def side_switch(self, option): - if option == "CANCEL": - self._config_options["Mnt Side"]["value"] = self.config_object.get_option( - "screen_direction" - ) - return False - - self.message("Ok! Restarting", 10) - self.config_object.set_option("screen_direction", option) - sys_utils.restart_pifinder() - - def wifi_switch(self, option): - with open(self.wifi_txt, "r") as wfs: - current_state = wfs.read() - if option == current_state or option == "CANCEL": - self._config_options["WiFi Mode"]["value"] = current_state - return False - - if option == "AP": - self.message("Switch to AP", 10) - sys_utils.go_wifi_ap() - else: - self.message("Switch to Client", 10) - sys_utils.go_wifi_cli() - - sys_utils.restart_system() - - def shutdown(self, option): - if option == "System": - self.message("Shutting down", 10) - sys_utils.shutdown() - else: - self._config_options["Shutdown"]["value"] = "" - return False - - def restart(self, option): - if option == "PiFi": - self.message("Restarting", 10) - sys_utils.restart_pifinder() - else: - self._config_options["Restart"]["value"] = "" - return False - def update_status_dict(self): """ Updates all the status dict values @@ -354,11 +186,3 @@ def key_up(self): def key_down(self): self.text_layout.next() - - def active(self): - """ - Called when a module becomes active - i.e. foreground controlling display - """ - with open(self.wifi_txt, "r") as wfs: - self._config_options["WiFi Mode"]["value"] = wfs.read()