diff -r 38e8903f9c2f -r f542ad1f76c5 Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py --- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Tue Apr 14 19:51:10 2015 +0200 +++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Thu Apr 16 19:58:27 2015 +0200 @@ -28,6 +28,7 @@ from . import pep8 +# TODO: implement CANCEL for batch jobs (if possible) class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): """ Class implementing a dialog to show the results of the code style check. @@ -85,11 +86,13 @@ self.styleCheckService = styleCheckService self.styleCheckService.styleChecked.connect(self.__processResult) + self.styleCheckService.batchFinished.connect(self.__batchFinished) self.filename = None self.noResults = True self.cancelled = False self.__lastFileItem = None + self.__finished = True self.__fileOrFileList = "" self.__project = None @@ -365,7 +368,12 @@ # now go through all the files self.progress = 0 self.files.sort() - self.check() + if len(self.files) == 1: + self.__batch = False + self.check() + else: + self.__batch = True + self.checkBatch() def check(self, codestring=''): """ @@ -425,9 +433,75 @@ args = self.__options + [ errors, eol, encoding, Preferences.getEditor("CreateBackupFile") ] + self.__finished = False self.styleCheckService.styleCheck( None, self.filename, source, args) - + + def checkBatch(self): + """ + Public method to start a style check batch job. + + The results are reported to the __processResult slot. + """ + self.__lastFileItem = None + + # Cancel doesn't work for batch jobs + self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) + + self.checkProgressLabel.setPath(self.tr("Preparing files...")) + progress = 0 + + argumentsList = [] + for filename in self.files: + progress += 1 + self.checkProgress.setValue(progress) + QApplication.processEvents() + + try: + source, encoding = Utilities.readEncodedFile( + filename) + source = source.splitlines(True) + except (UnicodeError, IOError) as msg: + self.noResults = False + self.__createResultItem( + filename, 1, 1, + self.tr("Error: {0}").format(str(msg)) + .rstrip(), False, False, False) + continue + + if encoding.endswith( + ('-selected', '-default', '-guessed', '-ignore')): + encoding = encoding.rsplit('-', 1)[0] + + errors = [] + self.__itms = [] + for error, itm in self.__onlyFixes.pop(filename, []): + errors.append(error) + self.__itms.append(itm) + + eol = self.__getEol(filename) + args = self.__options + [ + errors, eol, encoding, + Preferences.getEditor("CreateBackupFile") + ] + argumentsList.append((filename, source, args)) + + # reset the progress bar to the checked files + self.checkProgress.setValue(self.progress) + QApplication.processEvents() + + self.__finished = False + self.styleCheckService.styleBatchCheck(argumentsList) + + def __batchFinished(self): + """ + Private slot handling the completion of a batch job. + """ + self.checkProgressLabel.setPath("") + self.checkProgress.setMaximum(1) + self.checkProgress.setValue(1) + self.__finish() + def __processResult(self, fn, codeStyleCheckerStats, fixes, results): """ Private slot called after perfoming a style check on one file. @@ -439,8 +513,12 @@ lineno (int), position (int), text (str), ignored (bool), fixed (bool), autofixing (bool)) """ - # Check if it's the requested file, otherwise ignore signal - if fn != self.filename: + if self.__finished: + return + + # Check if it's the requested file, otherwise ignore signal if not + # in batch mode + if not self.__batch and fn != self.filename: return # disable updates of the list for speed @@ -455,6 +533,8 @@ self.__modifyFixedResultItem(itm, text, fixed) self.__updateFixerStatistics(fixes) else: + self.__lastFileItem = None + for lineno, position, text, ignored, fixed, autofixing in results: if ignored: ignoredErrors += 1 @@ -483,15 +563,19 @@ self.resultList.setUpdatesEnabled(True) self.checkProgress.setValue(self.progress) + self.checkProgressLabel.setPath(fn) QApplication.processEvents() - self.check() + if not self.__batch: + self.check() def __finish(self): """ Private slot called when the code style check finished or the user pressed the cancel button. """ + self.__finished = True + self.cancelled = True self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)