Files
Helmholtz_Test_Bench/main.py
T
2021-02-07 15:15:05 +01:00

46 lines
1.4 KiB
Python

from os.path import exists
import cage_func as func
from User_Interface import HelmholtzGUI
from User_Interface import ui_print
import traceback
import globals as g
import config_handling as config
try: # start normal operations
config.CONFIG_FILE = 'config.ini'
# ToDo: remember what the last config file was
if not exists(config.CONFIG_FILE):
print("Config file not found, creating new from defaults.")
config.reset_config_to_default(config.CONFIG_FILE)
config.write_config_to_file(config.CONFIG_OBJECT)
config.CONFIG_OBJECT = config.get_config_from_file(config.CONFIG_FILE)
print("Starting setup...")
func.setup_all() # initiate communication, set handles
print("\nOpening User Interface...")
g.app = HelmholtzGUI()
ui_print("Program Initialized")
config.check_config(config.CONFIG_OBJECT) # check config for values exceeding limits
ui_print("\nStarting setup...") # do it again, so it is printed in the UI console ToDo: do it only once
func.setup_all() # initiate communication, set handles
g.app.mainloop()
g.app = None # reset to None so nothing tries to print in the UI output
except BaseException as e: # if there is an error, print what happened
print("\nAn error occurred, Shutting down.")
print(e)
print(traceback.print_exc())
finally: # safely shut everything down at the end
func.shut_down_all()
# ToDo: logging