From 664c01c49be1903f66606d9642828871f73d22ae Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Tue, 15 Feb 2022 01:26:28 +0100 Subject: [PATCH] addded a function to store the configuration to disk --- main.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a7aa76b..6724c28 100644 --- a/main.py +++ b/main.py @@ -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 isn’t 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")