eric6/Debugger/CallStackViewer.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7377
cc920e534ac0
child 7780
41420f82c0ac
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2013 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the Call Stack viewer widget.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2677
3d4277929fb3 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2622
diff changeset
10
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
11 from PyQt5.QtCore import pyqtSignal, Qt, QFileInfo
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
12 from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QMenu
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from E5Gui.E5Application import e5App
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui import E5FileDialog, E5MessageBox
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Utilities
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class CallStackViewer(QTreeWidget):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the Call Stack viewer widget.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @signal sourceFile(str, int) emitted to show the source of a stack entry
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @signal frameSelected(int) emitted to signal the selection of a frame entry
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 sourceFile = pyqtSignal(str, int)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 frameSelected = pyqtSignal(int)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 FilenameRole = Qt.UserRole + 1
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 LinenoRole = Qt.UserRole + 2
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 def __init__(self, debugServer, parent=None):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 Constructor
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param debugServer reference to the debug server object (DebugServer)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param parent reference to the parent widget (QWidget)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
2677
3d4277929fb3 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2622
diff changeset
40 super(CallStackViewer, self).__init__(parent)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.setHeaderHidden(True)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.setAlternatingRowColors(True)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.setItemsExpandable(False)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setRootIsDecorated(False)
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
46 self.setWindowTitle(self.tr("Call Stack"))
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__menu = QMenu(self)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.__sourceAct = self.__menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
50 self.tr("Show source"), self.__openSource)
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
51 self.__menu.addAction(self.tr("Clear"), self.clear)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__menu.addSeparator()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
53 self.__menu.addAction(self.tr("Save"), self.__saveStackTrace)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.setContextMenuPolicy(Qt.CustomContextMenu)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.customContextMenuRequested.connect(self.__showContextMenu)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__dbs = debugServer
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 # file name, line number, function name, arguments
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
60 self.__entryFormat = self.tr("File: {0}\nLine: {1}\n{2}{3}")
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 # file name, line number
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
62 self.__entryFormatShort = self.tr("File: {0}\nLine: {1}")
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__projectMode = False
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__project = None
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__dbs.clientStack.connect(self.__showCallStack)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.itemDoubleClicked.connect(self.__itemDoubleClicked)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 def setDebugger(self, debugUI):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 Public method to set a reference to the Debug UI.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @param debugUI reference to the DebugUI object (DebugUI)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 debugUI.clientStack.connect(self.__showCallStack)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def setProjectMode(self, enabled):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Public slot to set the call trace viewer to project mode.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 In project mode the call trace info is shown with project relative
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 path names.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @param enabled flag indicating to enable the project mode (boolean)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__projectMode = enabled
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if enabled and self.__project is None:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__project = e5App().getObject("Project")
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 def __showContextMenu(self, coord):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Private slot to show the context menu.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 @param coord the position of the mouse pointer (QPoint)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if self.topLevelItemCount() > 0:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 itm = self.currentItem()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__sourceAct.setEnabled(itm is not None)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__menu.popup(self.mapToGlobal(coord))
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def __showCallStack(self, stack):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
104 Private slot to show the call stack of the program being debugged.
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
2988
f53c03574697 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2732
diff changeset
106 @param stack list of tuples with call stack data (file name,
f53c03574697 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2732
diff changeset
107 line number, function name, formatted argument/values list)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.clear()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 for fname, fline, ffunc, fargs in stack:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 if self.__projectMode:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 dfname = self.__project.getRelativePath(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 else:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 dfname = fname
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 if ffunc and not ffunc.startswith("<"):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 # use normal format
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
117 itm = QTreeWidgetItem(
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
118 self,
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 [self.__entryFormat.format(dfname, fline, ffunc, fargs)])
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 else:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 # use short format
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
122 itm = QTreeWidgetItem(
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
123 self, [self.__entryFormatShort.format(dfname, fline)])
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 itm.setData(0, self.FilenameRole, fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 itm.setData(0, self.LinenoRole, fline)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.resizeColumnToContents(0)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def __itemDoubleClicked(self, itm):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Private slot to handle a double click of a stack entry.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @param itm reference to the double clicked item (QTreeWidgetItem)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 fname = itm.data(0, self.FilenameRole)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 fline = itm.data(0, self.LinenoRole)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 if self.__projectMode:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 fname = self.__project.getAbsolutePath(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.sourceFile.emit(fname, fline)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 index = self.indexOfTopLevelItem(itm)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.frameSelected.emit(index)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def __openSource(self):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Private slot to show the source for the selected stack entry.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 itm = self.currentItem()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if itm:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.__itemDoubleClicked(itm)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 def __saveStackTrace(self):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 Private slot to save the stack trace info to a file.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 if self.topLevelItemCount() > 0:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
159 self.tr("Save Call Stack Info"),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
161 self.tr("Text Files (*.txt);;All Files (*)"),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 None,
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 if fname:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 ext = QFileInfo(fname).suffix()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 if not ext:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 ex = selectedFilter.split("(*")[1].split(")")[0]
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if ex:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 fname += ex
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
171 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
172 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
173 self.tr("Save Call Stack Info"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
174 self.tr("<p>The file <b>{0}</b> already exists."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
175 " Overwrite it?</p>").format(fname),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 icon=E5MessageBox.Warning)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 if not res:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 return
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 fname = Utilities.toNativeSeparators(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 try:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 f = open(fname, "w", encoding="utf-8")
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 itm = self.topLevelItem(0)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 while itm is not None:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 f.write("{0}\n".format(itm.text(0)))
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 f.write(78 * "=" + "\n")
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 itm = self.itemBelow(itm)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 f.close()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 except IOError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
190 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
191 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
192 self.tr("Error saving Call Stack Info"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
193 self.tr("""<p>The call stack info could not be"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
194 """ written to <b>{0}</b></p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
195 """<p>Reason: {1}</p>""")
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
196 .format(fname, str(err)))

eric ide

mercurial