5 |
5 |
6 """ |
6 """ |
7 Module implementing the Call Trace viewer widget. |
7 Module implementing the Call Trace viewer widget. |
8 """ |
8 """ |
9 |
9 |
|
10 import pathlib |
10 import re |
11 import re |
11 |
12 |
12 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QFileInfo |
13 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt |
13 from PyQt6.QtWidgets import QWidget, QTreeWidgetItem |
14 from PyQt6.QtWidgets import QWidget, QTreeWidgetItem |
14 |
15 |
15 from EricWidgets.EricApplication import ericApp |
16 from EricWidgets.EricApplication import ericApp |
16 from EricWidgets import EricFileDialog, EricMessageBox |
17 from EricWidgets import EricFileDialog, EricMessageBox |
17 |
18 |
18 from .Ui_CallTraceViewer import Ui_CallTraceViewer |
19 from .Ui_CallTraceViewer import Ui_CallTraceViewer |
19 |
20 |
20 import UI.PixmapCache |
21 import UI.PixmapCache |
21 import Preferences |
22 import Preferences |
22 import Utilities |
|
23 |
23 |
24 |
24 |
25 class CallTraceViewer(QWidget, Ui_CallTraceViewer): |
25 class CallTraceViewer(QWidget, Ui_CallTraceViewer): |
26 """ |
26 """ |
27 Class implementing the Call Trace viewer widget. |
27 Class implementing the Call Trace viewer widget. |
158 "", |
158 "", |
159 self.tr("Text Files (*.txt);;All Files (*)"), |
159 self.tr("Text Files (*.txt);;All Files (*)"), |
160 None, |
160 None, |
161 EricFileDialog.DontConfirmOverwrite) |
161 EricFileDialog.DontConfirmOverwrite) |
162 if fname: |
162 if fname: |
163 ext = QFileInfo(fname).suffix() |
163 fpath = pathlib.Path(fname) |
164 if not ext: |
164 if not fpath.suffix: |
165 ex = selectedFilter.split("(*")[1].split(")")[0] |
165 ex = selectedFilter.split("(*")[1].split(")")[0] |
166 if ex: |
166 if ex: |
167 fname += ex |
167 fpath = fpath.with_suffix(ex) |
168 if QFileInfo(fname).exists(): |
168 if fpath.exists(): |
169 res = EricMessageBox.yesNo( |
169 res = EricMessageBox.yesNo( |
170 self, |
170 self, |
171 self.tr("Save Call Trace Info"), |
171 self.tr("Save Call Trace Info"), |
172 self.tr("<p>The file <b>{0}</b> already exists." |
172 self.tr("<p>The file <b>{0}</b> already exists." |
173 " Overwrite it?</p>").format(fname), |
173 " Overwrite it?</p>").format(str(fpath)), |
174 icon=EricMessageBox.Warning) |
174 icon=EricMessageBox.Warning) |
175 if not res: |
175 if not res: |
176 return |
176 return |
177 fname = Utilities.toNativeSeparators(fname) |
|
178 |
177 |
179 try: |
178 try: |
180 title = self.tr("Call Trace Info of '{0}'").format( |
179 title = self.tr("Call Trace Info of '{0}'").format( |
181 self.__tracedDebuggerId) |
180 self.__tracedDebuggerId) |
182 with open(fname, "w", encoding="utf-8") as f: |
181 with fpath.open("w", encoding="utf-8") as f: |
183 f.write("{0}\n".format(title)) |
182 f.write("{0}\n".format(title)) |
184 f.write("{0}\n\n".format(len(title) * "=")) |
183 f.write("{0}\n\n".format(len(title) * "=")) |
185 itm = self.callTrace.topLevelItem(0) |
184 itm = self.callTrace.topLevelItem(0) |
186 while itm is not None: |
185 while itm is not None: |
187 isCall = itm.data(0, Qt.ItemDataRole.UserRole) |
186 isCall = itm.data(0, Qt.ItemDataRole.UserRole) |
195 self, |
194 self, |
196 self.tr("Error saving Call Trace Info"), |
195 self.tr("Error saving Call Trace Info"), |
197 self.tr("""<p>The call trace info could not""" |
196 self.tr("""<p>The call trace info could not""" |
198 """ be written to <b>{0}</b></p>""" |
197 """ be written to <b>{0}</b></p>""" |
199 """<p>Reason: {1}</p>""") |
198 """<p>Reason: {1}</p>""") |
200 .format(fname, str(err))) |
199 .format(str(fpath), str(err))) |
201 |
200 |
202 @pyqtSlot(QTreeWidgetItem, int) |
201 @pyqtSlot(QTreeWidgetItem, int) |
203 def on_callTrace_itemDoubleClicked(self, item, column): |
202 def on_callTrace_itemDoubleClicked(self, item, column): |
204 """ |
203 """ |
205 Private slot to open the double clicked file in an editor. |
204 Private slot to open the double clicked file in an editor. |