Debugger/ExceptionLogger.py

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Exception Logger widget.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from E4Gui.E4Application import e4App
14
15
16 class ExceptionLogger(QTreeWidget):
17 """
18 Class implementing the Exception Logger widget.
19
20 This class displays a log of all exceptions having occured during
21 a debugging session.
22
23 @signal sourceFile(string, int) emitted to open a source file at a line
24 """
25 def __init__(self, parent=None):
26 """
27 Constructor
28
29 @param parent the parent widget of this widget
30 """
31 QTreeWidget.__init__(self, parent)
32 self.setObjectName("ExceptionLogger")
33
34 self.setWindowTitle(self.trUtf8("Exceptions"))
35
36 self.setWordWrap(True)
37 self.setRootIsDecorated(True)
38 self.setHeaderLabels([self.trUtf8("Exception")])
39 self.setSortingEnabled(False)
40
41 self.setContextMenuPolicy(Qt.CustomContextMenu)
42 self.connect(self,SIGNAL('customContextMenuRequested(const QPoint &)'),
43 self.__showContextMenu)
44 self.connect(self,SIGNAL('itemDoubleClicked(QTreeWidgetItem *, int)'),
45 self.__itemDoubleClicked)
46
47 self.setWhatsThis(self.trUtf8(
48 """<b>Exceptions Logger</b>"""
49 """<p>This windows shows a trace of all exceptions, that have"""
50 """ occured during the last debugging session. Initially only the"""
51 """ exception type and exception message are shown. After"""
52 """ the expansion of this entry, the complete call stack as reported"""
53 """ by the client is show with the most recent call first.</p>"""
54 ))
55
56 self.menu = QMenu(self)
57 self.menu.addAction(self.trUtf8("Show source"), self.__openSource)
58 self.menu.addAction(self.trUtf8("Clear"), self.clear)
59 self.menu.addSeparator()
60 self.menu.addAction(self.trUtf8("Configure..."), self.__configure)
61
62 self.backMenu = QMenu(self)
63 self.backMenu.addAction(self.trUtf8("Clear"), self.clear)
64 self.backMenu.addSeparator()
65 self.backMenu.addAction(self.trUtf8("Configure..."), self.__configure)
66
67 def __itemDoubleClicked(self, itm):
68 """
69 Private slot to handle the double click of an item.
70
71 @param itm the item that was double clicked(QTreeWidgetItem), ignored
72 """
73 self.__openSource()
74
75 def __showContextMenu(self, coord):
76 """
77 Private slot to show the context menu of the listview.
78
79 @param coord the global coordinates of the mouse pointer (QPoint)
80 """
81 itm = self.itemAt(coord)
82 coord = self.mapToGlobal(coord)
83 if itm is None:
84 self.backMenu.popup(coord)
85 else:
86 self.menu.popup(coord)
87
88 def addException(self, exceptionType, exceptionMessage, stackTrace):
89 """
90 Public slot to handle the arrival of a new exception.
91
92 @param exceptionType type of exception raised (string)
93 @param exceptionMessage message given by the exception (string)
94 @param stackTrace list of stack entries.
95 """
96 itm = QTreeWidgetItem(self)
97 if exceptionType is None:
98 itm.setText(0,
99 self.trUtf8('An unhandled exception occured.'
100 ' See the shell window for details.'))
101 return
102
103 if exceptionMessage == '':
104 itm.setText(0, "%s" % exceptionType)
105 else:
106 itm.setText(0, "%s, %s" % (exceptionType, exceptionMessage))
107
108 # now add the call stack, most recent call first
109 for fn, ln in stackTrace:
110 excitm = QTreeWidgetItem(itm)
111 excitm.setText(0, "%s, %d" % (fn, ln))
112
113 def debuggingStarted(self):
114 """
115 Public slot to clear the listview upon starting a new debugging session.
116 """
117 self.clear()
118
119 def __openSource(self):
120 """
121 Private slot to handle a double click on an entry.
122 """
123 itm = self.currentItem()
124
125 if itm.parent() is None:
126 return
127
128 entry = itm.text(0)
129 entryList = entry.split(",")
130 try:
131 self.emit(SIGNAL('sourceFile'), entryList[0], int(entryList[1]))
132 except (IndexError, ValueError):
133 pass
134
135 def __configure(self):
136 """
137 Private method to open the configuration dialog.
138 """
139 e4App().getObject("UserInterface").showPreferences("debuggerGeneralPage")

eric ide

mercurial