Compare commits
3 Commits
e39368bf41
...
060b8e81d8
Author | SHA1 | Date |
---|---|---|
![]() |
060b8e81d8 | |
![]() |
a9a923fda9 | |
![]() |
928fa91671 |
33
main.py
33
main.py
|
@ -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 isn’t 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()
|
||||
|
|
Reference in New Issue