Added the ability for the configuration selection to loop, so you can do multiple configurations in without having to rerun the script.

This commit is contained in:
stormdragon2976 2023-06-05 10:39:45 -04:00
parent bcf17ff021
commit f45a77c7e1

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
@ -13,7 +12,6 @@ os.environ['DIALOGOPTS'] = '--no-lines --visit-items'
# Initialize the dialog # Initialize the dialog
tui = dialog.Dialog(dialog="dialog") tui = dialog.Dialog(dialog="dialog")
# Define the path to the settings file # Define the path to the settings file
settings_file = '/etc/fenrirscreenreader/settings/settings.conf' settings_file = '/etc/fenrirscreenreader/settings/settings.conf'
@ -22,41 +20,47 @@ if not os.access(settings_file, os.W_OK):
tui.msgbox("Error: Insufficient permissions to modify the settings file. Please run as root or with sudo.") tui.msgbox("Error: Insufficient permissions to modify the settings file. Please run as root or with sudo.")
exit() exit()
# Load the settings file while True:
config = configparser.ConfigParser() # Load the settings file
config.read(settings_file) config = configparser.ConfigParser()
config.read(settings_file)
# Get a list of sections in the settings file # Get a list of sections in the settings file
sections = config.sections() sections = config.sections()
# Select a section. # Select a section.
code, section = tui.menu("Select a section:", choices=[(s, "") for s in sections]) code, section = tui.menu("Select a section:", choices=[(s, "") for s in sections] + [("Exit", " ")])
# If a section is selected, modify its values # Exit if the "Exit" option is chosen
if code == tui.OK: if section == "Exit":
# Get the options in the selected section break
options = config.options(section)
# Select a value to edit using dialog while True:
code, option = tui.menu(f"Select a value to edit in '{section}':", choices=[(o, "") for o in options]) # Get the options in the selected section
options = config.options(section)
# If something is selected, prompt for a new value. # Select a value to edit using dialog
if code == tui.OK: code, option = tui.menu(f"Select a value to edit in '{section}':", choices=[(o, "") for o in options] + [("Go Back", " ")])
value = config.get(section, option)
code, new_value = tui.inputbox(f"Enter a new value for '{option}':", init=value)
# If a new setting is provided, update the configuration # Go back to the section menu if the "Go Back" option is chosen
if option == "Go Back":
break
# If something is selected, prompt for a new value.
if code == tui.OK: if code == tui.OK:
config.set(section, option, new_value) value = config.get(section, option)
code, new_value = tui.inputbox(f"Enter a new value for '{option}':", init=value)
# Save changes. # If a new setting is provided, update the configuration
with open(settings_file, 'w') as configfile: if code == tui.OK:
config.write(configfile) config.set(section, option, new_value)
tui.msgbox("Fenrir settings saved.") # Save changes.
with open(settings_file, 'w') as configfile:
config.write(configfile)
tui.msgbox("Fenrir settings saved.")
else:
tui.msgbox("Changes discarded. Your Fenrir configuration has not been modified.")
else: else:
tui.msgbox("Changes discarded. Your Fenrir configuration has not been modified.") tui.msgbox("Canceled.")
else:
tui.msgbox("Canceled.")
else:
tui.msgbox("Canceled.")