|
|
|
@ -3,9 +3,34 @@ import tkinter as tk
|
|
|
|
|
from tkinter import ttk
|
|
|
|
|
import sys, os, json, traceback
|
|
|
|
|
|
|
|
|
|
def warn(text):
|
|
|
|
|
print("WARNING: "+str(text), file=sys.stderr)
|
|
|
|
|
traceback.print_stack()
|
|
|
|
|
################################################################################
|
|
|
|
|
# DEFINITIONS
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
EXIT_SUCCESS=0
|
|
|
|
|
EXIT_ERROR=1
|
|
|
|
|
|
|
|
|
|
default_configuration = {
|
|
|
|
|
"window geometry": "640x480"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def warn(message, is_exception=False):
|
|
|
|
|
print("WARNING: "+str(message), file=sys.stderr)
|
|
|
|
|
if is_exception:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
else:
|
|
|
|
|
traceback.print_stack()
|
|
|
|
|
|
|
|
|
|
def error(message, is_exception=True, handle_gracefully=True):
|
|
|
|
|
print("ERROR: "+str(message), file=sys.stderr)
|
|
|
|
|
if is_exception:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
else:
|
|
|
|
|
traceback.print_stack()
|
|
|
|
|
if handle_gracefully:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
sys.exit(EXIT_ERROR)
|
|
|
|
|
|
|
|
|
|
# easy way to get data out of window events
|
|
|
|
|
class Window_Interaction_Handler:
|
|
|
|
@ -57,38 +82,54 @@ class Window_Interaction_Handler:
|
|
|
|
|
if len(self.__window_interactions)>0:
|
|
|
|
|
warn("__window_interactions not empty upon destruction of Window_Interaction_Handler:\n"+str(self.__window_interactions))
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# PROGRAM START
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
# read configuration
|
|
|
|
|
home_directory = os.path.expanduser("~")
|
|
|
|
|
config_file_path = os.path.join(home_directory, "some_ide_config.json")
|
|
|
|
|
configuration = {}
|
|
|
|
|
# load default configuration in case it is needed
|
|
|
|
|
configuration = default_configuration
|
|
|
|
|
if os.path.isfile(config_file_path):
|
|
|
|
|
try:
|
|
|
|
|
config_file = open(config_file_path, "r")
|
|
|
|
|
configuration = json.loads(config_file.read())
|
|
|
|
|
config_file.close()
|
|
|
|
|
except:
|
|
|
|
|
#TODO: show an error message
|
|
|
|
|
warn("Not implemented!")
|
|
|
|
|
except Exception:
|
|
|
|
|
error("An exception occurred while trying to load the configuration.", handle_gracefully=False)
|
|
|
|
|
else:
|
|
|
|
|
# config not found
|
|
|
|
|
dialog_interaction_handler = Window_Interaction_Handler()
|
|
|
|
|
|
|
|
|
|
dialog = tk.Tk()
|
|
|
|
|
dialog.title("No configuration found")
|
|
|
|
|
ttk.Label(dialog, text="No configuration found!").pack()
|
|
|
|
|
buttons_frame = tk.Frame(dialog)
|
|
|
|
|
buttons_frame.pack()
|
|
|
|
|
ttk.Button(buttons_frame, text="Create", command=lambda: dialog_interaction_handler.interact("create", True, additional_action=dialog.destroy)).grid(column=0, row=0) #TODO: add functionality
|
|
|
|
|
ttk.Button(buttons_frame, text="Quit", command=lambda: dialog_interaction_handler.interact("create", False, additional_action=dialog.destroy)).grid(column=1, row=0) #TODO: add functionality
|
|
|
|
|
ttk.Button(buttons_frame, text="Create", command=lambda: dialog_interaction_handler.interact("create", True, additional_action=dialog.destroy)).grid(column=0, row=0)
|
|
|
|
|
ttk.Button(buttons_frame, text="Quit", command=lambda: dialog_interaction_handler.interact("create", False, additional_action=dialog.destroy)).grid(column=1, row=0)
|
|
|
|
|
dialog.resizable(0,0)
|
|
|
|
|
dialog.mainloop()
|
|
|
|
|
|
|
|
|
|
if dialog_interaction_handler.get_result("create"):
|
|
|
|
|
#TODO: store default configuration
|
|
|
|
|
warn("Not implemented!")
|
|
|
|
|
try:
|
|
|
|
|
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:
|
|
|
|
|
print("No config present and user chose not to create one. Exiting.")
|
|
|
|
|
sys.exit()
|
|
|
|
|
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
|
|
|
|
|
sys.exit(EXIT_SUCCESS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#window = tk.Tk()
|
|
|
|
|
#frame = ttk.Frame(window, padding=10)
|
|
|
|
|