Thu, 01 Nov 2012 18:29:58 +0100
Finished the coding part of the call trace functionality.
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the Call Trace viewer widget. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
10 | from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QRegExp, QFileInfo |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | from PyQt4.QtGui import QWidget, QTreeWidgetItem |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
13 | from E5Gui.E5Application import e5App |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
14 | from E5Gui import E5FileDialog, E5MessageBox |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
15 | |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | from .Ui_CallTraceViewer import Ui_CallTraceViewer |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | import UI.PixmapCache |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | import Preferences |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
20 | import Utilities |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | class CallTraceViewer(QWidget, Ui_CallTraceViewer): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Class implementing the Call Trace viewer widget. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | @signal sourceFile(str, int) emitted to show the source of a call/return point |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | sourceFile = pyqtSignal(str, int) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | def __init__(self, debugServer, parent=None): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | Constructor |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @param parent reference to the parent widget (QWidget) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | super().__init__(parent) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | self.setupUi(self) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | self.__dbs = debugServer |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.startTraceButton.setIcon(UI.PixmapCache.getIcon("callTraceStart.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.stopTraceButton.setIcon(UI.PixmapCache.getIcon("callTraceStop.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.resizeButton.setIcon(UI.PixmapCache.getIcon("resizeColumns.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | self.clearButton.setIcon(UI.PixmapCache.getIcon("editDelete.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | self.__headerItem = QTreeWidgetItem(["", self.trUtf8("From"), self.trUtf8("To")]) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.__headerItem.setIcon(0, UI.PixmapCache.getIcon("callReturn.png")) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | self.callTrace.setHeaderItem(self.__headerItem) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | self.__callStack = [] |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | self.__entryFormat = "{0}:{1} ({2})" |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
55 | self.__entryRe = QRegExp(r"""(.+):(\d+)\s\((.*)\)""") |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
56 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
57 | self.__projectMode = False |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
58 | self.__project = None |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | self.__callTraceEnabled = Preferences.toBool( |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | Preferences.Prefs.settings.value("CallTrace/Enabled", False)) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | if self.__callTraceEnabled: |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
63 | self.startTraceButton.setEnabled(False) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
64 | else: |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | self.stopTraceButton.setEnabled(False) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | self.__dbs.callTraceInfo.connect(self.__addCallTraceInfo) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
69 | def __setCallTraceEnabled(self, enabled): |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
70 | """ |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
71 | Private slot to set the call trace enabled status. |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
72 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
73 | @param enabled flag indicating the new state (boolean) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
74 | """ |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
75 | self.__dbs.setCallTraceEnabled(enabled) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
76 | self.stopTraceButton.setEnabled(enabled) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
77 | self.startTraceButton.setEnabled(not enabled) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
78 | self.__callTraceEnabled = enabled |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
79 | Preferences.Prefs.settings.setValue("CallTrace/Enabled", enabled) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
80 | |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | @pyqtSlot() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | def on_startTraceButton_clicked(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | Private slot to start call tracing. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
86 | self.__setCallTraceEnabled(True) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @pyqtSlot() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | def on_stopTraceButton_clicked(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | Private slot to start call tracing. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
93 | self.__setCallTraceEnabled(False) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | @pyqtSlot() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | def on_resizeButton_clicked(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | Private slot to resize the columns of the call trace to their contents. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | for column in range(self.callTrace.columnCount()): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | self.callTrace.resizeColumnToContents(column) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | @pyqtSlot() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | def on_clearButton_clicked(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | Private slot to clear the call trace. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | self.clear() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | @pyqtSlot() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | def on_saveButton_clicked(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
113 | Private slot to save the call trace info to a file. |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
115 | if self.callTrace.topLevelItemCount() > 0: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
116 | fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
117 | self, |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
118 | self.trUtf8("Save Call Trace Info"), |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
119 | "", |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
120 | self.trUtf8("Text Files (*.txt);;All Files (*)"), |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
121 | None, |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
122 | E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
123 | if fname: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
124 | ext = QFileInfo(fname).suffix() |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
125 | if not ext: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
126 | ex = selectedFilter.split("(*")[1].split(")")[0] |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
127 | if ex: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
128 | fname += ex |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
129 | if QFileInfo(fname).exists(): |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
130 | res = E5MessageBox.yesNo(self, |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
131 | self.trUtf8("Save Call Trace Info"), |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
132 | self.trUtf8("<p>The file <b>{0}</b> already exists." |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
133 | " Overwrite it?</p>").format(fname), |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
134 | icon=E5MessageBox.Warning) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
135 | if not res: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
136 | return |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
137 | fname = Utilities.toNativeSeparators(fname) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
138 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
139 | try: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
140 | f = open(fname, "w", encoding="utf-8") |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
141 | itm = self.callTrace.topLevelItem(0) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
142 | while itm is not None: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
143 | isCall = itm.data(0, Qt.UserRole) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
144 | if isCall: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
145 | call = "->" |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
146 | else: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
147 | call = "<-" |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
148 | f.write("{0} {1} || {2}\n".format(call, |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
149 | itm.text(1), itm.text(2))) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
150 | itm = self.callTrace.itemBelow(itm) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
151 | f.close() |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
152 | except IOError as err: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
153 | E5MessageBox.critical(self, |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
154 | self.trUtf8("Error saving Call Trace Info"), |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
155 | self.trUtf8("""<p>The call trace info could not be written""" |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
156 | """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
157 | .format(fname, str(err))) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | @pyqtSlot(QTreeWidgetItem, int) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | def on_callTrace_itemDoubleClicked(self, item, column): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
162 | Private slot to open the double clicked file in an editor. |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
163 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
164 | @param item reference to the double clicked item (QTreeWidgetItem) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
165 | @param column column that was double clicked (integer) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | """ |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
167 | if item is not None and column > 0: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
168 | columnStr = item.text(column) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
169 | if self.__entryRe.exactMatch(columnStr.strip()): |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
170 | filename, lineno, func = self.__entryRe.capturedTexts()[1:] |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
171 | try: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
172 | lineno = int(lineno) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
173 | except ValueError: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
174 | # do nothing, if the line info is not an integer |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
175 | return |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
176 | if self.__projectMode: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
177 | filename = self.__project.getAbsolutePath(filename) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
178 | self.sourceFile.emit(filename, lineno) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | def clear(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | Public slot to clear the call trace info. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | self.callTrace.clear() |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | self.__callStack = [] |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
187 | def setProjectMode(self, enabled): |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
188 | """ |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
189 | Public slot to set the call trace viewer to project mode. |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
190 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
191 | In project mode the call trace info is shown with project relative |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
192 | path names. |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
193 | |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
194 | @param enabled flag indicating to enable the project mode (boolean) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
195 | """ |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
196 | self.__projectMode = enabled |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
197 | if enabled and self.__project is None: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
198 | self.__project = e5App().getObject("Project") |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
199 | |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | def __addCallTraceInfo(self, isCall, fromFile, fromLine, fromFunction, |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | toFile, toLine, toFunction): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | Private method to add an entry to the call trace viewer. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | @param isCall flag indicating a 'call' (boolean) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | @param fromFile name of the originating file (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | @param fromLine line number in the originating file (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | @param fromFunction name of the originating function (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | @param toFile name of the target file (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | @param toLine line number in the target file (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | @param toFunction name of the target function (string) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | if isCall: |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | icon = UI.PixmapCache.getIcon("forward.png") |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | else: |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | icon = UI.PixmapCache.getIcon("back.png") |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | parentItem = self.__callStack[-1] if self.__callStack else self.callTrace |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
219 | if self.__projectMode: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
220 | fromFile = self.__project.getRelativePath(fromFile) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
221 | toFile = self.__project.getRelativePath(toFile) |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
222 | |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | itm = QTreeWidgetItem(parentItem, ["", |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | self.__entryFormat.format(fromFile, fromLine, fromFunction), |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | self.__entryFormat.format(toFile, toLine, toFunction)]) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | itm.setIcon(0, icon) |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
227 | itm.setData(0, Qt.UserRole, isCall) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | itm.setExpanded(True) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | if isCall: |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | self.__callStack.append(itm) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | else: |
2171
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
233 | if self.__callStack: |
c7dd548d67d8
Finished the coding part of the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2170
diff
changeset
|
234 | self.__callStack.pop(-1) |
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | def isCallTraceEnabled(self): |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | Public method to get the state of the call trace function. |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | @return flag indicating the state of the call trace function (boolean) |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | """ |
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | return self.__callTraceEnabled |