Add top level stack() function for debugging

This commit is contained in:
Luke Campagnola 2018-01-24 09:06:37 -08:00
parent 52754d4859
commit 09aa198731
2 changed files with 24 additions and 3 deletions

View File

@ -447,6 +447,25 @@ def dbg(*args, **kwds):
except NameError:
consoles = [c]
return c
def stack(*args, **kwds):
"""
Create a console window and show the current stack trace.
All arguments are passed to :func:`ConsoleWidget.__init__() <pyqtgraph.console.ConsoleWidget.__init__>`.
"""
mkQApp()
from . import console
c = console.ConsoleWidget(*args, **kwds)
c.setStack()
c.show()
global consoles
try:
consoles.append(c)
except NameError:
consoles = [c]
return c
def mkQApp():

View File

@ -147,10 +147,11 @@ class ConsoleWidget(QtGui.QWidget):
def currentFrame(self):
## Return the currently selected exception stack frame (or None if there is no exception)
if self.currentTraceback is None:
return None
index = self.ui.exceptionStackList.currentRow()
return self.frames[index]
if index >= 0 and index < len(self.frames):
return self.frames[index]
else:
return None
def execSingle(self, cmd):
try:
@ -276,6 +277,7 @@ class ConsoleWidget(QtGui.QWidget):
def clearExceptionClicked(self):
self.currentTraceback = None
self.frames = []
self.ui.exceptionInfoLabel.setText("[No current exception]")
self.ui.exceptionStackList.clear()
self.ui.clearExceptionBtn.setEnabled(False)