diff --git a/save_to_radio.py b/save_to_radio.py index a423a20..806711f 100644 --- a/save_to_radio.py +++ b/save_to_radio.py @@ -47,7 +47,6 @@ def save_changes(interface, menu_path, modified_settings): logging.info(f"Updated {config_category} with Long Name: {long_name} and Short Name {short_name} and Licensed Mode {is_licensed}") return - elif menu_path[1] == "Channels": # for channel configs config_category = "Channels" @@ -80,8 +79,6 @@ def save_changes(interface, menu_path, modified_settings): else: config_category = None - - for config_item, new_value in modified_settings.items(): # Check if the category exists in localConfig if hasattr(node.localConfig, config_category): diff --git a/settings.py b/settings.py index ef04508..e7ee805 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,6 @@ from ui.menus import generate_menu_from_protobuf from input_handlers import get_bool_selection, get_repeated_input, get_user_input, get_enum_input, get_fixed32_input from ui.colors import setup_colors - def display_menu(current_menu, menu_path, selected_index, show_save_option): global menu_win @@ -148,44 +147,15 @@ def settings_menu(stdscr, interface): elif selected_option == 'isLicensed': new_value = get_bool_selection(f"Current value for {selected_option}: {current_value}", str(current_value)) - try: - if isinstance(new_value, str): - new_value_lower = new_value.lower() - if new_value_lower in ("true", "yes", "1", "on"): - new_value = True - elif new_value_lower in ("false", "no", "0", "off"): - new_value = False - else: - raise ValueError("Invalid string for boolean") - else: - new_value = bool(new_value) - except ValueError as e: - logging.error(f"Invalid input for boolean: {e}") - new_value = current_value # Keep the current value if the input is invalid - + new_value = new_value == "True" current_menu[selected_option] = (field, new_value) for option, (field, value) in current_menu.items(): modified_settings[option] = value - elif field.type == 8: # Handle boolean type new_value = get_bool_selection(selected_option, str(current_value)) - try: - if isinstance(new_value, str): - new_value_lower = new_value.lower() - if new_value_lower in ("true", "yes", "1", "on"): - new_value = True - elif new_value_lower in ("false", "no", "0", "off"): - new_value = False - else: - raise ValueError("Invalid string for boolean") - else: - new_value = bool(new_value) - - except ValueError as e: - logging.info(f"Invalid input for boolean: {e}") - + new_value = new_value == "True" elif field.label == field.LABEL_REPEATED: # Handle repeated field new_value = get_repeated_input(current_value) @@ -209,7 +179,13 @@ def settings_menu(stdscr, interface): else: # Handle other field types new_value = get_user_input(f"Current value for {selected_option}: {current_value}") new_value = current_value if new_value is None else new_value - + + for key in menu_path[3:]: # Skip "Main Menu" + modified_settings = modified_settings.setdefault(key, {}) + + # Add the new value to the appropriate level + modified_settings[selected_option] = new_value + current_menu[selected_option] = (field, new_value) else: current_menu = current_menu[selected_option]