Compare commits

...

3 Commits

Author SHA1 Message Date
BodgeMaster 060b8e81d8 basic window initialization 2022-02-14 14:36:03 +01:00
BodgeMaster a9a923fda9 configuration loading implemented 2022-02-14 14:35:04 +01:00
BodgeMaster 928fa91671 added a function for debug/info logging 2022-02-14 14:22:46 +01:00
1 changed files with 23 additions and 10 deletions

33
main.py
View File

@ -13,6 +13,14 @@ EXIT_ERROR=1
default_configuration = {
"window geometry": "640x480"
}
# 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 = {}
def info(message):
# print info to sys.stderr because it isnt really output, just debug information
print("INFO: "+str(message), file=sys.stderr)
traceback.print_stack()
def warn(message, is_exception=False):
print("WARNING: "+str(message), file=sys.stderr)
@ -32,6 +40,18 @@ def error(message, is_exception=True, handle_gracefully=True):
else:
sys.exit(EXIT_ERROR)
def get_configuration_value(key):
if key in configuration:
pass
else:
info("Requested configuration value for "+str(key)+" not in configuration. Loading from default configuration.")
try:
configuration[key] = default_configuration[key]
except KeyError:
error("Requested an invalid configuration key.")
return None
return configuration[key]
# easy way to get data out of window events
class Window_Interaction_Handler:
# constructor
@ -89,8 +109,6 @@ class Window_Interaction_Handler:
# read configuration
home_directory = os.path.expanduser("~")
config_file_path = os.path.join(home_directory, "some_ide_config.json")
# 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")
@ -130,11 +148,6 @@ else:
# 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)
#frame.grid()
#ttk.Label(frame, text="Hello, World!").grid(column=0, row=0)
#ttk.Button(frame, text="Quit", command=window.destroy).grid(column=0, row=1)
#window.mainloop()
main_window = tk.Tk()
main_window.geometry(get_configuration_value("window geometry"))
main_window.mainloop()