diff -r 6422943b388f -r 0843dd7239f6 RadonMetrics/RawMetricsDialog.py --- a/RadonMetrics/RawMetricsDialog.py Sat Dec 31 16:27:44 2022 +0100 +++ b/RadonMetrics/RawMetricsDialog.py Sat May 27 15:33:58 2023 +0200 @@ -66,6 +66,7 @@ self.radonService.error.connect(self.__processError) self.radonService.batchFinished.connect(self.__batchFinished) + self.__batch = False self.cancelled = False self.__project = ericApp().getObject("Project") @@ -235,8 +236,6 @@ self.__summary[key] = 0 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)) @@ -252,14 +251,11 @@ self.__batch = True self.rawMetricsBatch() - def rawMetrics(self, codestring=""): + def rawMetrics(self): """ Public method to start a code metrics 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) @@ -269,7 +265,6 @@ self.filename = self.files.pop(0) self.checkProgress.setValue(self.progress) - QApplication.processEvents() if self.cancelled: return @@ -298,7 +293,6 @@ argumentsList = [] for progress, filename in enumerate(self.files, start=1): self.checkProgress.setValue(progress) - QApplication.processEvents() try: source = Utilities.readEncodedFile(filename)[0] @@ -311,7 +305,6 @@ # reset the progress bar to the checked files self.checkProgress.setValue(self.progress) - QApplication.processEvents() self.__finished = False self.radonService.rawMetricsBatch(argumentsList) @@ -368,9 +361,7 @@ self.__createResultItem(fn, result) self.progress += 1 - self.checkProgress.setValue(self.progress) - QApplication.processEvents() if not self.__batch: self.rawMetrics() @@ -410,10 +401,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.__createSummary() @@ -512,6 +501,25 @@ itm = QTreeWidgetItem(self.summaryList, [col0, col1]) itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) + def __cancel(self): + """ + Private method to cancel the current check run. + """ + if self.__batch: + self.radonService.cancelRawMetricsBatch() + 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): """ @@ -523,11 +531,7 @@ if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): self.close() elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): - if self.__batch: - self.radonService.cancelRawMetricsBatch() - QTimer.singleShot(1000, self.__finish) - else: - self.__finish() + self.__cancel() @pyqtSlot() def on_startButton_clicked(self):