26 |
30 |
27 class MaintainabilityIndexDialog(QDialog, Ui_MaintainabilityIndexDialog): |
31 class MaintainabilityIndexDialog(QDialog, Ui_MaintainabilityIndexDialog): |
28 """ |
32 """ |
29 Class implementing a dialog to show maintainability indexes. |
33 Class implementing a dialog to show maintainability indexes. |
30 """ |
34 """ |
|
35 |
31 FilePathRole = Qt.ItemDataRole.UserRole + 1 |
36 FilePathRole = Qt.ItemDataRole.UserRole + 1 |
32 |
37 |
33 def __init__(self, radonService, parent=None): |
38 def __init__(self, radonService, parent=None): |
34 """ |
39 """ |
35 Constructor |
40 Constructor |
36 |
41 |
37 @param radonService reference to the service |
42 @param radonService reference to the service |
38 @type RadonMetricsPlugin |
43 @type RadonMetricsPlugin |
39 @param parent reference to the parent widget |
44 @param parent reference to the parent widget |
40 @type QWidget |
45 @type QWidget |
41 """ |
46 """ |
42 super().__init__(parent) |
47 super().__init__(parent) |
43 self.setupUi(self) |
48 self.setupUi(self) |
44 self.setWindowFlags(Qt.WindowType.Window) |
49 self.setWindowFlags(Qt.WindowType.Window) |
45 |
50 |
46 self.buttonBox.button( |
51 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
47 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
52 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
48 self.buttonBox.button( |
53 |
49 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
50 |
|
51 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
54 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
52 |
55 |
53 self.radonService = radonService |
56 self.radonService = radonService |
54 self.radonService.maintainabilityIndexDone.connect( |
57 self.radonService.maintainabilityIndexDone.connect(self.__processResult) |
55 self.__processResult) |
|
56 self.radonService.error.connect(self.__processError) |
58 self.radonService.error.connect(self.__processError) |
57 self.radonService.batchFinished.connect(self.__batchFinished) |
59 self.radonService.batchFinished.connect(self.__batchFinished) |
58 |
60 |
59 self.cancelled = False |
61 self.cancelled = False |
60 |
62 |
61 self.__project = ericApp().getObject("Project") |
63 self.__project = ericApp().getObject("Project") |
62 self.__locale = QLocale() |
64 self.__locale = QLocale() |
63 self.__finished = True |
65 self.__finished = True |
64 self.__errorItem = None |
66 self.__errorItem = None |
65 |
67 |
66 self.__fileList = [] |
68 self.__fileList = [] |
67 self.filterFrame.setVisible(False) |
69 self.filterFrame.setVisible(False) |
68 |
70 |
69 self.explanationLabel.setText(self.tr( |
71 self.explanationLabel.setText( |
70 "<table>" |
72 self.tr( |
71 "<tr><td><b>Rank</b></td><td><b>MI Score</b></td>" |
73 "<table>" |
72 "<td><b>Maintainability</b></td></tr>" |
74 "<tr><td><b>Rank</b></td><td><b>MI Score</b></td>" |
73 "<tr><td><b>A</b></td><td>100 - 20</td><td>very high</td></tr>" |
75 "<td><b>Maintainability</b></td></tr>" |
74 "<tr><td><b>B</b></td><td>19 - 10</td><td>medium</td></tr>" |
76 "<tr><td><b>A</b></td><td>100 - 20</td><td>very high</td></tr>" |
75 "<tr><td><b>C</b></td><td>9 - 0</td><td>extremely low</td></tr>" |
77 "<tr><td><b>B</b></td><td>19 - 10</td><td>medium</td></tr>" |
76 "</table>" |
78 "<tr><td><b>C</b></td><td>9 - 0</td><td>extremely low</td></tr>" |
77 )) |
79 "</table>" |
78 |
80 ) |
|
81 ) |
|
82 |
79 try: |
83 try: |
80 usesDarkPalette = ericApp().usesDarkPalette() |
84 usesDarkPalette = ericApp().usesDarkPalette() |
81 except AttributeError: |
85 except AttributeError: |
82 from PyQt6.QtGui import QPalette |
86 from PyQt6.QtGui import QPalette |
|
87 |
83 palette = ericApp().palette() |
88 palette = ericApp().palette() |
84 lightness = palette.color(QPalette.Window).lightness() |
89 lightness = palette.color(QPalette.Window).lightness() |
85 usesDarkPalette = lightness <= 128 |
90 usesDarkPalette = lightness <= 128 |
86 if usesDarkPalette: |
91 if usesDarkPalette: |
87 self.__rankColors = { |
92 self.__rankColors = { |
93 self.__rankColors = { |
98 self.__rankColors = { |
94 "A": QColor("#00ff00"), |
99 "A": QColor("#00ff00"), |
95 "B": QColor("#ffff00"), |
100 "B": QColor("#ffff00"), |
96 "C": QColor("#ff0000"), |
101 "C": QColor("#ff0000"), |
97 } |
102 } |
98 |
103 |
99 def __resizeResultColumns(self): |
104 def __resizeResultColumns(self): |
100 """ |
105 """ |
101 Private method to resize the list columns. |
106 Private method to resize the list columns. |
102 """ |
107 """ |
103 self.resultList.header().resizeSections( |
108 self.resultList.header().resizeSections( |
104 QHeaderView.ResizeMode.ResizeMode.ResizeToContents) |
109 QHeaderView.ResizeMode.ResizeMode.ResizeToContents |
|
110 ) |
105 self.resultList.header().setStretchLastSection(True) |
111 self.resultList.header().setStretchLastSection(True) |
106 |
112 |
107 def __createResultItem(self, filename, values): |
113 def __createResultItem(self, filename, values): |
108 """ |
114 """ |
109 Private slot to create a new item in the result list. |
115 Private slot to create a new item in the result list. |
110 |
116 |
111 @param filename name of the file |
117 @param filename name of the file |
112 @type str |
118 @type str |
113 @param values values to be displayed |
119 @param values values to be displayed |
114 @type dict |
120 @type dict |
115 """ |
121 """ |
116 data = [self.__project.getRelativePath(filename)] |
122 data = [self.__project.getRelativePath(filename)] |
117 try: |
123 try: |
118 data.append("{0:>6}".format( |
124 data.append( |
119 self.__locale.toString(float(values["mi"]), "f", 2))) |
125 "{0:>6}".format(self.__locale.toString(float(values["mi"]), "f", 2)) |
|
126 ) |
120 except ValueError: |
127 except ValueError: |
121 data.append(values["mi"]) |
128 data.append(values["mi"]) |
122 data.append(values["rank"]) |
129 data.append(values["rank"]) |
123 itm = QTreeWidgetItem(self.resultList, data) |
130 itm = QTreeWidgetItem(self.resultList, data) |
124 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
131 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
125 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter) |
132 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter) |
126 if values["rank"] in self.__rankColors: |
133 if values["rank"] in self.__rankColors: |
127 itm.setBackground(2, self.__rankColors[values["rank"]]) |
134 itm.setBackground(2, self.__rankColors[values["rank"]]) |
128 itm.setData(0, self.FilePathRole, filename) |
135 itm.setData(0, self.FilePathRole, filename) |
129 |
136 |
130 if values["rank"] in self.__summary: |
137 if values["rank"] in self.__summary: |
131 self.__summary[values["rank"]] += 1 |
138 self.__summary[values["rank"]] += 1 |
132 |
139 |
133 def __createErrorItem(self, filename, message): |
140 def __createErrorItem(self, filename, message): |
134 """ |
141 """ |
135 Private slot to create a new error item in the result list. |
142 Private slot to create a new error item in the result list. |
136 |
143 |
137 @param filename name of the file |
144 @param filename name of the file |
138 @type str |
145 @type str |
139 @param message error message |
146 @param message error message |
140 @type str |
147 @type str |
141 """ |
148 """ |
142 if self.__errorItem is None: |
149 if self.__errorItem is None: |
143 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
150 self.__errorItem = QTreeWidgetItem(self.resultList, [self.tr("Errors")]) |
144 self.tr("Errors")]) |
|
145 self.__errorItem.setExpanded(True) |
151 self.__errorItem.setExpanded(True) |
146 self.__errorItem.setForeground(0, Qt.GlobalColor.red) |
152 self.__errorItem.setForeground(0, Qt.GlobalColor.red) |
147 |
153 |
148 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
154 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), message) |
149 message) |
|
150 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly): |
155 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly): |
151 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
156 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
152 itm.setForeground(0, Qt.GlobalColor.red) |
157 itm.setForeground(0, Qt.GlobalColor.red) |
153 itm.setFirstColumnSpanned(True) |
158 itm.setFirstColumnSpanned(True) |
154 |
159 |
155 def prepare(self, fileList, project): |
160 def prepare(self, fileList, project): |
156 """ |
161 """ |
157 Public method to prepare the dialog with a list of filenames. |
162 Public method to prepare the dialog with a list of filenames. |
158 |
163 |
159 @param fileList list of filenames |
164 @param fileList list of filenames |
160 @type list of str |
165 @type list of str |
161 @param project reference to the project object |
166 @param project reference to the project object |
162 @type Project |
167 @type Project |
163 """ |
168 """ |
164 self.__fileList = fileList[:] |
169 self.__fileList = fileList[:] |
165 self.__project = project |
170 self.__project = project |
166 |
171 |
167 self.buttonBox.button( |
172 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) |
168 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
173 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
169 self.buttonBox.button( |
174 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
170 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
175 |
171 self.buttonBox.button( |
|
172 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
173 |
|
174 self.filterFrame.setVisible(True) |
176 self.filterFrame.setVisible(True) |
175 |
177 |
176 self.__data = self.__project.getData( |
178 self.__data = self.__project.getData("OTHERTOOLSPARMS", "RadonCodeMetrics") |
177 "OTHERTOOLSPARMS", "RadonCodeMetrics") |
|
178 if self.__data is None or "ExcludeFiles" not in self.__data: |
179 if self.__data is None or "ExcludeFiles" not in self.__data: |
179 self.__data = {"ExcludeFiles": ""} |
180 self.__data = {"ExcludeFiles": ""} |
180 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
181 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
181 |
182 |
182 def start(self, fn): |
183 def start(self, fn): |
183 """ |
184 """ |
184 Public slot to start the maintainability index determination. |
185 Public slot to start the maintainability index determination. |
185 |
186 |
186 @param fn file or list of files or directory to show |
187 @param fn file or list of files or directory to show |
187 the maintainability index for |
188 the maintainability index for |
188 @type str or list of str |
189 @type str or list of str |
189 """ |
190 """ |
190 self.__errorItem = None |
191 self.__errorItem = None |
191 self.resultList.clear() |
192 self.resultList.clear() |
192 self.summaryLabel.clear() |
193 self.summaryLabel.clear() |
193 self.cancelled = False |
194 self.cancelled = False |
194 QApplication.processEvents() |
195 QApplication.processEvents() |
195 |
196 |
196 self.buttonBox.button( |
197 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
197 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
198 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
198 self.buttonBox.button( |
199 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
199 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
200 QApplication.processEvents() |
200 self.buttonBox.button( |
201 |
201 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
202 QApplication.processEvents() |
|
203 |
|
204 if isinstance(fn, list): |
202 if isinstance(fn, list): |
205 self.files = fn |
203 self.files = fn |
206 elif os.path.isdir(fn): |
204 elif os.path.isdir(fn): |
207 self.files = [] |
205 self.files = [] |
208 extensions = set(Preferences.getPython("Python3Extensions")) |
206 extensions = set(Preferences.getPython("Python3Extensions")) |
209 for ext in extensions: |
207 for ext in extensions: |
210 self.files.extend( |
208 self.files.extend(Utilities.direntries(fn, True, "*{0}".format(ext), 0)) |
211 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) |
|
212 else: |
209 else: |
213 self.files = [fn] |
210 self.files = [fn] |
214 self.files.sort() |
211 self.files.sort() |
215 # check for missing files |
212 # check for missing files |
216 for f in self.files[:]: |
213 for f in self.files[:]: |
217 if not os.path.exists(f): |
214 if not os.path.exists(f): |
218 self.files.remove(f) |
215 self.files.remove(f) |
219 |
216 |
220 self.__summary = { |
217 self.__summary = { |
221 "A": 0, |
218 "A": 0, |
222 "B": 0, |
219 "B": 0, |
223 "C": 0, |
220 "C": 0, |
224 } |
221 } |
225 |
222 |
226 if len(self.files) > 0: |
223 if len(self.files) > 0: |
227 # disable updates of the list for speed |
224 # disable updates of the list for speed |
228 self.resultList.setUpdatesEnabled(False) |
225 self.resultList.setUpdatesEnabled(False) |
229 self.resultList.setSortingEnabled(False) |
226 self.resultList.setSortingEnabled(False) |
230 |
227 |
231 self.checkProgress.setMaximum(len(self.files)) |
228 self.checkProgress.setMaximum(len(self.files)) |
232 self.checkProgress.setVisible(len(self.files) > 1) |
229 self.checkProgress.setVisible(len(self.files) > 1) |
233 QApplication.processEvents() |
230 QApplication.processEvents() |
234 |
231 |
235 # now go through all the files |
232 # now go through all the files |
236 self.progress = 0 |
233 self.progress = 0 |
237 if len(self.files) == 1: |
234 if len(self.files) == 1: |
238 self.__batch = False |
235 self.__batch = False |
239 self.maintainabilityIndex() |
236 self.maintainabilityIndex() |
240 else: |
237 else: |
241 self.__batch = True |
238 self.__batch = True |
242 self.maintainabilityIndexBatch() |
239 self.maintainabilityIndexBatch() |
243 |
240 |
244 def maintainabilityIndex(self, codestring=''): |
241 def maintainabilityIndex(self, codestring=""): |
245 """ |
242 """ |
246 Public method to start a maintainability index calculation for one |
243 Public method to start a maintainability index calculation for one |
247 Python file. |
244 Python file. |
248 |
245 |
249 The results are reported to the __processResult slot. |
246 The results are reported to the __processResult slot. |
250 |
247 |
251 @param codestring optional sourcestring |
248 @param codestring optional sourcestring |
252 @type str |
249 @type str |
253 """ |
250 """ |
254 if not self.files: |
251 if not self.files: |
255 self.checkProgress.setMaximum(1) |
252 self.checkProgress.setMaximum(1) |
256 self.checkProgress.setValue(1) |
253 self.checkProgress.setValue(1) |
257 self.__finish() |
254 self.__finish() |
258 return |
255 return |
259 |
256 |
260 self.filename = self.files.pop(0) |
257 self.filename = self.files.pop(0) |
261 self.checkProgress.setValue(self.progress) |
258 self.checkProgress.setValue(self.progress) |
262 QApplication.processEvents() |
259 QApplication.processEvents() |
263 |
260 |
264 if self.cancelled: |
261 if self.cancelled: |
265 return |
262 return |
266 |
263 |
267 try: |
264 try: |
268 self.source = Utilities.readEncodedFile(self.filename)[0] |
265 self.source = Utilities.readEncodedFile(self.filename)[0] |
269 self.source = Utilities.normalizeCode(self.source) |
266 self.source = Utilities.normalizeCode(self.source) |
270 except (UnicodeError, OSError) as msg: |
267 except (UnicodeError, OSError) as msg: |
271 self.__createErrorItem(self.filename, str(msg).rstrip()) |
268 self.__createErrorItem(self.filename, str(msg).rstrip()) |
273 # Continue with next file |
270 # Continue with next file |
274 self.maintainabilityIndex() |
271 self.maintainabilityIndex() |
275 return |
272 return |
276 |
273 |
277 self.__finished = False |
274 self.__finished = False |
278 self.radonService.maintainabilityIndex( |
275 self.radonService.maintainabilityIndex(None, self.filename, self.source) |
279 None, self.filename, self.source) |
|
280 |
276 |
281 def maintainabilityIndexBatch(self): |
277 def maintainabilityIndexBatch(self): |
282 """ |
278 """ |
283 Public method to start a maintainability index calculation batch job. |
279 Public method to start a maintainability index calculation batch job. |
284 |
280 |
285 The results are reported to the __processResult slot. |
281 The results are reported to the __processResult slot. |
286 """ |
282 """ |
287 self.__lastFileItem = None |
283 self.__lastFileItem = None |
288 |
284 |
289 argumentsList = [] |
285 argumentsList = [] |
290 for progress, filename in enumerate(self.files, start=1): |
286 for progress, filename in enumerate(self.files, start=1): |
291 self.checkProgress.setValue(progress) |
287 self.checkProgress.setValue(progress) |
292 QApplication.processEvents() |
288 QApplication.processEvents() |
293 |
289 |
294 try: |
290 try: |
295 source = Utilities.readEncodedFile(filename)[0] |
291 source = Utilities.readEncodedFile(filename)[0] |
296 source = Utilities.normalizeCode(source) |
292 source = Utilities.normalizeCode(source) |
297 except (UnicodeError, OSError) as msg: |
293 except (UnicodeError, OSError) as msg: |
298 self.__createErrorItem(filename, str(msg).rstrip()) |
294 self.__createErrorItem(filename, str(msg).rstrip()) |
299 continue |
295 continue |
300 |
296 |
301 argumentsList.append((filename, source)) |
297 argumentsList.append((filename, source)) |
302 |
298 |
303 # reset the progress bar to the checked files |
299 # reset the progress bar to the checked files |
304 self.checkProgress.setValue(self.progress) |
300 self.checkProgress.setValue(self.progress) |
305 QApplication.processEvents() |
301 QApplication.processEvents() |
306 |
302 |
307 self.__finished = False |
303 self.__finished = False |
308 self.radonService.maintainabilityIndexBatch(argumentsList) |
304 self.radonService.maintainabilityIndexBatch(argumentsList) |
309 |
305 |
310 def __batchFinished(self, type_): |
306 def __batchFinished(self, type_): |
311 """ |
307 """ |
312 Private slot handling the completion of a batch job. |
308 Private slot handling the completion of a batch job. |
313 |
309 |
314 @param type_ type of the calculated metrics |
310 @param type_ type of the calculated metrics |
315 @type str, one of ["raw", "mi", "cc"] |
311 @type str, one of ["raw", "mi", "cc"] |
316 """ |
312 """ |
317 if type_ == "mi": |
313 if type_ == "mi": |
318 self.checkProgress.setMaximum(1) |
314 self.checkProgress.setMaximum(1) |
319 self.checkProgress.setValue(1) |
315 self.checkProgress.setValue(1) |
320 self.__finish() |
316 self.__finish() |
321 |
317 |
322 def __processError(self, type_, fn, msg): |
318 def __processError(self, type_, fn, msg): |
323 """ |
319 """ |
324 Private slot to process an error indication from the service. |
320 Private slot to process an error indication from the service. |
325 |
321 |
326 @param type_ type of the calculated metrics |
322 @param type_ type of the calculated metrics |
327 @type str, one of ["raw", "mi", "cc"] |
323 @type str, one of ["raw", "mi", "cc"] |
328 @param fn filename of the file |
324 @param fn filename of the file |
329 @type str |
325 @type str |
330 @param msg error message |
326 @param msg error message |
331 @type str |
327 @type str |
332 """ |
328 """ |
333 if type_ == "mi": |
329 if type_ == "mi": |
334 self.__createErrorItem(fn, msg) |
330 self.__createErrorItem(fn, msg) |
335 |
331 |
336 def __processResult(self, fn, result): |
332 def __processResult(self, fn, result): |
337 """ |
333 """ |
338 Private slot called after perfoming a maintainability index calculation |
334 Private slot called after perfoming a maintainability index calculation |
339 on one file. |
335 on one file. |
340 |
336 |
341 @param fn filename of the file |
337 @param fn filename of the file |
342 @type str |
338 @type str |
343 @param result result dict |
339 @param result result dict |
344 @type dict |
340 @type dict |
345 """ |
341 """ |
346 if self.__finished: |
342 if self.__finished: |
347 return |
343 return |
348 |
344 |
349 # Check if it's the requested file, otherwise ignore signal if not |
345 # Check if it's the requested file, otherwise ignore signal if not |
350 # in batch mode |
346 # in batch mode |
351 if not self.__batch and fn != self.filename: |
347 if not self.__batch and fn != self.filename: |
352 return |
348 return |
353 |
349 |
354 QApplication.processEvents() |
350 QApplication.processEvents() |
355 |
351 |
356 if "error" in result: |
352 if "error" in result: |
357 self.__createErrorItem(fn, result["error"]) |
353 self.__createErrorItem(fn, result["error"]) |
358 else: |
354 else: |
359 self.__createResultItem(fn, result) |
355 self.__createResultItem(fn, result) |
360 |
356 |
361 self.progress += 1 |
357 self.progress += 1 |
362 |
358 |
363 self.checkProgress.setValue(self.progress) |
359 self.checkProgress.setValue(self.progress) |
364 QApplication.processEvents() |
360 QApplication.processEvents() |
365 |
361 |
366 if not self.__batch: |
362 if not self.__batch: |
367 self.maintainabilityIndex() |
363 self.maintainabilityIndex() |
368 |
364 |
369 def __finish(self): |
365 def __finish(self): |
370 """ |
366 """ |
371 Private slot called when the action or the user pressed the button. |
367 Private slot called when the action or the user pressed the button. |
372 """ |
368 """ |
373 if not self.__finished: |
369 if not self.__finished: |
374 self.__finished = True |
370 self.__finished = True |
375 |
371 |
376 # reenable updates of the list |
372 # reenable updates of the list |
377 self.resultList.setSortingEnabled(True) |
373 self.resultList.setSortingEnabled(True) |
378 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
374 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
379 self.resultList.setUpdatesEnabled(True) |
375 self.resultList.setUpdatesEnabled(True) |
380 |
376 |
381 self.cancelled = True |
377 self.cancelled = True |
382 self.buttonBox.button( |
378 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( |
383 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
379 True |
384 self.buttonBox.button( |
380 ) |
385 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
381 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled( |
386 self.buttonBox.button( |
382 False |
387 QDialogButtonBox.StandardButton.Close).setDefault(True) |
383 ) |
388 |
384 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault( |
|
385 True |
|
386 ) |
|
387 |
389 self.resultList.header().resizeSections( |
388 self.resultList.header().resizeSections( |
390 QHeaderView.ResizeMode.ResizeToContents) |
389 QHeaderView.ResizeMode.ResizeToContents |
|
390 ) |
391 self.resultList.header().setStretchLastSection(True) |
391 self.resultList.header().setStretchLastSection(True) |
392 self.resultList.header().setSectionResizeMode( |
392 self.resultList.header().setSectionResizeMode( |
393 QHeaderView.ResizeMode.Interactive) |
393 QHeaderView.ResizeMode.Interactive |
394 |
394 ) |
395 self.summaryLabel.setText(self.tr( |
395 |
396 "<table>" |
396 self.summaryLabel.setText( |
397 "<tr><td colspan=2><b>Summary:</b></td></tr>" |
397 self.tr( |
398 "<tr><td><b>A</b></td><td align='right'>{0} files</td></tr>" |
398 "<table>" |
399 "<tr><td><b>B</b></td><td align='right'>{1} files</td></tr>" |
399 "<tr><td colspan=2><b>Summary:</b></td></tr>" |
400 "<tr><td><b>C</b></td><td align='right'>{2} files</td></tr>" |
400 "<tr><td><b>A</b></td><td align='right'>{0} files</td></tr>" |
401 "</table>" |
401 "<tr><td><b>B</b></td><td align='right'>{1} files</td></tr>" |
402 ).format(self.__locale.toString(self.__summary["A"]), |
402 "<tr><td><b>C</b></td><td align='right'>{2} files</td></tr>" |
403 self.__locale.toString(self.__summary["B"]), |
403 "</table>" |
404 self.__locale.toString(self.__summary["C"])) |
404 ).format( |
405 ) |
405 self.__locale.toString(self.__summary["A"]), |
406 |
406 self.__locale.toString(self.__summary["B"]), |
|
407 self.__locale.toString(self.__summary["C"]), |
|
408 ) |
|
409 ) |
|
410 |
407 self.checkProgress.setVisible(False) |
411 self.checkProgress.setVisible(False) |
408 |
412 |
409 @pyqtSlot(QAbstractButton) |
413 @pyqtSlot(QAbstractButton) |
410 def on_buttonBox_clicked(self, button): |
414 def on_buttonBox_clicked(self, button): |
411 """ |
415 """ |
412 Private slot called by a button of the button box clicked. |
416 Private slot called by a button of the button box clicked. |
413 |
417 |
414 @param button button that was clicked |
418 @param button button that was clicked |
415 @type QAbstractButton |
419 @type QAbstractButton |
416 """ |
420 """ |
417 if button == self.buttonBox.button( |
421 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
418 QDialogButtonBox.StandardButton.Close |
|
419 ): |
|
420 self.close() |
422 self.close() |
421 elif button == self.buttonBox.button( |
423 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
422 QDialogButtonBox.StandardButton.Cancel |
|
423 ): |
|
424 if self.__batch: |
424 if self.__batch: |
425 self.radonService.cancelMaintainabilityIndexBatch() |
425 self.radonService.cancelMaintainabilityIndexBatch() |
426 QTimer.singleShot(1000, self.__finish) |
426 QTimer.singleShot(1000, self.__finish) |
427 else: |
427 else: |
428 self.__finish() |
428 self.__finish() |
429 |
429 |
430 @pyqtSlot() |
430 @pyqtSlot() |
431 def on_startButton_clicked(self): |
431 def on_startButton_clicked(self): |
432 """ |
432 """ |
433 Private slot to start a maintainability index run. |
433 Private slot to start a maintainability index run. |
434 """ |
434 """ |
435 fileList = self.__fileList[:] |
435 fileList = self.__fileList[:] |
436 |
436 |
437 filterString = self.excludeFilesEdit.text() |
437 filterString = self.excludeFilesEdit.text() |
438 if ( |
438 if ( |
439 "ExcludeFiles" not in self.__data or |
439 "ExcludeFiles" not in self.__data |
440 filterString != self.__data["ExcludeFiles"] |
440 or filterString != self.__data["ExcludeFiles"] |
441 ): |
441 ): |
442 self.__data["ExcludeFiles"] = filterString |
442 self.__data["ExcludeFiles"] = filterString |
443 self.__project.setData( |
443 self.__project.setData("OTHERTOOLSPARMS", "RadonCodeMetrics", self.__data) |
444 "OTHERTOOLSPARMS", "RadonCodeMetrics", self.__data) |
444 filterList = [f.strip() for f in filterString.split(",") if f.strip()] |
445 filterList = [f.strip() for f in filterString.split(",") |
|
446 if f.strip()] |
|
447 if filterList: |
445 if filterList: |
448 for fileFilter in filterList: |
446 for fileFilter in filterList: |
449 fileList = [f for f in fileList |
447 fileList = [f for f in fileList if not fnmatch.fnmatch(f, fileFilter)] |
450 if not fnmatch.fnmatch(f, fileFilter)] |
448 |
451 |
|
452 self.start(fileList) |
449 self.start(fileList) |
453 |
450 |
454 def clear(self): |
451 def clear(self): |
455 """ |
452 """ |
456 Public method to clear all results. |
453 Public method to clear all results. |
457 """ |
454 """ |
458 self.resultList.clear() |
455 self.resultList.clear() |
459 self.summaryLabel.clear() |
456 self.summaryLabel.clear() |
460 |
457 |
461 @pyqtSlot(QTreeWidgetItem, int) |
458 @pyqtSlot(QTreeWidgetItem, int) |
462 def on_resultList_itemActivated(self, item, column): |
459 def on_resultList_itemActivated(self, item, column): |
463 """ |
460 """ |
464 Private slot to handle the activation of a result item. |
461 Private slot to handle the activation of a result item. |
465 |
462 |
466 @param item reference to the activated item |
463 @param item reference to the activated item |
467 @type QTreeWidgetItem |
464 @type QTreeWidgetItem |
468 @param column activated column |
465 @param column activated column |
469 @type int |
466 @type int |
470 """ |
467 """ |