|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Call Trace viewer widget. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, pyqtSignal |
|
11 from PyQt4.QtGui import QWidget, QTreeWidgetItem |
|
12 |
|
13 from .Ui_CallTraceViewer import Ui_CallTraceViewer |
|
14 |
|
15 import UI.PixmapCache |
|
16 import Preferences |
|
17 |
|
18 |
|
19 class CallTraceViewer(QWidget, Ui_CallTraceViewer): |
|
20 """ |
|
21 Class implementing the Call Trace viewer widget. |
|
22 |
|
23 @signal sourceFile(str, int) emitted to show the source of a call/return point |
|
24 """ |
|
25 sourceFile = pyqtSignal(str, int) |
|
26 |
|
27 def __init__(self, debugServer, parent=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param parent reference to the parent widget (QWidget) |
|
32 """ |
|
33 super().__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.__dbs = debugServer |
|
37 |
|
38 self.startTraceButton.setIcon(UI.PixmapCache.getIcon("callTraceStart.png")) |
|
39 self.stopTraceButton.setIcon(UI.PixmapCache.getIcon("callTraceStop.png")) |
|
40 self.resizeButton.setIcon(UI.PixmapCache.getIcon("resizeColumns.png")) |
|
41 self.clearButton.setIcon(UI.PixmapCache.getIcon("editDelete.png")) |
|
42 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave.png")) |
|
43 |
|
44 self.__headerItem = QTreeWidgetItem(["", self.trUtf8("From"), self.trUtf8("To")]) |
|
45 self.__headerItem.setIcon(0, UI.PixmapCache.getIcon("callReturn.png")) |
|
46 self.callTrace.setHeaderItem(self.__headerItem) |
|
47 |
|
48 self.__callStack = [] |
|
49 |
|
50 self.__entryFormat = "{0}:{1} ({2})" |
|
51 |
|
52 self.__callTraceEnabled = Preferences.toBool( |
|
53 Preferences.Prefs.settings.value("CallTrace/Enabled", False)) |
|
54 |
|
55 if self.__callTraceEnabled: |
|
56 self.stopTraceButton.setEnabled(False) |
|
57 else: |
|
58 self.startTraceButton.setEnabled(False) |
|
59 |
|
60 self.__dbs.callTraceInfo.connect(self.__addCallTraceInfo) |
|
61 |
|
62 @pyqtSlot() |
|
63 def on_startTraceButton_clicked(self): |
|
64 """ |
|
65 Private slot to start call tracing. |
|
66 """ |
|
67 self.__dbs.setCallTraceEnabled(True) |
|
68 self.stopTraceButton.setEnabled(True) |
|
69 self.startTraceButton.setEnabled(False) |
|
70 Preferences.Prefs.settings.setValue("CallTrace/Enabled", True) |
|
71 |
|
72 @pyqtSlot() |
|
73 def on_stopTraceButton_clicked(self): |
|
74 """ |
|
75 Private slot to start call tracing. |
|
76 """ |
|
77 self.__dbs.setCallTraceEnabled(False) |
|
78 self.stopTraceButton.setEnabled(False) |
|
79 self.startTraceButton.setEnabled(True) |
|
80 Preferences.Prefs.settings.setValue("CallTrace/Enabled", False) |
|
81 |
|
82 @pyqtSlot() |
|
83 def on_resizeButton_clicked(self): |
|
84 """ |
|
85 Private slot to resize the columns of the call trace to their contents. |
|
86 """ |
|
87 for column in range(self.callTrace.columnCount()): |
|
88 self.callTrace.resizeColumnToContents(column) |
|
89 |
|
90 @pyqtSlot() |
|
91 def on_clearButton_clicked(self): |
|
92 """ |
|
93 Private slot to clear the call trace. |
|
94 """ |
|
95 self.clear() |
|
96 |
|
97 @pyqtSlot() |
|
98 def on_saveButton_clicked(self): |
|
99 """ |
|
100 Slot documentation goes here. |
|
101 """ |
|
102 # TODO: not implemented yet |
|
103 raise NotImplementedError |
|
104 |
|
105 @pyqtSlot(QTreeWidgetItem, int) |
|
106 def on_callTrace_itemDoubleClicked(self, item, column): |
|
107 """ |
|
108 Slot documentation goes here. |
|
109 """ |
|
110 # TODO: not implemented yet |
|
111 raise NotImplementedError |
|
112 |
|
113 def clear(self): |
|
114 """ |
|
115 Public slot to clear the call trace info. |
|
116 """ |
|
117 self.callTrace.clear() |
|
118 self.__callStack = [] |
|
119 |
|
120 def __addCallTraceInfo(self, isCall, fromFile, fromLine, fromFunction, |
|
121 toFile, toLine, toFunction): |
|
122 """ |
|
123 Private method to add an entry to the call trace viewer. |
|
124 |
|
125 @param isCall flag indicating a 'call' (boolean) |
|
126 @param fromFile name of the originating file (string) |
|
127 @param fromLine line number in the originating file (string) |
|
128 @param fromFunction name of the originating function (string) |
|
129 @param toFile name of the target file (string) |
|
130 @param toLine line number in the target file (string) |
|
131 @param toFunction name of the target function (string) |
|
132 """ |
|
133 if isCall: |
|
134 icon = UI.PixmapCache.getIcon("forward.png") |
|
135 else: |
|
136 icon = UI.PixmapCache.getIcon("back.png") |
|
137 parentItem = self.__callStack[-1] if self.__callStack else self.callTrace |
|
138 |
|
139 itm = QTreeWidgetItem(parentItem, ["", |
|
140 self.__entryFormat.format(fromFile, fromLine, fromFunction), |
|
141 self.__entryFormat.format(toFile, toLine, toFunction)]) |
|
142 itm.setIcon(0, icon) |
|
143 itm.setExpanded(True) |
|
144 |
|
145 if isCall: |
|
146 self.__callStack.append(itm) |
|
147 else: |
|
148 self.__callStack.pop(-1) |
|
149 |
|
150 def isCallTraceEnabled(self): |
|
151 """ |
|
152 Public method to get the state of the call trace function. |
|
153 |
|
154 @return flag indicating the state of the call trace function (boolean) |
|
155 """ |
|
156 return self.__callTraceEnabled |