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.QtGui import QColor |
14 from PyQt6.QtGui import QColor |
15 from PyQt5.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
16 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
16 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
17 QApplication |
17 QApplication |
18 ) |
18 ) |
19 |
19 |
20 from .Ui_MaintainabilityIndexDialog import Ui_MaintainabilityIndexDialog |
20 from .Ui_MaintainabilityIndexDialog import Ui_MaintainabilityIndexDialog |
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 MaintainabilityIndexDialog(QDialog, Ui_MaintainabilityIndexDialog): |
27 class MaintainabilityIndexDialog(QDialog, Ui_MaintainabilityIndexDialog): |
28 """ |
28 """ |
29 Class implementing a dialog to show maintainability indexes. |
29 Class implementing a dialog to show maintainability indexes. |
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.resultList.headerItem().setText(self.resultList.columnCount(), "") |
51 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
50 |
52 |
51 self.radonService = radonService |
53 self.radonService = radonService |
52 self.radonService.maintainabilityIndexDone.connect( |
54 self.radonService.maintainabilityIndexDone.connect( |
54 self.radonService.error.connect(self.__processError) |
56 self.radonService.error.connect(self.__processError) |
55 self.radonService.batchFinished.connect(self.__batchFinished) |
57 self.radonService.batchFinished.connect(self.__batchFinished) |
56 |
58 |
57 self.cancelled = False |
59 self.cancelled = False |
58 |
60 |
59 self.__project = e5App().getObject("Project") |
61 self.__project = ericApp().getObject("Project") |
60 self.__locale = QLocale() |
62 self.__locale = QLocale() |
61 self.__finished = True |
63 self.__finished = True |
62 self.__errorItem = None |
64 self.__errorItem = None |
63 |
65 |
64 self.__fileList = [] |
66 self.__fileList = [] |
73 "<tr><td><b>C</b></td><td>9 - 0</td><td>extremely low</td></tr>" |
75 "<tr><td><b>C</b></td><td>9 - 0</td><td>extremely low</td></tr>" |
74 "</table>" |
76 "</table>" |
75 )) |
77 )) |
76 |
78 |
77 try: |
79 try: |
78 usesDarkPalette = e5App().usesDarkPalette() |
80 usesDarkPalette = ericApp().usesDarkPalette() |
79 except AttributeError: |
81 except AttributeError: |
80 from PyQt5.QtGui import QPalette |
82 from PyQt6.QtGui import QPalette |
81 palette = e5App().palette() |
83 palette = ericApp().palette() |
82 lightness = palette.color(QPalette.Window).lightness() |
84 lightness = palette.color(QPalette.Window).lightness() |
83 usesDarkPalette = lightness <= 128 |
85 usesDarkPalette = lightness <= 128 |
84 if usesDarkPalette: |
86 if usesDarkPalette: |
85 self.__rankColors = { |
87 self.__rankColors = { |
86 "A": QColor("#308030"), |
88 "A": QColor("#308030"), |
96 |
98 |
97 def __resizeResultColumns(self): |
99 def __resizeResultColumns(self): |
98 """ |
100 """ |
99 Private method to resize the list columns. |
101 Private method to resize the list columns. |
100 """ |
102 """ |
101 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) |
103 self.resultList.header().resizeSections( |
|
104 QHeaderView.ResizeMode.ResizeMode.ResizeToContents) |
102 self.resultList.header().setStretchLastSection(True) |
105 self.resultList.header().setStretchLastSection(True) |
103 |
106 |
104 def __createResultItem(self, filename, values): |
107 def __createResultItem(self, filename, values): |
105 """ |
108 """ |
106 Private slot to create a new item in the result list. |
109 Private slot to create a new item in the result list. |
116 self.__locale.toString(float(values["mi"]), "f", 2))) |
119 self.__locale.toString(float(values["mi"]), "f", 2))) |
117 except ValueError: |
120 except ValueError: |
118 data.append(values["mi"]) |
121 data.append(values["mi"]) |
119 data.append(values["rank"]) |
122 data.append(values["rank"]) |
120 itm = QTreeWidgetItem(self.resultList, data) |
123 itm = QTreeWidgetItem(self.resultList, data) |
121 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) |
124 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
122 itm.setTextAlignment(2, Qt.Alignment(Qt.AlignHCenter)) |
125 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter) |
123 if values["rank"] in self.__rankColors: |
126 if values["rank"] in self.__rankColors: |
124 itm.setBackground(2, self.__rankColors[values["rank"]]) |
127 itm.setBackground(2, self.__rankColors[values["rank"]]) |
125 itm.setData(0, self.FilePathRole, filename) |
128 itm.setData(0, self.FilePathRole, filename) |
126 |
129 |
127 if values["rank"] in self.__summary: |
130 if values["rank"] in self.__summary: |
138 """ |
141 """ |
139 if self.__errorItem is None: |
142 if self.__errorItem is None: |
140 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
143 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
141 self.tr("Errors")]) |
144 self.tr("Errors")]) |
142 self.__errorItem.setExpanded(True) |
145 self.__errorItem.setExpanded(True) |
143 self.__errorItem.setForeground(0, Qt.red) |
146 self.__errorItem.setForeground(0, Qt.GlobalColor.red) |
144 |
147 |
145 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
148 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
146 message) |
149 message) |
147 if not self.resultList.findItems(msg, Qt.MatchExactly): |
150 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly): |
148 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
151 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
149 itm.setForeground(0, Qt.red) |
152 itm.setForeground(0, Qt.GlobalColor.red) |
150 itm.setFirstColumnSpanned(True) |
153 itm.setFirstColumnSpanned(True) |
151 |
154 |
152 def prepare(self, fileList, project): |
155 def prepare(self, fileList, project): |
153 """ |
156 """ |
154 Public method to prepare the dialog with a list of filenames. |
157 Public method to prepare the dialog with a list of filenames. |
159 @type Project |
162 @type Project |
160 """ |
163 """ |
161 self.__fileList = fileList[:] |
164 self.__fileList = fileList[:] |
162 self.__project = project |
165 self.__project = project |
163 |
166 |
164 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
167 self.buttonBox.button( |
165 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
168 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
166 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
169 self.buttonBox.button( |
|
170 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
171 self.buttonBox.button( |
|
172 QDialogButtonBox.StandardButton.Close).setDefault(True) |
167 |
173 |
168 self.filterFrame.setVisible(True) |
174 self.filterFrame.setVisible(True) |
169 |
175 |
170 self.__data = self.__project.getData( |
176 self.__data = self.__project.getData( |
171 "OTHERTOOLSPARMS", "RadonCodeMetrics") |
177 "OTHERTOOLSPARMS", "RadonCodeMetrics") |
185 self.resultList.clear() |
191 self.resultList.clear() |
186 self.summaryLabel.clear() |
192 self.summaryLabel.clear() |
187 self.cancelled = False |
193 self.cancelled = False |
188 QApplication.processEvents() |
194 QApplication.processEvents() |
189 |
195 |
190 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
196 self.buttonBox.button( |
191 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
197 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
192 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
198 self.buttonBox.button( |
|
199 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
|
200 self.buttonBox.button( |
|
201 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
193 QApplication.processEvents() |
202 QApplication.processEvents() |
194 |
203 |
195 if isinstance(fn, list): |
204 if isinstance(fn, list): |
196 self.files = fn |
205 self.files = fn |
197 elif os.path.isdir(fn): |
206 elif os.path.isdir(fn): |
198 self.files = [] |
207 self.files = [] |
199 extensions = set(Preferences.getPython("PythonExtensions") + |
208 extensions = set(Preferences.getPython("Python3Extensions")) |
200 Preferences.getPython("Python3Extensions")) |
|
201 for ext in extensions: |
209 for ext in extensions: |
202 self.files.extend( |
210 self.files.extend( |
203 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) |
211 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) |
204 else: |
212 else: |
205 self.files = [fn] |
213 self.files = [fn] |
239 Public method to start a maintainability index calculation for one |
247 Public method to start a maintainability index calculation for one |
240 Python file. |
248 Python file. |
241 |
249 |
242 The results are reported to the __processResult slot. |
250 The results are reported to the __processResult slot. |
243 |
251 |
244 @keyparam codestring optional sourcestring |
252 @param codestring optional sourcestring |
245 @type str |
253 @type str |
246 """ |
254 """ |
247 if not self.files: |
255 if not self.files: |
248 self.checkProgressLabel.setPath("") |
256 self.checkProgressLabel.setPath("") |
249 self.checkProgress.setMaximum(1) |
257 self.checkProgress.setMaximum(1) |
372 if not self.__finished: |
380 if not self.__finished: |
373 self.__finished = True |
381 self.__finished = True |
374 |
382 |
375 # reenable updates of the list |
383 # reenable updates of the list |
376 self.resultList.setSortingEnabled(True) |
384 self.resultList.setSortingEnabled(True) |
377 self.resultList.sortItems(0, Qt.AscendingOrder) |
385 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
378 self.resultList.setUpdatesEnabled(True) |
386 self.resultList.setUpdatesEnabled(True) |
379 |
387 |
380 self.cancelled = True |
388 self.cancelled = True |
381 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
389 self.buttonBox.button( |
382 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
390 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
383 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
391 self.buttonBox.button( |
|
392 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
393 self.buttonBox.button( |
|
394 QDialogButtonBox.StandardButton.Close).setDefault(True) |
384 |
395 |
385 self.resultList.header().resizeSections( |
396 self.resultList.header().resizeSections( |
386 QHeaderView.ResizeToContents) |
397 QHeaderView.ResizeMode.ResizeToContents) |
387 self.resultList.header().setStretchLastSection(True) |
398 self.resultList.header().setStretchLastSection(True) |
388 if qVersion() >= "5.0.0": |
399 self.resultList.header().setSectionResizeMode( |
389 self.resultList.header().setSectionResizeMode( |
400 QHeaderView.ResizeMode.Interactive) |
390 QHeaderView.Interactive) |
|
391 else: |
|
392 self.resultList.header().setResizeMode(QHeaderView.Interactive) |
|
393 |
401 |
394 self.summaryLabel.setText(self.tr( |
402 self.summaryLabel.setText(self.tr( |
395 "<table>" |
403 "<table>" |
396 "<tr><td colspan=2><b>Summary:</b></td></tr>" |
404 "<tr><td colspan=2><b>Summary:</b></td></tr>" |
397 "<tr><td><b>A</b></td><td align='right'>{0} files</td></tr>" |
405 "<tr><td><b>A</b></td><td align='right'>{0} files</td></tr>" |
412 Private slot called by a button of the button box clicked. |
420 Private slot called by a button of the button box clicked. |
413 |
421 |
414 @param button button that was clicked |
422 @param button button that was clicked |
415 @type QAbstractButton |
423 @type QAbstractButton |
416 """ |
424 """ |
417 if button == self.buttonBox.button(QDialogButtonBox.Close): |
425 if button == self.buttonBox.button( |
|
426 QDialogButtonBox.StandardButton.Close |
|
427 ): |
418 self.close() |
428 self.close() |
419 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
429 elif button == self.buttonBox.button( |
|
430 QDialogButtonBox.StandardButton.Cancel |
|
431 ): |
420 if self.__batch: |
432 if self.__batch: |
421 self.radonService.cancelMaintainabilityIndexBatch() |
433 self.radonService.cancelMaintainabilityIndexBatch() |
422 QTimer.singleShot(1000, self.__finish) |
434 QTimer.singleShot(1000, self.__finish) |
423 else: |
435 else: |
424 self.__finish() |
436 self.__finish() |