Skip to content

Commit 26243db

Browse files
committed
qtvcp -improve closing clean up debug message - add the objects's Id name
If you have embedded panels they could have closing cleanup functions too. Now you can get some idea which is which
1 parent d0032b4 commit 26243db

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/python/qtvcp/qt_makegui.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(self, halcomp=None, path=None):
8686
return
8787
self.__class__._instanceNum += 1
8888

89+
self._idName = "TopObject" # initial name, will be replaced
8990
self.halcomp = halcomp
9091
self.has_closing_handler = False
9192
self.setFocus(True)
@@ -124,7 +125,7 @@ def keyReleaseTrap(self, e):
124125
def shutdown(self):
125126
for i in (self._VCPWindowList):
126127
if 'closing_cleanup__' in dir(i):
127-
log.debug('Calling handler file Closing_cleanup__ function of {}.'.format(i))
128+
log.debug('Calling handler file closing_cleanup__ function of {}.'.format(i._idName))
128129
i.closing_cleanup__()
129130

130131
def sync_qsettings(self):
@@ -380,19 +381,19 @@ def __init__(self, *args, **kwargs):
380381
self.PATHS = value.PATHS
381382
self.MAIN = value
382383
elif key == 'name':
383-
self._name = value
384+
self._idName = value
384385

385386
def instance(self, filename):
386387
try:
387388
instance = uic.loadUi(filename, self)
388389
except AttributeError as e:
389390
formatted_lines = traceback.format_exc().splitlines()
390391
if 'slotname' in formatted_lines[-2]:
391-
log.critical('{}: Missing slot name in handler file: {}'.format(self._name, e))
392+
log.critical('{}: Missing slot name in handler file: {}'.format(self._idName, e))
392393
message = '''A widget in the ui file, {} was assigned a signal \
393394
call to a missing function name in the handler file?\n
394395
There may be more. Some functions might not work.\n
395-
Python Error:\n {}'''.format(self._name, str(e))
396+
Python Error:\n {}'''.format(self._idName, str(e))
396397
rtn = QtWidgets.QMessageBox.critical(None, "QTVCP Error", message)
397398
else:
398399
log.critical(e)
@@ -424,33 +425,33 @@ def add_handler(method, f):
424425
directory = '.'
425426
if directory not in sys.path:
426427
sys.path.insert(0, directory)
427-
log.debug('{}: adding import dir: yellow<{}>'.format(self._name, directory))
428+
log.debug('{}: adding import dir: yellow<{}>'.format(self._idName, directory))
428429

429430
try:
430431
mod = __import__(basename)
431432
except ImportError as e:
432433
log.critical("{}: module '{}' skipped - import error: "
433-
.format(self._name, basename), exc_info=e)
434+
.format(self._idName, basename), exc_info=e)
434435
raise
435436
continue
436-
log.debug("{}: module '{}' imported green<OK>".format(self._name, mod.__name__))
437+
log.debug("{}: module '{}' imported green<OK>".format(self._idName, mod.__name__))
437438

438439
try:
439440
# look for 'get_handlers' function
440441
h = getattr(mod, hdl_func, None)
441442
if h and callable(h):
442-
log.debug("{}: module '{}' : '{}' function found".format(self._name, mod.__name__, hdl_func))
443+
log.debug("{}: module '{}' : '{}' function found".format(self._idName, mod.__name__, hdl_func))
443444
objlist = h(halcomp, widgets, self.PATHS) # this sets the handler class signature
444445
else:
445446
# the module has no get_handlers() callable.
446447
# in this case we permit any callable except class Objects in the module to register as handler
447448
log.debug("{}: module '{}': no '{}' function - registering only functions as callbacks"
448-
.format(self._name, mod.__name__, hdl_func))
449+
.format(self._idName, mod.__name__, hdl_func))
449450
objlist = [mod]
450451
# extract callback candidates
451452
for object in objlist:
452453
log.debug("{}: Registering handlers in module {} object {}"
453-
.format(self._name, mod.__name__, object))
454+
.format(self._idName, mod.__name__, object))
454455
if isinstance(object, dict):
455456
methods = list(dict.items())
456457
else:
@@ -459,12 +460,12 @@ def add_handler(method, f):
459460
if method.startswith('_'):
460461
continue
461462
if callable(f):
462-
log.debug("{}: Register callback '{}'".format(self._name, method))
463+
log.debug("{}: Register callback '{}'".format(self._idName, method))
463464
add_handler(method, f)
464465

465466
except Exception as e:
466467
log.exception("{}: Trouble looking for handlers in '{}':"
467-
.format(self._name, basename), exc_info=e)
468+
.format(self._idName, basename), exc_info=e)
468469
# we require a working handler file!
469470
raise
470471

src/emc/usr_intf/qtvcp/qtvcp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def __init__(self):
277277
# initialize the window
278278
self.w = window = qt_makegui.VCPWindow(self.hal, self.PATH)
279279

280+
# give the window an id name
281+
window._idName = basepath
282+
280283
# give reference to user command line options
281284
if opts.useropts:
282285
window.USEROPTIONS_ = opts.useropts
@@ -458,7 +461,6 @@ def __init__(self):
458461
# start loop
459462
global _app
460463
_app = APP.exec()
461-
462464
self.shutdown()
463465

464466
# finds the postgui file name and INI file path
@@ -506,7 +508,7 @@ def shutdown(self,signum=None,stack_frame=None):
506508

507509
# call HAL widget 'hal_cleanuo_' functions
508510
try:
509-
self.w.panel_.shutdown()
511+
self.panel.shutdown()
510512
except Exception as e:
511513
print(e)
512514
pass

0 commit comments

Comments
 (0)