diff --git a/pyqtgraph/__init__.py b/pyqtgraph/__init__.py index 412c8627..520ea196 100644 --- a/pyqtgraph/__init__.py +++ b/pyqtgraph/__init__.py @@ -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__() `. + """ + 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(): diff --git a/pyqtgraph/console/Console.py b/pyqtgraph/console/Console.py index 72164f33..14890e0b 100644 --- a/pyqtgraph/console/Console.py +++ b/pyqtgraph/console/Console.py @@ -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)