--- a/RadonMetrics/CyclomaticComplexityDialog.py Sat Dec 31 16:27:44 2022 +0100 +++ b/RadonMetrics/CyclomaticComplexityDialog.py Sat May 27 15:33:58 2023 +0200 @@ -74,6 +74,7 @@ self.radonService.batchFinished.connect(self.__batchFinished) self.__isSingle = isSingle + self.__batch = False self.cancelled = False self.__project = ericApp().getObject("Project") @@ -84,10 +85,11 @@ self.__fileList = [] self.filterFrame.setVisible(False) + self.summaryHeader.setText(self.tr("<b>Summary:</b>")) + self.explanationHeader.setText(self.tr("<b>Ranking:</b>")) self.explanationLabel.setText( self.tr( "<table>" - "<tr><td colspan=3><b>Ranking:</b></td></tr>" "<tr><td><b>A</b></td><td>1 - 5</td>" "<td>(low risk - simple block)</td></tr>" "<tr><td><b>B</b></td><td>6 - 10</td>" @@ -103,10 +105,10 @@ "</table>" ) ) + self.typeHeader.setText(self.tr("<b>Type:</b>")) self.typeLabel.setText( self.tr( "<table>" - "<tr><td colspan=2><b>Type:</b></td></tr>" "<tr><td><b>C</b></td><td>Class</td></tr>" "<tr><td><b>F</b></td><td>Function</td></tr>" "<tr><td><b>M</b></td><td>Method</td></tr>" @@ -271,15 +273,13 @@ self.rankComboBox.findText(self.__minimumRank) ) - def start(self, fn, minRank="D"): + def start(self, fn): """ Public slot to start the cyclomatic complexity determination. @param fn file or list of files or directory to show the cyclomatic complexity for @type str or list of str - @param minRank minimum rank of entries to be shown - @type str (one character out of A - F) """ self.cancelled = False self.__errorItem = None @@ -324,8 +324,6 @@ self.__minimumRank = self.rankComboBox.currentText() 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)) @@ -341,15 +339,12 @@ self.__batch = True self.cyclomaticComplexityBatch() - def cyclomaticComplexity(self, codestring=""): + def cyclomaticComplexity(self): """ Public method to start a cyclomatic complexity 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) @@ -359,7 +354,6 @@ self.filename = self.files.pop(0) self.checkProgress.setValue(self.progress) - QApplication.processEvents() if self.cancelled: return @@ -388,7 +382,6 @@ argumentsList = [] for progress, filename in enumerate(self.files, start=1): self.checkProgress.setValue(progress) - QApplication.processEvents() try: source = Utilities.readEncodedFile(filename)[0] @@ -401,7 +394,6 @@ # reset the progress bar to the checked files self.checkProgress.setValue(self.progress) - QApplication.processEvents() self.__finished = False self.radonService.cyclomaticComplexityBatch(argumentsList) @@ -470,9 +462,7 @@ self.__summary[rank] += result["summary"][rank] self.progress += 1 - self.checkProgress.setValue(self.progress) - QApplication.processEvents() if not self.__batch: self.cyclomaticComplexity() @@ -486,11 +476,9 @@ if not self.__finished: self.__finished = True - # re-enable updates of the list self.resultList.setSortingEnabled(True) self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) self.resultList.sortItems(1, Qt.SortOrder.AscendingOrder) - self.resultList.setUpdatesEnabled(True) self.cancelled = True self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( @@ -516,7 +504,6 @@ self.summaryLabel.setText( self.tr( - "<b>Summary:</b><br/>" "{0} blocks (classes, functions, methods) analyzed.<br/>" "Average complexity: {7} ({8})" "<table>" @@ -548,6 +535,25 @@ self.checkProgress.setVisible(False) + def __cancel(self): + """ + Private method to cancel the current check run. + """ + if self.__batch: + self.radonService.cancelComplexityBatch() + 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): """ @@ -559,11 +565,7 @@ if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): self.close() elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): - if self.__batch: - self.radonService.cancelComplexityBatch() - QTimer.singleShot(1000, self.__finish) - else: - self.__finish() + self.__cancel() @pyqtSlot() def on_startButton_clicked(self): @@ -644,12 +646,12 @@ vm = ericApp().getObject("ViewManager") vm.openSourceFile(filename, lineno) - @pyqtSlot(str) - def on_rankComboBox_activated(self, rank): + @pyqtSlot(int) + def on_rankComboBox_activated(self, index): """ Private slot to handle the selection of a minimum rank. - @param rank selected minimum rank + @param index index of the selected minimum rank @type str """ if self.__isSingle: