From 09aa19873147d612388131fb15253f9c47bae16e Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 24 Jan 2018 09:06:37 -0800 Subject: [PATCH] Add top level stack() function for debugging --- pyqtgraph/__init__.py | 19 +++++++++++++++++++ pyqtgraph/console/Console.py | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) 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)