Compare commits
3 Commits
a3d6129bad
...
027a88342e
Author | SHA1 | Date |
---|---|---|
BodgeMaster | 027a88342e | |
BodgeMaster | 0fe719782c | |
BodgeMaster | 664c01c49b |
20
main.py
20
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,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()
|
||||
|
|
Reference in New Issue