configuration loading implemented
parent
928fa91671
commit
a9a923fda9
18
main.py
18
main.py
|
@ -13,6 +13,10 @@ EXIT_ERROR=1
|
||||||
default_configuration = {
|
default_configuration = {
|
||||||
"window geometry": "640x480"
|
"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):
|
def info(message):
|
||||||
# print info to sys.stderr because it isn’t really output, just debug information
|
# print info to sys.stderr because it isn’t really output, just debug information
|
||||||
print("INFO: "+str(message), file=sys.stderr)
|
print("INFO: "+str(message), file=sys.stderr)
|
||||||
|
@ -36,6 +40,18 @@ def error(message, is_exception=True, handle_gracefully=True):
|
||||||
else:
|
else:
|
||||||
sys.exit(EXIT_ERROR)
|
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
|
# easy way to get data out of window events
|
||||||
class Window_Interaction_Handler:
|
class Window_Interaction_Handler:
|
||||||
# constructor
|
# constructor
|
||||||
|
@ -93,8 +109,6 @@ class Window_Interaction_Handler:
|
||||||
# read configuration
|
# read configuration
|
||||||
home_directory = os.path.expanduser("~")
|
home_directory = os.path.expanduser("~")
|
||||||
config_file_path = os.path.join(home_directory, "some_ide_config.json")
|
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):
|
if os.path.isfile(config_file_path):
|
||||||
try:
|
try:
|
||||||
config_file = open(config_file_path, "r")
|
config_file = open(config_file_path, "r")
|
||||||
|
|
Reference in New Issue