addded a function to store the configuration to disk
parent
a3d6129bad
commit
664c01c49b
21
main.py
21
main.py
|
@ -16,6 +16,8 @@ default_configuration = {
|
||||||
# empty configuration by default because new values will be added while trying to load them
|
# 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
|
# this allows the IDE to load old configuration files with missing keys
|
||||||
configuration = {}
|
configuration = {}
|
||||||
|
home_directory = os.path.expanduser("~")
|
||||||
|
config_file_path = os.path.join(home_directory, "some_ide_config.json")
|
||||||
|
|
||||||
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
|
||||||
|
@ -52,6 +54,23 @@ def get_configuration_value(key):
|
||||||
return None
|
return None
|
||||||
return configuration[key]
|
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
|
# easy way to get data out of window events
|
||||||
class Window_Interaction_Handler:
|
class Window_Interaction_Handler:
|
||||||
# constructor
|
# constructor
|
||||||
|
@ -107,8 +126,6 @@ class Window_Interaction_Handler:
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# read configuration
|
# 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):
|
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