diff --git a/main.py b/main.py index 2383510..b9117c4 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,10 @@ EXIT_ERROR=1 default_configuration = { "window geometry": "640x480" } +# 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 = {} + def info(message): # print info to sys.stderr because it isn’t really output, just debug information print("INFO: "+str(message), file=sys.stderr) @@ -36,6 +40,18 @@ def error(message, is_exception=True, handle_gracefully=True): else: sys.exit(EXIT_ERROR) +def get_configuration_value(key): + if key in configuration: + pass + else: + info("Requested configuration value for "+str(key)+" not in configuration. Loading from default configuration.") + try: + configuration[key] = default_configuration[key] + except KeyError: + error("Requested an invalid configuration key.") + return None + return configuration[key] + # easy way to get data out of window events class Window_Interaction_Handler: # constructor @@ -93,8 +109,6 @@ class Window_Interaction_Handler: # read configuration home_directory = os.path.expanduser("~") config_file_path = os.path.join(home_directory, "some_ide_config.json") -# load default configuration in case it is needed -configuration = default_configuration if os.path.isfile(config_file_path): try: config_file = open(config_file_path, "r")