Compare commits

...

3 Commits

1 changed files with 18 additions and 2 deletions

20
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,17 @@ 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:
error("Failed to save config file.")
# easy way to get data out of window events
class Window_Interaction_Handler:
# constructor
@ -107,8 +120,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")
@ -241,4 +252,9 @@ def rebuild_menu():
rebuild_menu()
def handle_exit():
set_configuration_value("window geometry", main_window.geometry())
main_window.destroy()
main_window.protocol("WM_DELETE_WINDOW", handle_exit)
main_window.mainloop()