16 |
16 |
17 import os |
17 import os |
18 import fnmatch |
18 import fnmatch |
19 |
19 |
20 from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale |
20 from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale |
|
21 from PyQt5.QtGui import QColor |
21 from PyQt5.QtWidgets import ( |
22 from PyQt5.QtWidgets import ( |
22 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
23 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
23 QApplication |
24 QApplication |
24 ) |
25 ) |
25 |
26 |
61 self.cancelled = False |
62 self.cancelled = False |
62 |
63 |
63 self.__project = e5App().getObject("Project") |
64 self.__project = e5App().getObject("Project") |
64 self.__locale = QLocale() |
65 self.__locale = QLocale() |
65 self.__finished = True |
66 self.__finished = True |
|
67 self.__errorItem = None |
66 |
68 |
67 self.__fileList = [] |
69 self.__fileList = [] |
68 self.filterFrame.setVisible(False) |
70 self.filterFrame.setVisible(False) |
69 |
71 |
70 self.explanationLabel.setText(self.tr( |
72 self.explanationLabel.setText(self.tr( |
73 "<tr><td><b>A</b></td><td>score > 19</td></tr>" |
75 "<tr><td><b>A</b></td><td>score > 19</td></tr>" |
74 "<tr><td><b>B</b></td><td>9 < score ≤ 19</td></tr>" |
76 "<tr><td><b>B</b></td><td>9 < score ≤ 19</td></tr>" |
75 "<tr><td><b>C</b></td><td>score ≤ 9</td></tr>" |
77 "<tr><td><b>C</b></td><td>score ≤ 9</td></tr>" |
76 "</table>" |
78 "</table>" |
77 )) |
79 )) |
|
80 self.__rankColors = { |
|
81 "A": Qt.green, |
|
82 "B": Qt.yellow, #QColor("orange"), |
|
83 "C": Qt.red, |
|
84 } |
78 |
85 |
79 def __resizeResultColumns(self): |
86 def __resizeResultColumns(self): |
80 """ |
87 """ |
81 Private method to resize the list columns. |
88 Private method to resize the list columns. |
82 """ |
89 """ |
90 @param filename name of the file |
97 @param filename name of the file |
91 @type str |
98 @type str |
92 @param values values to be displayed |
99 @param values values to be displayed |
93 @type dict |
100 @type dict |
94 """ |
101 """ |
95 # TODO: colorize the rank column according to rank (green, orange, red) |
|
96 data = [self.__project.getRelativePath(filename)] |
102 data = [self.__project.getRelativePath(filename)] |
97 try: |
103 try: |
98 data.append(self.__locale.toString(float(values["mi"]), "f", 2)) |
104 data.append("{0:>6}".format( |
|
105 self.__locale.toString(float(values["mi"]), "f", 2))) |
99 except ValueError: |
106 except ValueError: |
100 data.append(values["mi"]) |
107 data.append(values["mi"]) |
101 data.append(values["rank"]) |
108 data.append(values["rank"]) |
102 itm = QTreeWidgetItem(self.resultList, data) |
109 itm = QTreeWidgetItem(self.resultList, data) |
103 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) |
110 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) |
104 itm.setTextAlignment(2, Qt.Alignment(Qt.AlignHCenter)) |
111 itm.setTextAlignment(2, Qt.Alignment(Qt.AlignHCenter)) |
|
112 if values["rank"] in ["A", "B", "C"]: |
|
113 itm.setBackground(2, self.__rankColors[values["rank"]]) |
105 |
114 |
106 if values["rank"] in ["A", "B", "C"]: |
115 if values["rank"] in ["A", "B", "C"]: |
107 self.__summary[values["rank"]] += 1 |
116 self.__summary[values["rank"]] += 1 |
108 |
117 |
109 def __createErrorItem(self, filename, message): |
118 def __createErrorItem(self, filename, message): |
113 @param filename name of the file |
122 @param filename name of the file |
114 @type str |
123 @type str |
115 @param message error message |
124 @param message error message |
116 @type str |
125 @type str |
117 """ |
126 """ |
118 itm = QTreeWidgetItem(self.resultList, [ |
127 if self.__errorItem is None: |
119 "{0} ({1})".format(self.__project.getRelativePath(filename), |
128 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
120 message)]) |
129 self.tr("Errors")]) |
121 itm.setFirstColumnSpanned(True) |
130 self.__errorItem.setExpanded(True) |
122 font = itm.font(0) |
131 self.__errorItem.setForeground(0, Qt.red) |
123 font.setItalic(True) |
132 |
124 itm.setFont(0, font) |
133 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
|
134 message) |
|
135 if not self.resultList.findItems(msg, Qt.MatchExactly): |
|
136 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
|
137 itm.setForeground(0, Qt.red) |
|
138 itm.setFirstColumnSpanned(True) |
125 |
139 |
126 def prepare(self, fileList, project): |
140 def prepare(self, fileList, project): |
127 """ |
141 """ |
128 Public method to prepare the dialog with a list of filenames. |
142 Public method to prepare the dialog with a list of filenames. |
129 |
143 |
273 QApplication.processEvents() |
287 QApplication.processEvents() |
274 |
288 |
275 self.__finished = False |
289 self.__finished = False |
276 self.radonService.maintainabilityIndexBatch(argumentsList) |
290 self.radonService.maintainabilityIndexBatch(argumentsList) |
277 |
291 |
278 def __batchFinished(self): |
292 def __batchFinished(self, type_): |
279 """ |
293 """ |
280 Private slot handling the completion of a batch job. |
294 Private slot handling the completion of a batch job. |
281 """ |
295 |
282 self.checkProgressLabel.setPath("") |
296 @param type_ type of the calculated metrics |
283 self.checkProgress.setMaximum(1) |
297 @type str, one of ["raw", "mi", "cc"] |
284 self.checkProgress.setValue(1) |
298 """ |
285 self.__finish() |
299 if type_ == "mi": |
286 |
300 self.checkProgressLabel.setPath("") |
287 def __processError(self, fn, msg): |
301 self.checkProgress.setMaximum(1) |
|
302 self.checkProgress.setValue(1) |
|
303 self.__finish() |
|
304 |
|
305 def __processError(self, type_, fn, msg): |
288 """ |
306 """ |
289 Private slot to process an error indication from the service. |
307 Private slot to process an error indication from the service. |
290 |
308 |
|
309 @param type_ type of the calculated metrics |
|
310 @type str, one of ["raw", "mi", "cc"] |
291 @param fn filename of the file |
311 @param fn filename of the file |
292 @type str |
312 @type str |
293 @param msg error message |
313 @param msg error message |
294 @type str |
314 @type str |
295 """ |
315 """ |
296 self.__createErrorItem(fn, msg) |
316 if type_ == "mi": |
|
317 self.__createErrorItem(fn, msg) |
297 |
318 |
298 def __processResult(self, fn, result): |
319 def __processResult(self, fn, result): |
299 """ |
320 """ |
300 Private slot called after perfoming a maintainability index calculation |
321 Private slot called after perfoming a maintainability index calculation |
301 on one file. |
322 on one file. |
319 self.__createResultItem(fn, result) |
340 self.__createResultItem(fn, result) |
320 |
341 |
321 self.progress += 1 |
342 self.progress += 1 |
322 |
343 |
323 self.checkProgress.setValue(self.progress) |
344 self.checkProgress.setValue(self.progress) |
324 self.checkProgressLabel.setPath(fn) |
345 self.checkProgressLabel.setPath(self.__project.getRelativePath(fn)) |
325 QApplication.processEvents() |
346 QApplication.processEvents() |
326 |
347 |
327 if not self.__batch: |
348 if not self.__batch: |
328 self.maintainabilityIndex() |
349 self.maintainabilityIndex() |
329 |
350 |
402 if filterList: |
423 if filterList: |
403 for filter in filterList: |
424 for filter in filterList: |
404 fileList = \ |
425 fileList = \ |
405 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
426 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
406 |
427 |
|
428 self.__errorItem = None |
407 self.resultList.clear() |
429 self.resultList.clear() |
408 self.cancelled = False |
430 self.cancelled = False |
409 self.start(fileList) |
431 self.start(fileList) |