Console: added ability to display exceptions before they are caught
Canvas: added clear() method
This commit is contained in:
parent
1b650083ef
commit
f208a9c824
|
@ -519,6 +519,10 @@ class Canvas(QtGui.QWidget):
|
||||||
|
|
||||||
## disconnect signals, remove from list, etc..
|
## disconnect signals, remove from list, etc..
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
while len(self.items) > 0:
|
||||||
|
self.removeItem(self.items[0])
|
||||||
|
|
||||||
|
|
||||||
def addToScene(self, item):
|
def addToScene(self, item):
|
||||||
self.view.addItem(item)
|
self.view.addItem(item)
|
||||||
|
|
|
@ -75,8 +75,8 @@ class ConsoleWidget(QtGui.QWidget):
|
||||||
self.ui.clearExceptionBtn.clicked.connect(self.clearExceptionClicked)
|
self.ui.clearExceptionBtn.clicked.connect(self.clearExceptionClicked)
|
||||||
self.ui.exceptionStackList.itemClicked.connect(self.stackItemClicked)
|
self.ui.exceptionStackList.itemClicked.connect(self.stackItemClicked)
|
||||||
self.ui.exceptionStackList.itemDoubleClicked.connect(self.stackItemDblClicked)
|
self.ui.exceptionStackList.itemDoubleClicked.connect(self.stackItemDblClicked)
|
||||||
|
self.ui.onlyUncaughtCheck.toggled.connect(self.updateSysTrace)
|
||||||
|
|
||||||
self.exceptionHandlerRunning = False
|
|
||||||
self.currentTraceback = None
|
self.currentTraceback = None
|
||||||
|
|
||||||
def loadHistory(self):
|
def loadHistory(self):
|
||||||
|
@ -235,10 +235,10 @@ class ConsoleWidget(QtGui.QWidget):
|
||||||
self.ui.catchAllExceptionsBtn.setChecked(catch)
|
self.ui.catchAllExceptionsBtn.setChecked(catch)
|
||||||
if catch:
|
if catch:
|
||||||
self.ui.catchNextExceptionBtn.setChecked(False)
|
self.ui.catchNextExceptionBtn.setChecked(False)
|
||||||
exceptionHandling.register(self.allExceptionsHandler)
|
self.enableExceptionHandling()
|
||||||
self.ui.exceptionBtn.setChecked(True)
|
self.ui.exceptionBtn.setChecked(True)
|
||||||
else:
|
else:
|
||||||
exceptionHandling.unregister(self.allExceptionsHandler)
|
self.disableExceptionHandling()
|
||||||
|
|
||||||
def catchNextException(self, catch=True):
|
def catchNextException(self, catch=True):
|
||||||
"""
|
"""
|
||||||
|
@ -248,11 +248,18 @@ class ConsoleWidget(QtGui.QWidget):
|
||||||
self.ui.catchNextExceptionBtn.setChecked(catch)
|
self.ui.catchNextExceptionBtn.setChecked(catch)
|
||||||
if catch:
|
if catch:
|
||||||
self.ui.catchAllExceptionsBtn.setChecked(False)
|
self.ui.catchAllExceptionsBtn.setChecked(False)
|
||||||
exceptionHandling.register(self.nextExceptionHandler)
|
self.enableExceptionHandling()
|
||||||
self.ui.exceptionBtn.setChecked(True)
|
self.ui.exceptionBtn.setChecked(True)
|
||||||
else:
|
else:
|
||||||
exceptionHandling.unregister(self.nextExceptionHandler)
|
self.disableExceptionHandling()
|
||||||
|
|
||||||
|
def enableExceptionHandling(self):
|
||||||
|
exceptionHandling.register(self.exceptionHandler)
|
||||||
|
self.updateSysTrace()
|
||||||
|
|
||||||
|
def disableExceptionHandling(self):
|
||||||
|
exceptionHandling.unregister(self.exceptionHandler)
|
||||||
|
self.updateSysTrace()
|
||||||
|
|
||||||
def clearExceptionClicked(self):
|
def clearExceptionClicked(self):
|
||||||
self.currentTraceback = None
|
self.currentTraceback = None
|
||||||
|
@ -275,14 +282,35 @@ class ConsoleWidget(QtGui.QWidget):
|
||||||
subprocess.Popen(self.editor.format(fileName=fileName, lineNum=lineNum), shell=True)
|
subprocess.Popen(self.editor.format(fileName=fileName, lineNum=lineNum), shell=True)
|
||||||
|
|
||||||
|
|
||||||
def allExceptionsHandler(self, *args):
|
#def allExceptionsHandler(self, *args):
|
||||||
self.exceptionHandler(*args)
|
#self.exceptionHandler(*args)
|
||||||
|
|
||||||
def nextExceptionHandler(self, *args):
|
#def nextExceptionHandler(self, *args):
|
||||||
self.ui.catchNextExceptionBtn.setChecked(False)
|
#self.ui.catchNextExceptionBtn.setChecked(False)
|
||||||
self.exceptionHandler(*args)
|
#self.exceptionHandler(*args)
|
||||||
|
|
||||||
|
def updateSysTrace(self):
|
||||||
|
## Install or uninstall sys.settrace handler
|
||||||
|
|
||||||
|
if not self.ui.catchNextExceptionBtn.isChecked() and not self.ui.catchAllExceptionsBtn.isChecked():
|
||||||
|
if sys.gettrace() == self.systrace:
|
||||||
|
sys.settrace(None)
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.ui.onlyUncaughtCheck.isChecked():
|
||||||
|
if sys.gettrace() == self.systrace:
|
||||||
|
sys.settrace(None)
|
||||||
|
else:
|
||||||
|
if sys.gettrace() is not None and sys.gettrace() != self.systrace:
|
||||||
|
self.ui.onlyUncaughtCheck.setChecked(False)
|
||||||
|
raise Exception("sys.settrace is in use; cannot monitor for caught exceptions.")
|
||||||
|
else:
|
||||||
|
sys.settrace(self.systrace)
|
||||||
|
|
||||||
def exceptionHandler(self, excType, exc, tb):
|
def exceptionHandler(self, excType, exc, tb):
|
||||||
|
if self.ui.catchNextExceptionBtn.isChecked():
|
||||||
|
self.ui.catchNextExceptionBtn.setChecked(False)
|
||||||
|
|
||||||
self.ui.clearExceptionBtn.setEnabled(True)
|
self.ui.clearExceptionBtn.setEnabled(True)
|
||||||
self.currentTraceback = tb
|
self.currentTraceback = tb
|
||||||
|
|
||||||
|
@ -292,13 +320,8 @@ class ConsoleWidget(QtGui.QWidget):
|
||||||
for index, line in enumerate(traceback.extract_tb(tb)):
|
for index, line in enumerate(traceback.extract_tb(tb)):
|
||||||
self.ui.exceptionStackList.addItem('File "%s", line %s, in %s()\n %s' % line)
|
self.ui.exceptionStackList.addItem('File "%s", line %s, in %s()\n %s' % line)
|
||||||
|
|
||||||
|
def systrace(self, frame, event, arg):
|
||||||
def quit(self):
|
if event == 'exception':
|
||||||
if self.exceptionHandlerRunning:
|
self.exceptionHandler(*arg)
|
||||||
self.exitHandler = True
|
return self.systrace
|
||||||
try:
|
|
||||||
exceptionHandling.unregister(self.exceptionHandler)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Form implementation generated from reading ui file './lib/modules/Console/template.ui'
|
# Form implementation generated from reading ui file 'template.ui'
|
||||||
#
|
#
|
||||||
# Created: Wed Jun 6 12:46:30 2012
|
# Created: Mon Aug 20 22:49:47 2012
|
||||||
# by: PyQt4 UI code generator 4.9.1
|
# by: PyQt4 UI code generator 4.9.1
|
||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
@ -62,43 +62,50 @@ class Ui_Form(object):
|
||||||
self.gridLayout_2.setSpacing(0)
|
self.gridLayout_2.setSpacing(0)
|
||||||
self.gridLayout_2.setContentsMargins(-1, 0, -1, 0)
|
self.gridLayout_2.setContentsMargins(-1, 0, -1, 0)
|
||||||
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
|
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
|
||||||
self.catchNextExceptionBtn = QtGui.QPushButton(self.exceptionGroup)
|
|
||||||
self.catchNextExceptionBtn.setCheckable(True)
|
|
||||||
self.catchNextExceptionBtn.setObjectName(_fromUtf8("catchNextExceptionBtn"))
|
|
||||||
self.gridLayout_2.addWidget(self.catchNextExceptionBtn, 0, 0, 1, 1)
|
|
||||||
self.exceptionStackList = QtGui.QListWidget(self.exceptionGroup)
|
|
||||||
self.exceptionStackList.setAlternatingRowColors(True)
|
|
||||||
self.exceptionStackList.setObjectName(_fromUtf8("exceptionStackList"))
|
|
||||||
self.gridLayout_2.addWidget(self.exceptionStackList, 2, 0, 1, 3)
|
|
||||||
self.catchAllExceptionsBtn = QtGui.QPushButton(self.exceptionGroup)
|
self.catchAllExceptionsBtn = QtGui.QPushButton(self.exceptionGroup)
|
||||||
self.catchAllExceptionsBtn.setCheckable(True)
|
self.catchAllExceptionsBtn.setCheckable(True)
|
||||||
self.catchAllExceptionsBtn.setObjectName(_fromUtf8("catchAllExceptionsBtn"))
|
self.catchAllExceptionsBtn.setObjectName(_fromUtf8("catchAllExceptionsBtn"))
|
||||||
self.gridLayout_2.addWidget(self.catchAllExceptionsBtn, 0, 1, 1, 1)
|
self.gridLayout_2.addWidget(self.catchAllExceptionsBtn, 0, 1, 1, 1)
|
||||||
self.clearExceptionBtn = QtGui.QPushButton(self.exceptionGroup)
|
self.catchNextExceptionBtn = QtGui.QPushButton(self.exceptionGroup)
|
||||||
self.clearExceptionBtn.setEnabled(False)
|
self.catchNextExceptionBtn.setCheckable(True)
|
||||||
self.clearExceptionBtn.setObjectName(_fromUtf8("clearExceptionBtn"))
|
self.catchNextExceptionBtn.setObjectName(_fromUtf8("catchNextExceptionBtn"))
|
||||||
self.gridLayout_2.addWidget(self.clearExceptionBtn, 0, 2, 1, 1)
|
self.gridLayout_2.addWidget(self.catchNextExceptionBtn, 0, 0, 1, 1)
|
||||||
|
self.onlyUncaughtCheck = QtGui.QCheckBox(self.exceptionGroup)
|
||||||
|
self.onlyUncaughtCheck.setChecked(True)
|
||||||
|
self.onlyUncaughtCheck.setObjectName(_fromUtf8("onlyUncaughtCheck"))
|
||||||
|
self.gridLayout_2.addWidget(self.onlyUncaughtCheck, 0, 2, 1, 1)
|
||||||
|
self.exceptionStackList = QtGui.QListWidget(self.exceptionGroup)
|
||||||
|
self.exceptionStackList.setAlternatingRowColors(True)
|
||||||
|
self.exceptionStackList.setObjectName(_fromUtf8("exceptionStackList"))
|
||||||
|
self.gridLayout_2.addWidget(self.exceptionStackList, 2, 0, 1, 5)
|
||||||
self.runSelectedFrameCheck = QtGui.QCheckBox(self.exceptionGroup)
|
self.runSelectedFrameCheck = QtGui.QCheckBox(self.exceptionGroup)
|
||||||
self.runSelectedFrameCheck.setChecked(True)
|
self.runSelectedFrameCheck.setChecked(True)
|
||||||
self.runSelectedFrameCheck.setObjectName(_fromUtf8("runSelectedFrameCheck"))
|
self.runSelectedFrameCheck.setObjectName(_fromUtf8("runSelectedFrameCheck"))
|
||||||
self.gridLayout_2.addWidget(self.runSelectedFrameCheck, 3, 0, 1, 3)
|
self.gridLayout_2.addWidget(self.runSelectedFrameCheck, 3, 0, 1, 5)
|
||||||
self.exceptionInfoLabel = QtGui.QLabel(self.exceptionGroup)
|
self.exceptionInfoLabel = QtGui.QLabel(self.exceptionGroup)
|
||||||
self.exceptionInfoLabel.setObjectName(_fromUtf8("exceptionInfoLabel"))
|
self.exceptionInfoLabel.setObjectName(_fromUtf8("exceptionInfoLabel"))
|
||||||
self.gridLayout_2.addWidget(self.exceptionInfoLabel, 1, 0, 1, 3)
|
self.gridLayout_2.addWidget(self.exceptionInfoLabel, 1, 0, 1, 5)
|
||||||
|
self.clearExceptionBtn = QtGui.QPushButton(self.exceptionGroup)
|
||||||
|
self.clearExceptionBtn.setEnabled(False)
|
||||||
|
self.clearExceptionBtn.setObjectName(_fromUtf8("clearExceptionBtn"))
|
||||||
|
self.gridLayout_2.addWidget(self.clearExceptionBtn, 0, 4, 1, 1)
|
||||||
|
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||||
|
self.gridLayout_2.addItem(spacerItem, 0, 3, 1, 1)
|
||||||
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1)
|
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1)
|
||||||
|
|
||||||
self.retranslateUi(Form)
|
self.retranslateUi(Form)
|
||||||
QtCore.QMetaObject.connectSlotsByName(Form)
|
QtCore.QMetaObject.connectSlotsByName(Form)
|
||||||
|
|
||||||
def retranslateUi(self, Form):
|
def retranslateUi(self, Form):
|
||||||
Form.setWindowTitle(QtGui.QApplication.translate("Console", "Console", None, QtGui.QApplication.UnicodeUTF8))
|
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Console", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.historyBtn.setText(QtGui.QApplication.translate("Form", "History..", None, QtGui.QApplication.UnicodeUTF8))
|
self.historyBtn.setText(QtGui.QApplication.translate("Form", "History..", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.exceptionBtn.setText(QtGui.QApplication.translate("Form", "Exceptions..", None, QtGui.QApplication.UnicodeUTF8))
|
self.exceptionBtn.setText(QtGui.QApplication.translate("Form", "Exceptions..", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.exceptionGroup.setTitle(QtGui.QApplication.translate("Form", "Exception Handling", None, QtGui.QApplication.UnicodeUTF8))
|
self.exceptionGroup.setTitle(QtGui.QApplication.translate("Form", "Exception Handling", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.catchNextExceptionBtn.setText(QtGui.QApplication.translate("Form", "Catch Next Exception", None, QtGui.QApplication.UnicodeUTF8))
|
self.catchAllExceptionsBtn.setText(QtGui.QApplication.translate("Form", "Show All Exceptions", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.catchAllExceptionsBtn.setText(QtGui.QApplication.translate("Form", "Catch All Exceptions", None, QtGui.QApplication.UnicodeUTF8))
|
self.catchNextExceptionBtn.setText(QtGui.QApplication.translate("Form", "Show Next Exception", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.clearExceptionBtn.setText(QtGui.QApplication.translate("Form", "Clear Exception", None, QtGui.QApplication.UnicodeUTF8))
|
self.onlyUncaughtCheck.setText(QtGui.QApplication.translate("Form", "Only Uncaught Exceptions", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.runSelectedFrameCheck.setText(QtGui.QApplication.translate("Form", "Run commands in selected stack frame", None, QtGui.QApplication.UnicodeUTF8))
|
self.runSelectedFrameCheck.setText(QtGui.QApplication.translate("Form", "Run commands in selected stack frame", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.exceptionInfoLabel.setText(QtGui.QApplication.translate("Form", "Exception Info", None, QtGui.QApplication.UnicodeUTF8))
|
self.exceptionInfoLabel.setText(QtGui.QApplication.translate("Form", "Exception Info", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.clearExceptionBtn.setText(QtGui.QApplication.translate("Form", "Clear Exception", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
from .CmdInput import CmdInput
|
from .CmdInput import CmdInput
|
||||||
|
|
|
@ -89,27 +89,20 @@
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="1">
|
||||||
<widget class="QPushButton" name="catchNextExceptionBtn">
|
<widget class="QPushButton" name="catchAllExceptionsBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Catch Next Exception</string>
|
<string>Show All Exceptions</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="3">
|
<item row="0" column="0">
|
||||||
<widget class="QListWidget" name="exceptionStackList">
|
<widget class="QPushButton" name="catchNextExceptionBtn">
|
||||||
<property name="alternatingRowColors">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QPushButton" name="catchAllExceptionsBtn">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Catch All Exceptions</string>
|
<string>Show Next Exception</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -117,16 +110,23 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<widget class="QPushButton" name="clearExceptionBtn">
|
<widget class="QCheckBox" name="onlyUncaughtCheck">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Clear Exception</string>
|
<string>Only Uncaught Exceptions</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="3">
|
<item row="2" column="0" colspan="5">
|
||||||
|
<widget class="QListWidget" name="exceptionStackList">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" colspan="5">
|
||||||
<widget class="QCheckBox" name="runSelectedFrameCheck">
|
<widget class="QCheckBox" name="runSelectedFrameCheck">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Run commands in selected stack frame</string>
|
<string>Run commands in selected stack frame</string>
|
||||||
|
@ -136,13 +136,36 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="3">
|
<item row="1" column="0" colspan="5">
|
||||||
<widget class="QLabel" name="exceptionInfoLabel">
|
<widget class="QLabel" name="exceptionInfoLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Exception Info</string>
|
<string>Exception Info</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="4">
|
||||||
|
<widget class="QPushButton" name="clearExceptionBtn">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear Exception</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="3">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user