eric6/Debugger/ExceptionLogger.py

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

eric ide

mercurial