8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 import fnmatch |
11 import fnmatch |
12 |
12 |
13 from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale |
13 from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QLocale |
14 from PyQt5.QtWidgets import ( |
14 from PyQt6.QtWidgets import ( |
15 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
15 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
16 QApplication |
16 QApplication |
17 ) |
17 ) |
18 |
18 |
19 from .Ui_RawMetricsDialog import Ui_RawMetricsDialog |
19 from .Ui_RawMetricsDialog import Ui_RawMetricsDialog |
20 |
20 |
21 from E5Gui.E5Application import e5App |
21 from EricWidgets.EricApplication import ericApp |
22 |
22 |
23 import Preferences |
23 import Preferences |
24 import Utilities |
24 import Utilities |
25 |
25 |
26 |
26 |
27 class RawMetricsDialog(QDialog, Ui_RawMetricsDialog): |
27 class RawMetricsDialog(QDialog, Ui_RawMetricsDialog): |
28 """ |
28 """ |
29 Class implementing a dialog to show raw code metrics. |
29 Class implementing a dialog to show raw code metrics. |
30 """ |
30 """ |
31 FilePathRole = Qt.UserRole + 1 |
31 FilePathRole = Qt.ItemDataRole.UserRole + 1 |
32 |
32 |
33 def __init__(self, radonService, parent=None): |
33 def __init__(self, radonService, parent=None): |
34 """ |
34 """ |
35 Constructor |
35 Constructor |
36 |
36 |
39 @param parent reference to the parent widget |
39 @param parent reference to the parent widget |
40 @type QWidget |
40 @type QWidget |
41 """ |
41 """ |
42 super().__init__(parent) |
42 super().__init__(parent) |
43 self.setupUi(self) |
43 self.setupUi(self) |
44 self.setWindowFlags(Qt.Window) |
44 self.setWindowFlags(Qt.WindowType.Window) |
45 |
45 |
46 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
46 self.buttonBox.button( |
47 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
47 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
|
48 self.buttonBox.button( |
|
49 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
48 |
50 |
49 self.summaryList.headerItem().setText( |
51 self.summaryList.headerItem().setText( |
50 self.summaryList.columnCount(), "") |
52 self.summaryList.columnCount(), "") |
51 self.summaryList.header().resizeSection(0, 200) |
53 self.summaryList.header().resizeSection(0, 200) |
52 self.summaryList.header().resizeSection(1, 100) |
54 self.summaryList.header().resizeSection(1, 100) |
58 self.radonService.error.connect(self.__processError) |
60 self.radonService.error.connect(self.__processError) |
59 self.radonService.batchFinished.connect(self.__batchFinished) |
61 self.radonService.batchFinished.connect(self.__batchFinished) |
60 |
62 |
61 self.cancelled = False |
63 self.cancelled = False |
62 |
64 |
63 self.__project = e5App().getObject("Project") |
65 self.__project = ericApp().getObject("Project") |
64 self.__locale = QLocale() |
66 self.__locale = QLocale() |
65 self.__finished = True |
67 self.__finished = True |
66 self.__errorItem = None |
68 self.__errorItem = None |
67 |
69 |
68 self.__fileList = [] |
70 self.__fileList = [] |
91 |
93 |
92 def __resizeResultColumns(self): |
94 def __resizeResultColumns(self): |
93 """ |
95 """ |
94 Private method to resize the list columns. |
96 Private method to resize the list columns. |
95 """ |
97 """ |
96 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) |
98 self.resultList.header().resizeSections( |
|
99 QHeaderView.ResizeMode.ResizeToContents) |
97 self.resultList.header().setStretchLastSection(True) |
100 self.resultList.header().setStretchLastSection(True) |
98 |
101 |
99 def __createResultItem(self, filename, values): |
102 def __createResultItem(self, filename, values): |
100 """ |
103 """ |
101 Private slot to create a new item in the result list. |
104 Private slot to create a new item in the result list. |
121 (values["comments"] + values["multi"]) / |
124 (values["comments"] + values["multi"]) / |
122 (float(values["loc"]) or 1), |
125 (float(values["loc"]) or 1), |
123 1.0))) |
126 1.0))) |
124 itm = QTreeWidgetItem(self.resultList, data) |
127 itm = QTreeWidgetItem(self.resultList, data) |
125 for col in range(1, 10): |
128 for col in range(1, 10): |
126 itm.setTextAlignment(col, Qt.Alignment(Qt.AlignRight)) |
129 itm.setTextAlignment(col, Qt.AlignmentFlag.AlignRight) |
127 itm.setData(0, self.FilePathRole, filename) |
130 itm.setData(0, self.FilePathRole, filename) |
128 |
131 |
129 def __createErrorItem(self, filename, message): |
132 def __createErrorItem(self, filename, message): |
130 """ |
133 """ |
131 Private slot to create a new error item in the result list. |
134 Private slot to create a new error item in the result list. |
137 """ |
140 """ |
138 if self.__errorItem is None: |
141 if self.__errorItem is None: |
139 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
142 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
140 self.tr("Errors")]) |
143 self.tr("Errors")]) |
141 self.__errorItem.setExpanded(True) |
144 self.__errorItem.setExpanded(True) |
142 self.__errorItem.setForeground(0, Qt.red) |
145 self.__errorItem.setForeground(0, Qt.GlobalColor.red) |
143 |
146 |
144 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
147 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
145 message) |
148 message) |
146 if not self.resultList.findItems(msg, Qt.MatchExactly): |
149 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly): |
147 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
150 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
148 itm.setForeground(0, Qt.red) |
151 itm.setForeground(0, Qt.GlobalColor.red) |
149 itm.setFirstColumnSpanned(True) |
152 itm.setFirstColumnSpanned(True) |
150 |
153 |
151 def prepare(self, fileList, project): |
154 def prepare(self, fileList, project): |
152 """ |
155 """ |
153 Public method to prepare the dialog with a list of filenames. |
156 Public method to prepare the dialog with a list of filenames. |
158 @type Project |
161 @type Project |
159 """ |
162 """ |
160 self.__fileList = fileList[:] |
163 self.__fileList = fileList[:] |
161 self.__project = project |
164 self.__project = project |
162 |
165 |
163 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
166 self.buttonBox.button( |
164 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
167 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
165 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
168 self.buttonBox.button( |
|
169 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
170 self.buttonBox.button( |
|
171 QDialogButtonBox.StandardButton.Close).setDefault(True) |
166 |
172 |
167 self.filterFrame.setVisible(True) |
173 self.filterFrame.setVisible(True) |
168 |
174 |
169 self.__data = self.__project.getData( |
175 self.__data = self.__project.getData( |
170 "OTHERTOOLSPARMS", "RadonCodeMetrics") |
176 "OTHERTOOLSPARMS", "RadonCodeMetrics") |
184 self.__errorItem = None |
190 self.__errorItem = None |
185 self.resultList.clear() |
191 self.resultList.clear() |
186 self.summaryList.clear() |
192 self.summaryList.clear() |
187 QApplication.processEvents() |
193 QApplication.processEvents() |
188 |
194 |
189 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
195 self.buttonBox.button( |
190 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
196 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
191 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
197 self.buttonBox.button( |
|
198 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
|
199 self.buttonBox.button( |
|
200 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
192 QApplication.processEvents() |
201 QApplication.processEvents() |
193 |
202 |
194 if isinstance(fn, list): |
203 if isinstance(fn, list): |
195 self.files = fn |
204 self.files = fn |
196 elif os.path.isdir(fn): |
205 elif os.path.isdir(fn): |
197 self.files = [] |
206 self.files = [] |
198 extensions = set(Preferences.getPython("PythonExtensions") + |
207 extensions = set(Preferences.getPython("Python3Extensions")) |
199 Preferences.getPython("Python3Extensions")) |
|
200 for ext in extensions: |
208 for ext in extensions: |
201 self.files.extend( |
209 self.files.extend( |
202 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) |
210 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) |
203 else: |
211 else: |
204 self.files = [fn] |
212 self.files = [fn] |
390 if not self.__finished: |
398 if not self.__finished: |
391 self.__finished = True |
399 self.__finished = True |
392 |
400 |
393 # reenable updates of the list |
401 # reenable updates of the list |
394 self.resultList.setSortingEnabled(True) |
402 self.resultList.setSortingEnabled(True) |
395 self.resultList.sortItems(0, Qt.AscendingOrder) |
403 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
396 self.resultList.setUpdatesEnabled(True) |
404 self.resultList.setUpdatesEnabled(True) |
397 |
405 |
398 self.__createSummary() |
406 self.__createSummary() |
399 |
407 |
400 self.cancelled = True |
408 self.cancelled = True |
401 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
409 self.buttonBox.button( |
402 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
410 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
403 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
411 self.buttonBox.button( |
|
412 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
413 self.buttonBox.button( |
|
414 QDialogButtonBox.StandardButton.Close).setDefault(True) |
404 |
415 |
405 self.resultList.header().resizeSections( |
416 self.resultList.header().resizeSections( |
406 QHeaderView.ResizeToContents) |
417 QHeaderView.ResizeMode.ResizeToContents) |
407 self.resultList.header().setStretchLastSection(True) |
418 self.resultList.header().setStretchLastSection(True) |
408 if qVersion() >= "5.0.0": |
419 self.resultList.header().setSectionResizeMode( |
409 self.resultList.header().setSectionResizeMode( |
420 QHeaderView.ResizeMode.Interactive) |
410 QHeaderView.Interactive) |
|
411 else: |
|
412 self.resultList.header().setResizeMode(QHeaderView.Interactive) |
|
413 |
421 |
414 self.checkProgress.setVisible(False) |
422 self.checkProgress.setVisible(False) |
415 self.checkProgressLabel.setVisible(False) |
423 self.checkProgressLabel.setVisible(False) |
416 |
424 |
417 def __createSummary(self): |
425 def __createSummary(self): |
437 self.__locale.toString(self.__summary["multi"])) |
445 self.__locale.toString(self.__summary["multi"])) |
438 self.__createSummaryItem( |
446 self.__createSummaryItem( |
439 self.tr("Empty Lines"), |
447 self.tr("Empty Lines"), |
440 self.__locale.toString(self.__summary["blank"])) |
448 self.__locale.toString(self.__summary["blank"])) |
441 |
449 |
442 self.summaryList.header().resizeSections(QHeaderView.ResizeToContents) |
450 self.summaryList.header().resizeSections( |
|
451 QHeaderView.ResizeMode.ResizeToContents) |
443 self.summaryList.header().setStretchLastSection(True) |
452 self.summaryList.header().setStretchLastSection(True) |
444 |
453 |
445 def __createSummaryItem(self, col0, col1): |
454 def __createSummaryItem(self, col0, col1): |
446 """ |
455 """ |
447 Private slot to create a new item in the summary list. |
456 Private slot to create a new item in the summary list. |
448 |
457 |
449 @param col0 string for column 0 (string) |
458 @param col0 string for column 0 (string) |
450 @param col1 string for column 1 (string) |
459 @param col1 string for column 1 (string) |
451 """ |
460 """ |
452 itm = QTreeWidgetItem(self.summaryList, [col0, col1]) |
461 itm = QTreeWidgetItem(self.summaryList, [col0, col1]) |
453 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) |
462 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
454 |
463 |
455 @pyqtSlot(QAbstractButton) |
464 @pyqtSlot(QAbstractButton) |
456 def on_buttonBox_clicked(self, button): |
465 def on_buttonBox_clicked(self, button): |
457 """ |
466 """ |
458 Private slot called by a button of the button box clicked. |
467 Private slot called by a button of the button box clicked. |
459 |
468 |
460 @param button button that was clicked |
469 @param button button that was clicked |
461 @type QAbstractButton |
470 @type QAbstractButton |
462 """ |
471 """ |
463 if button == self.buttonBox.button(QDialogButtonBox.Close): |
472 if button == self.buttonBox.button( |
|
473 QDialogButtonBox.StandardButton.Close |
|
474 ): |
464 self.close() |
475 self.close() |
465 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
476 elif button == self.buttonBox.button( |
|
477 QDialogButtonBox.StandardButton.Cancel |
|
478 ): |
466 if self.__batch: |
479 if self.__batch: |
467 self.radonService.cancelRawMetricsBatch() |
480 self.radonService.cancelRawMetricsBatch() |
468 QTimer.singleShot(1000, self.__finish) |
481 QTimer.singleShot(1000, self.__finish) |
469 else: |
482 else: |
470 self.__finish() |
483 self.__finish() |