Fix parameters sending 'children' key to setOpts on restoreState (fixes error seen in relativity demo)
Add debug replacement for sys.excepthook that prints full stack trace
This commit is contained in:
parent
8a64c04f71
commit
c7923d3f95
@ -83,8 +83,9 @@ class Tracer(object):
|
||||
funcname = cls.__name__ + "." + funcname
|
||||
return "%s: %s %s: %s" % (callline, filename, lineno, funcname)
|
||||
|
||||
|
||||
def warnOnException(func):
|
||||
"""Decorator which catches/ignores exceptions and prints a stack trace."""
|
||||
"""Decorator that catches/ignores exceptions and prints a stack trace."""
|
||||
def w(*args, **kwds):
|
||||
try:
|
||||
func(*args, **kwds)
|
||||
@ -92,11 +93,9 @@ def warnOnException(func):
|
||||
printExc('Ignored exception:')
|
||||
return w
|
||||
|
||||
|
||||
def getExc(indent=4, prefix='| ', skip=1):
|
||||
lines = (traceback.format_stack()[:-skip]
|
||||
+ [" ---- exception caught ---->\n"]
|
||||
+ traceback.format_tb(sys.exc_info()[2])
|
||||
+ traceback.format_exception_only(*sys.exc_info()[:2]))
|
||||
lines = formatException(*sys.exc_info(), skip=skip)
|
||||
lines2 = []
|
||||
for l in lines:
|
||||
lines2.extend(l.strip('\n').split('\n'))
|
||||
@ -112,6 +111,7 @@ def printExc(msg='', indent=4, prefix='|'):
|
||||
print(" "*indent + prefix + '='*30 + '>>')
|
||||
print(exc)
|
||||
print(" "*indent + prefix + '='*30 + '<<')
|
||||
|
||||
|
||||
def printTrace(msg='', indent=4, prefix='|'):
|
||||
"""Print an error message followed by an indented stack trace"""
|
||||
@ -126,7 +126,30 @@ def printTrace(msg='', indent=4, prefix='|'):
|
||||
|
||||
def backtrace(skip=0):
|
||||
return ''.join(traceback.format_stack()[:-(skip+1)])
|
||||
|
||||
|
||||
def formatException(exctype, value, tb, skip=0):
|
||||
"""Return a list of formatted exception strings.
|
||||
|
||||
Similar to traceback.format_exception, but displays the entire stack trace
|
||||
rather than just the portion downstream of the point where the exception is
|
||||
caught. In particular, unhandled exceptions that occur during Qt signal
|
||||
handling do not usually show the portion of the stack that emitted the
|
||||
signal.
|
||||
"""
|
||||
lines = traceback.format_exception(exctype, value, tb)
|
||||
lines = [lines[0]] + traceback.format_stack()[:-(skip+1)] + [' --- exception caught here ---\n'] + lines[1:]
|
||||
return lines
|
||||
|
||||
|
||||
def printException(exctype, value, traceback):
|
||||
"""Print an exception with its full traceback.
|
||||
|
||||
Set `sys.excepthook = printException` to ensure that exceptions caught
|
||||
inside Qt signal handlers are printed with their full stack trace.
|
||||
"""
|
||||
print(''.join(formatException(exctype, value, traceback, skip=1)))
|
||||
|
||||
|
||||
def listObjs(regex='Q', typ=None):
|
||||
"""List all objects managed by python gc with class name matching regex.
|
||||
|
@ -312,7 +312,8 @@ class Parameter(QtCore.QObject):
|
||||
If blockSignals is True, no signals will be emitted until the tree has been completely restored.
|
||||
This prevents signal handlers from responding to a partially-rebuilt network.
|
||||
"""
|
||||
childState = state.get('children', [])
|
||||
state = state.copy()
|
||||
childState = state.pop('children', [])
|
||||
|
||||
## list of children may be stored either as list or dict.
|
||||
if isinstance(childState, dict):
|
||||
|
@ -284,8 +284,6 @@ class WidgetParameterItem(ParameterItem):
|
||||
self.widget.setOpts(**opts)
|
||||
self.updateDisplayLabel()
|
||||
|
||||
|
||||
|
||||
|
||||
class EventProxy(QtCore.QObject):
|
||||
def __init__(self, qobj, callback):
|
||||
@ -296,8 +294,6 @@ class EventProxy(QtCore.QObject):
|
||||
def eventFilter(self, obj, ev):
|
||||
return self.callback(obj, ev)
|
||||
|
||||
|
||||
|
||||
|
||||
class SimpleParameter(Parameter):
|
||||
itemClass = WidgetParameterItem
|
||||
|
Loading…
Reference in New Issue
Block a user