mirror of
https://github.com/pdxlocations/contact.git
synced 2026-03-28 17:12:35 +01:00
Merge pull request #49 from pdxlocations/settings-cleanup
Add is_licensed to user settings
This commit is contained in:
@@ -10,7 +10,6 @@ def get_user_input(prompt):
|
||||
|
||||
# Create a new window for user input
|
||||
input_win = curses.newwin(height, width, start_y, start_x)
|
||||
input_win.clear()
|
||||
input_win.border()
|
||||
|
||||
# Display the prompt
|
||||
@@ -18,15 +17,12 @@ def get_user_input(prompt):
|
||||
input_win.addstr(3, 2, "Enter value: ")
|
||||
input_win.refresh()
|
||||
|
||||
# Enable user input
|
||||
curses.echo()
|
||||
curses.curs_set(1)
|
||||
|
||||
user_input = ""
|
||||
while True:
|
||||
key = input_win.getch(3, 15 + len(user_input)) # Adjust cursor position dynamically
|
||||
if key == 27 or key == curses.KEY_LEFT: # ESC or Left Arrow
|
||||
curses.noecho()
|
||||
curses.curs_set(0)
|
||||
return None # Exit without returning a value
|
||||
elif key == ord('\n'): # Enter key
|
||||
@@ -40,7 +36,6 @@ def get_user_input(prompt):
|
||||
input_win.addstr(3, 15, user_input)
|
||||
|
||||
curses.curs_set(0)
|
||||
curses.noecho()
|
||||
|
||||
# Clear the input window
|
||||
input_win.clear()
|
||||
|
||||
@@ -40,11 +40,11 @@ def save_changes(interface, menu_path, modified_settings):
|
||||
|
||||
elif menu_path[1] == "User Settings": # for user configs
|
||||
config_category = "User Settings"
|
||||
long_name = modified_settings.get("longName", None)
|
||||
short_name = modified_settings.get("shortName", None)
|
||||
#TODO add is_licensed
|
||||
node.setOwner(long_name, short_name, is_licensed=False)
|
||||
logging.info(f"Updated {config_category} with Long Name: {long_name} and Short Name {short_name}")
|
||||
long_name = modified_settings.get("longName")
|
||||
short_name = modified_settings.get("shortName")
|
||||
is_licensed = modified_settings.get("isLicensed")
|
||||
node.setOwner(long_name, short_name, is_licensed)
|
||||
logging.info(f"Updated {config_category} with Long Name: {long_name} and Short Name {short_name} and Licensed Mode {is_licensed}")
|
||||
return
|
||||
|
||||
|
||||
|
||||
38
settings.py
38
settings.py
@@ -111,47 +111,63 @@ def settings_menu(stdscr, interface):
|
||||
selected_option = options[selected_index]
|
||||
|
||||
if selected_option == "Exit":
|
||||
stdscr.clear()
|
||||
break
|
||||
elif selected_option == "Reboot":
|
||||
confirmation = get_bool_selection("Are you sure you want to Reboot?", 0)
|
||||
if confirmation == "True":
|
||||
settings_reboot(interface)
|
||||
logging.info(f"Node Reboot Requested by menu")
|
||||
stdscr.clear()
|
||||
break
|
||||
elif selected_option == "Reset Node DB":
|
||||
confirmation = get_bool_selection("Are you sure you want to Reset Node DB?", 0)
|
||||
if confirmation == "True":
|
||||
settings_reset_nodedb(interface)
|
||||
logging.info(f"Node DB Reset Requested by menu")
|
||||
stdscr.clear()
|
||||
break
|
||||
elif selected_option == "Shutdown":
|
||||
confirmation = get_bool_selection("Are you sure you want to Shutdown?", 0)
|
||||
if confirmation == "True":
|
||||
settings_shutdown(interface)
|
||||
logging.info(f"Node Shutdown Requested by menu")
|
||||
stdscr.clear()
|
||||
break
|
||||
elif selected_option == "Factory Reset":
|
||||
confirmation = get_bool_selection("Are you sure you want to Factory Reset?", 0)
|
||||
if confirmation == "True":
|
||||
settings_factory_reset(interface)
|
||||
logging.info(f"Factory Reset Requested by menu")
|
||||
stdscr.clear()
|
||||
break
|
||||
|
||||
field_info = current_menu.get(selected_option)
|
||||
|
||||
if isinstance(field_info, tuple):
|
||||
field, current_value = field_info
|
||||
|
||||
if selected_option == 'longName' or selected_option == 'shortName':
|
||||
new_value = get_user_input(f"Current value for {selected_option}: {current_value}")
|
||||
|
||||
modified_settings[selected_option] = (new_value)
|
||||
current_menu[selected_option] = (field, new_value)
|
||||
if selected_option in ['longName', 'shortName', 'isLicensed']:
|
||||
if selected_option in ['longName', 'shortName']:
|
||||
new_value = get_user_input(f"Current value for {selected_option}: {current_value}")
|
||||
current_menu[selected_option] = (field, new_value)
|
||||
|
||||
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
|
||||
|
||||
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))
|
||||
|
||||
@@ -61,7 +61,8 @@ def generate_menu_from_protobuf(interface):
|
||||
|
||||
menu_structure["Main Menu"]["User Settings"] = {
|
||||
"longName": (None, current_user_config.get("longName", "Not Set")),
|
||||
"shortName": (None, current_user_config.get("shortName", "Not Set"))
|
||||
"shortName": (None, current_user_config.get("shortName", "Not Set")),
|
||||
"isLicensed": (None, current_user_config.get("isLicensed", "False"))
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user