addded a function to store the configuration to disk

master
BodgeMaster 2022-02-15 01:26:28 +01:00
parent a3d6129bad
commit 664c01c49b
1 changed files with 19 additions and 2 deletions

21
main.py
View File

@ -16,6 +16,8 @@ default_configuration = {
# empty configuration by default because new values will be added while trying to load them
# this allows the IDE to load old configuration files with missing keys
configuration = {}
home_directory = os.path.expanduser("~")
config_file_path = os.path.join(home_directory, "some_ide_config.json")
def info(message):
# print info to sys.stderr because it isnt really output, just debug information
@ -52,6 +54,23 @@ def get_configuration_value(key):
return None
return configuration[key]
def set_configuration_value(key, value, save_to_disk=True):
if not key in configuration:
info("Writing configuration for previously unknown key "+str(key)+".")
configuration[key]=value
try:
config_file = open(config_file_path, "w")
config_file.write(json.dumps(configuration))
config_file.close()
except:
warn("Failed to save config file.", is_exception=True)
dialog = tk.Tk()
dialog.title("Failed to save config file")
ttk.Label(dialog, text="Failed to save the configuration file.").pack()
ttk.Button(dialog, text="Continue", command=dialog.destroy).pack()
dialog.resizable(0,0)
dialog.mainloop()
# easy way to get data out of window events
class Window_Interaction_Handler:
# constructor
@ -107,8 +126,6 @@ class Window_Interaction_Handler:
################################################################################
# read configuration
home_directory = os.path.expanduser("~")
config_file_path = os.path.join(home_directory, "some_ide_config.json")
if os.path.isfile(config_file_path):
try:
config_file = open(config_file_path, "r")