Skip to content

Commit

Permalink
Log if NatlinkConfig or NatlinkStatus fails to initialize in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
LexiconCode committed Mar 23, 2024
1 parent b931fe1 commit f8939c9
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/natlinkcore/configure/natlinkconfig_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
logfile_logger.addHandler(file_handler)
logfile_logger.setLevel(logging.DEBUG)



# https://www.pysimplegui.org/en/latest/
from natlinkcore.configure.natlinkconfigfunctions import NatlinkConfig
from natlinkcore import natlinkstatus

pyVersion = platform.python_version()
osVersion = sys.getwindowsversion()

# Inlize the NatlinkConfig
Config = NatlinkConfig()
Status = natlinkstatus.NatlinkStatus()


try:
# Initialize the NatlinkConfig, if this fails the gui will not start
Config = NatlinkConfig()
Status = natlinkstatus.NatlinkStatus()
except Exception as e:
logging.error(f"Failed to initialize NatlinkConfig or NatlinkStatus: {e}")
raise Exception(f"Failed to initialize NatlinkConfig or NatlinkStatus: {e}")

SYMBOL_UP = '▲'
SYMBOL_DOWN = '▼'
Expand Down Expand Up @@ -161,18 +162,13 @@ def OpenNatlinkConfig(values, event):

#### Event Loop ####
try:
#we want to set the logger up just before we call window.read()
#because if something is logged before the first window.read() there will be a failure.



#this would be a good spot to change the logging level, based on the natlink logging level
#note the natlink logging level doesn't correspond one to one with the logging module levels.
# we want to set the logger up just before we call window.read()
# because if something is logged before the first window.read() there will be a failure.
# note the natlink logging level doesn't correspond one to one with the logging module levels.
# do not change the logger level from debug
# change it in the handler. Because a file handler logs everything.
logfile_logger.addHandler(handler)

handler.setLevel(logging.DEBUG)
#do not change the logger level from debug
#change it in the handler. Because a file handler logs everything.
while True:
event, values = window.read()
if (event in ['-WINDOW CLOSE ATTEMPTED-', 'Exit']) and not Thread_Running:
Expand Down Expand Up @@ -218,6 +214,7 @@ def OpenNatlinkConfig(values, event):
func_to_call(values, event)

except Exception as e:
logging.error(f"Exception in GUI: {e}")
sg.Print('Exception in GUI event loop:', sg.__file__, e, keep_on_top=True, wait=True)
finally:
Config.status.refresh()
Expand Down

0 comments on commit f8939c9

Please sign in to comment.