61 self.radonService = radonService |
61 self.radonService = radonService |
62 self.radonService.maintainabilityIndexDone.connect(self.__processResult) |
62 self.radonService.maintainabilityIndexDone.connect(self.__processResult) |
63 self.radonService.error.connect(self.__processError) |
63 self.radonService.error.connect(self.__processError) |
64 self.radonService.batchFinished.connect(self.__batchFinished) |
64 self.radonService.batchFinished.connect(self.__batchFinished) |
65 |
65 |
|
66 self.__batch = False |
66 self.cancelled = False |
67 self.cancelled = False |
67 |
68 |
68 self.__project = ericApp().getObject("Project") |
69 self.__project = ericApp().getObject("Project") |
69 self.__locale = QLocale() |
70 self.__locale = QLocale() |
70 self.__finished = True |
71 self.__finished = True |
224 "B": 0, |
225 "B": 0, |
225 "C": 0, |
226 "C": 0, |
226 } |
227 } |
227 |
228 |
228 if len(self.files) > 0: |
229 if len(self.files) > 0: |
229 # disable updates of the list for speed |
|
230 self.resultList.setUpdatesEnabled(False) |
|
231 self.resultList.setSortingEnabled(False) |
230 self.resultList.setSortingEnabled(False) |
232 |
231 |
233 self.checkProgress.setMaximum(len(self.files)) |
232 self.checkProgress.setMaximum(len(self.files)) |
234 self.checkProgress.setVisible(len(self.files) > 1) |
233 self.checkProgress.setVisible(len(self.files) > 1) |
235 QApplication.processEvents() |
234 QApplication.processEvents() |
241 self.maintainabilityIndex() |
240 self.maintainabilityIndex() |
242 else: |
241 else: |
243 self.__batch = True |
242 self.__batch = True |
244 self.maintainabilityIndexBatch() |
243 self.maintainabilityIndexBatch() |
245 |
244 |
246 def maintainabilityIndex(self, codestring=""): |
245 def maintainabilityIndex(self): |
247 """ |
246 """ |
248 Public method to start a maintainability index calculation for one |
247 Public method to start a maintainability index calculation for one |
249 Python file. |
248 Python file. |
250 |
249 |
251 The results are reported to the __processResult slot. |
250 The results are reported to the __processResult slot. |
252 |
|
253 @param codestring optional sourcestring |
|
254 @type str |
|
255 """ |
251 """ |
256 if not self.files: |
252 if not self.files: |
257 self.checkProgress.setMaximum(1) |
253 self.checkProgress.setMaximum(1) |
258 self.checkProgress.setValue(1) |
254 self.checkProgress.setValue(1) |
259 self.__finish() |
255 self.__finish() |
260 return |
256 return |
261 |
257 |
262 self.filename = self.files.pop(0) |
258 self.filename = self.files.pop(0) |
263 self.checkProgress.setValue(self.progress) |
259 self.checkProgress.setValue(self.progress) |
264 QApplication.processEvents() |
|
265 |
260 |
266 if self.cancelled: |
261 if self.cancelled: |
267 return |
262 return |
268 |
263 |
269 try: |
264 try: |
288 self.__lastFileItem = None |
283 self.__lastFileItem = None |
289 |
284 |
290 argumentsList = [] |
285 argumentsList = [] |
291 for progress, filename in enumerate(self.files, start=1): |
286 for progress, filename in enumerate(self.files, start=1): |
292 self.checkProgress.setValue(progress) |
287 self.checkProgress.setValue(progress) |
293 QApplication.processEvents() |
|
294 |
288 |
295 try: |
289 try: |
296 source = Utilities.readEncodedFile(filename)[0] |
290 source = Utilities.readEncodedFile(filename)[0] |
297 source = Utilities.normalizeCode(source) |
291 source = Utilities.normalizeCode(source) |
298 except (UnicodeError, OSError) as msg: |
292 except (UnicodeError, OSError) as msg: |
301 |
295 |
302 argumentsList.append((filename, source)) |
296 argumentsList.append((filename, source)) |
303 |
297 |
304 # reset the progress bar to the checked files |
298 # reset the progress bar to the checked files |
305 self.checkProgress.setValue(self.progress) |
299 self.checkProgress.setValue(self.progress) |
306 QApplication.processEvents() |
|
307 |
300 |
308 self.__finished = False |
301 self.__finished = False |
309 self.radonService.maintainabilityIndexBatch(argumentsList) |
302 self.radonService.maintainabilityIndexBatch(argumentsList) |
310 |
303 |
311 def __batchFinished(self, type_): |
304 def __batchFinished(self, type_): |
358 self.__createErrorItem(fn, result["error"]) |
351 self.__createErrorItem(fn, result["error"]) |
359 else: |
352 else: |
360 self.__createResultItem(fn, result) |
353 self.__createResultItem(fn, result) |
361 |
354 |
362 self.progress += 1 |
355 self.progress += 1 |
363 |
|
364 self.checkProgress.setValue(self.progress) |
356 self.checkProgress.setValue(self.progress) |
365 QApplication.processEvents() |
|
366 |
357 |
367 if not self.__batch: |
358 if not self.__batch: |
368 self.maintainabilityIndex() |
359 self.maintainabilityIndex() |
369 |
360 |
370 def __finish(self): |
361 def __finish(self): |
372 Private slot called when the action or the user pressed the button. |
363 Private slot called when the action or the user pressed the button. |
373 """ |
364 """ |
374 if not self.__finished: |
365 if not self.__finished: |
375 self.__finished = True |
366 self.__finished = True |
376 |
367 |
377 # reenable updates of the list |
|
378 self.resultList.setSortingEnabled(True) |
368 self.resultList.setSortingEnabled(True) |
379 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
369 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) |
380 self.resultList.setUpdatesEnabled(True) |
|
381 |
370 |
382 self.cancelled = True |
371 self.cancelled = True |
383 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( |
372 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( |
384 True |
373 True |
385 ) |
374 ) |
413 ) |
402 ) |
414 ) |
403 ) |
415 |
404 |
416 self.checkProgress.setVisible(False) |
405 self.checkProgress.setVisible(False) |
417 |
406 |
|
407 def __cancel(self): |
|
408 """ |
|
409 Private method to cancel the current check run. |
|
410 """ |
|
411 if self.__batch: |
|
412 self.radonService.cancelMaintainabilityIndexBatch() |
|
413 QTimer.singleShot(1000, self.__finish) |
|
414 else: |
|
415 self.__finish() |
|
416 |
|
417 def closeEvent(self, evt): |
|
418 """ |
|
419 Protected method to handle a close event. |
|
420 |
|
421 @param evt reference to the close event |
|
422 @type QCloseEvent |
|
423 """ |
|
424 self.__cancel() |
|
425 |
418 @pyqtSlot(QAbstractButton) |
426 @pyqtSlot(QAbstractButton) |
419 def on_buttonBox_clicked(self, button): |
427 def on_buttonBox_clicked(self, button): |
420 """ |
428 """ |
421 Private slot called by a button of the button box clicked. |
429 Private slot called by a button of the button box clicked. |
422 |
430 |
424 @type QAbstractButton |
432 @type QAbstractButton |
425 """ |
433 """ |
426 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
434 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
427 self.close() |
435 self.close() |
428 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
436 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
429 if self.__batch: |
437 self.__cancel() |
430 self.radonService.cancelMaintainabilityIndexBatch() |
|
431 QTimer.singleShot(1000, self.__finish) |
|
432 else: |
|
433 self.__finish() |
|
434 |
438 |
435 @pyqtSlot() |
439 @pyqtSlot() |
436 def on_startButton_clicked(self): |
440 def on_startButton_clicked(self): |
437 """ |
441 """ |
438 Private slot to start a maintainability index run. |
442 Private slot to start a maintainability index run. |