forked from zietzm/Helmholtz_Test_Bench
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from os.path import exists
|
|
import traceback
|
|
from tkinter import messagebox
|
|
|
|
import cage_func as func
|
|
from User_Interface import HelmholtzGUI
|
|
from User_Interface import ui_print
|
|
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()
|
|
g.app.state('zoomed') # open maximized
|
|
g.app.StatusDisplay.continuous_label_update(g.app, 500) # initiate regular Status Display updates (ms)
|
|
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.")
|
|
# shop pup-up error message:
|
|
message = "%s.\nSee python console traceback for more details. " \
|
|
"\nShutting down devices, check equipment to confirm." % e
|
|
messagebox.showerror("Error!", message)
|
|
print(traceback.print_exc())
|
|
|
|
finally: # safely shut everything down at the end
|
|
func.shut_down_all()
|
|
|
|
# ToDo: logging
|