handle default config
parent
4f844b6480
commit
77f0aa9d87
22
main.py
22
main.py
|
@ -10,6 +10,10 @@ import sys, os, json, traceback
|
||||||
EXIT_SUCCESS=0
|
EXIT_SUCCESS=0
|
||||||
EXIT_ERROR=1
|
EXIT_ERROR=1
|
||||||
|
|
||||||
|
default_configuration = {
|
||||||
|
"window geometry": "640x480"
|
||||||
|
}
|
||||||
|
|
||||||
def warn(message, is_exception=False):
|
def warn(message, is_exception=False):
|
||||||
print("WARNING: "+str(message), file=sys.stderr)
|
print("WARNING: "+str(message), file=sys.stderr)
|
||||||
if is_exception:
|
if is_exception:
|
||||||
|
@ -85,8 +89,8 @@ 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")
|
||||||
# default configuration
|
# load default configuration in case it is needed
|
||||||
configuration = {}
|
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")
|
||||||
|
@ -108,8 +112,18 @@ else:
|
||||||
dialog.mainloop()
|
dialog.mainloop()
|
||||||
|
|
||||||
if dialog_interaction_handler.get_result("create"):
|
if dialog_interaction_handler.get_result("create"):
|
||||||
#TODO: store default configuration
|
try:
|
||||||
warn("Not implemented!")
|
config_file = open(config_file_path, "w")
|
||||||
|
config_file.write(json.dumps(default_configuration))
|
||||||
|
config_file.close()
|
||||||
|
except:
|
||||||
|
warn("Failed to save initial config file.", is_exception=True)
|
||||||
|
dialog = tk.Tk()
|
||||||
|
dialog.title("Failed to save initial config file")
|
||||||
|
ttk.Label(dialog, text="Failed to save the initial config file. The IDE can still start up, but it is likely that all changes to the configuration will be lost where they would be saved otherwise.").pack()
|
||||||
|
ttk.Button(dialog, text="Continue", command=dialog.destroy).pack()
|
||||||
|
dialog.resizable(0,0)
|
||||||
|
dialog.mainloop()
|
||||||
else:
|
else:
|
||||||
error("No config present and user chose not to create one. Exiting.", is_exception=False, handle_gracefully=True)
|
error("No config present and user chose not to create one. Exiting.", is_exception=False, handle_gracefully=True)
|
||||||
# exit with success exit code anyway because this is not a program failure
|
# exit with success exit code anyway because this is not a program failure
|
||||||
|
|
Reference in New Issue