--- a/RadonMetrics/MaintainabilityIndexDialog.py Sat Dec 31 16:27:44 2022 +0100 +++ b/RadonMetrics/MaintainabilityIndexDialog.py Sat May 27 15:33:58 2023 +0200 @@ -63,6 +63,7 @@ self.radonService.error.connect(self.__processError) self.radonService.batchFinished.connect(self.__batchFinished) + self.__batch = False self.cancelled = False self.__project = ericApp().getObject("Project") @@ -226,8 +227,6 @@ } if len(self.files) > 0: - # disable updates of the list for speed - self.resultList.setUpdatesEnabled(False) self.resultList.setSortingEnabled(False) self.checkProgress.setMaximum(len(self.files)) @@ -243,15 +242,12 @@ self.__batch = True self.maintainabilityIndexBatch() - def maintainabilityIndex(self, codestring=""): + def maintainabilityIndex(self): """ Public method to start a maintainability index calculation for one Python file. The results are reported to the __processResult slot. - - @param codestring optional sourcestring - @type str """ if not self.files: self.checkProgress.setMaximum(1) @@ -261,7 +257,6 @@ self.filename = self.files.pop(0) self.checkProgress.setValue(self.progress) - QApplication.processEvents() if self.cancelled: return @@ -290,7 +285,6 @@ argumentsList = [] for progress, filename in enumerate(self.files, start=1): self.checkProgress.setValue(progress) - QApplication.processEvents() try: source = Utilities.readEncodedFile(filename)[0] @@ -303,7 +297,6 @@ # reset the progress bar to the checked files self.checkProgress.setValue(self.progress) - QApplication.processEvents() self.__finished = False self.radonService.maintainabilityIndexBatch(argumentsList) @@ -360,9 +353,7 @@ self.__createResultItem(fn, result) self.progress += 1 - self.checkProgress.setValue(self.progress) - QApplication.processEvents() if not self.__batch: self.maintainabilityIndex() @@ -374,10 +365,8 @@ if not self.__finished: self.__finished = True - # reenable updates of the list self.resultList.setSortingEnabled(True) self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) - self.resultList.setUpdatesEnabled(True) self.cancelled = True self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( @@ -415,6 +404,25 @@ self.checkProgress.setVisible(False) + def __cancel(self): + """ + Private method to cancel the current check run. + """ + if self.__batch: + self.radonService.cancelMaintainabilityIndexBatch() + QTimer.singleShot(1000, self.__finish) + else: + self.__finish() + + def closeEvent(self, evt): + """ + Protected method to handle a close event. + + @param evt reference to the close event + @type QCloseEvent + """ + self.__cancel() + @pyqtSlot(QAbstractButton) def on_buttonBox_clicked(self, button): """ @@ -426,11 +434,7 @@ if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): self.close() elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): - if self.__batch: - self.radonService.cancelMaintainabilityIndexBatch() - QTimer.singleShot(1000, self.__finish) - else: - self.__finish() + self.__cancel() @pyqtSlot() def on_startButton_clicked(self):