From 5e33c54ac07a06acdb1ba020a47bccfad47719cd Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Thu, 31 Jul 2025 00:01:28 -0700 Subject: [PATCH] formatting and catch --- contact/ui/control_ui.py | 22 +++++++++++----------- contact/ui/dialog.py | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/contact/ui/control_ui.py b/contact/ui/control_ui.py index 45cbaa1..528ed05 100644 --- a/contact/ui/control_ui.py +++ b/contact/ui/control_ui.py @@ -22,8 +22,6 @@ from contact.ui.nav_utils import move_highlight, draw_arrows, update_help_window from contact.ui.user_config import json_editor from contact.utilities.singleton import menu_state -# menu_state = MenuState() - # Constants width = 80 save_option = "Save Changes" @@ -171,26 +169,28 @@ def settings_menu(stdscr: object, interface: object) -> None: menu_state.show_save_option = False while True: - if menu_state.need_redraw == True: + if menu_state.need_redraw: + menu_state.need_redraw = False options = list(menu_state.current_menu.keys()) + # Determine if save option should be shown + path = menu_state.menu_path menu_state.show_save_option = ( - ( - len(menu_state.menu_path) > 2 - and ("Radio Settings" in menu_state.menu_path or "Module Settings" in menu_state.menu_path) - ) - or (len(menu_state.menu_path) == 2 and "User Settings" in menu_state.menu_path) - or (len(menu_state.menu_path) == 3 and "Channels" in menu_state.menu_path) + (len(path) > 2 and ("Radio Settings" in path or "Module Settings" in path)) + or (len(path) == 2 and "User Settings" in path) + or (len(path) == 3 and "Channels" in path) ) # Display the menu menu_win, menu_pad = display_menu() - menu_state.need_redraw = False + if menu_win is None: + continue # Skip if menu_win is not initialized menu_win.timeout(200) # wait up to 200 ms for a keypress (or less if key is pressed) - # Capture user input key = menu_win.getch() + if key == -1: + continue max_index = len(options) + (1 if menu_state.show_save_option else 0) - 1 # max_help_lines = 4 diff --git a/contact/ui/dialog.py b/contact/ui/dialog.py index 22bb772..7d5af3d 100644 --- a/contact/ui/dialog.py +++ b/contact/ui/dialog.py @@ -48,6 +48,8 @@ def dialog(title: str, message: str) -> None: while True: win.timeout(200) char = win.getch() + if char == -1: + continue if menu_state.need_redraw: menu_state.need_redraw = False