29 |
29 |
30 try: |
30 try: |
31 basestring # __IGNORE_WARNING__ |
31 basestring # __IGNORE_WARNING__ |
32 except Exception: |
32 except Exception: |
33 basestring = str # define for Python3 |
33 basestring = str # define for Python3 |
34 |
|
35 NO_RESULTS = 0 |
|
36 NO_FILES = 1 |
|
37 HAS_RESULTS = 2 |
|
38 |
34 |
39 |
35 |
40 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
36 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
41 """ |
37 """ |
42 Class implementing a dialog to show the results of the code style check. |
38 Class implementing a dialog to show the results of the code style check. |
50 ignoredRole = Qt.UserRole + 7 |
46 ignoredRole = Qt.UserRole + 7 |
51 |
47 |
52 availableFutures = [ |
48 availableFutures = [ |
53 'division', 'absolute_import', 'with_statement', |
49 'division', 'absolute_import', 'with_statement', |
54 'print_function', 'unicode_literals', 'generator_stop'] |
50 'print_function', 'unicode_literals', 'generator_stop'] |
|
51 |
|
52 noResults = 0 |
|
53 noFiles = 1 |
|
54 hasResults = 2 |
55 |
55 |
56 def __init__(self, styleCheckService, parent=None): |
56 def __init__(self, styleCheckService, parent=None): |
57 """ |
57 """ |
58 Constructor |
58 Constructor |
59 |
59 |
103 self.styleCheckService.styleChecked.connect(self.__processResult) |
103 self.styleCheckService.styleChecked.connect(self.__processResult) |
104 self.styleCheckService.batchFinished.connect(self.__batchFinished) |
104 self.styleCheckService.batchFinished.connect(self.__batchFinished) |
105 self.styleCheckService.error.connect(self.__processError) |
105 self.styleCheckService.error.connect(self.__processError) |
106 self.filename = None |
106 self.filename = None |
107 |
107 |
108 self.results = NO_RESULTS |
108 self.results = CodeStyleCheckerDialog.noResults |
109 self.cancelled = False |
109 self.cancelled = False |
110 self.__lastFileItem = None |
110 self.__lastFileItem = None |
111 self.__batch = False |
111 self.__batch = False |
112 self.__finished = True |
112 self.__finished = True |
113 self.__errorItem = None |
113 self.__errorItem = None |
506 try: |
506 try: |
507 source, encoding = Utilities.readEncodedFile( |
507 source, encoding = Utilities.readEncodedFile( |
508 self.filename) |
508 self.filename) |
509 source = source.splitlines(True) |
509 source = source.splitlines(True) |
510 except (UnicodeError, IOError) as msg: |
510 except (UnicodeError, IOError) as msg: |
511 self.results = HAS_RESULTS |
511 self.results = CodeStyleCheckerDialog.hasResults |
512 self.__createResultItem( |
512 self.__createResultItem( |
513 self.filename, 1, 1, |
513 self.filename, 1, 1, |
514 self.tr("Error: {0}").format(str(msg)) |
514 self.tr("Error: {0}").format(str(msg)) |
515 .rstrip(), False, False, False) |
515 .rstrip(), False, False, False) |
516 self.progress += 1 |
516 self.progress += 1 |
557 try: |
557 try: |
558 source, encoding = Utilities.readEncodedFile( |
558 source, encoding = Utilities.readEncodedFile( |
559 filename) |
559 filename) |
560 source = source.splitlines(True) |
560 source = source.splitlines(True) |
561 except (UnicodeError, IOError) as msg: |
561 except (UnicodeError, IOError) as msg: |
562 self.results = HAS_RESULTS |
562 self.results = CodeStyleCheckerDialog.hasResults |
563 self.__createResultItem( |
563 self.__createResultItem( |
564 filename, 1, 1, |
564 filename, 1, 1, |
565 self.tr("Error: {0}").format(str(msg)) |
565 self.tr("Error: {0}").format(str(msg)) |
566 .rstrip(), False, False, False) |
566 .rstrip(), False, False, False) |
567 continue |
567 continue |
654 ignoredErrors += 1 |
654 ignoredErrors += 1 |
655 if self.showIgnored: |
655 if self.showIgnored: |
656 text = self.tr("{0} (ignored)").format(text) |
656 text = self.tr("{0} (ignored)").format(text) |
657 else: |
657 else: |
658 continue |
658 continue |
659 self.results = HAS_RESULTS |
659 self.results = CodeStyleCheckerDialog.hasResults |
660 self.__createResultItem( |
660 self.__createResultItem( |
661 fn, lineno, position, text, fixed, autofixing, ignored) |
661 fn, lineno, position, text, fixed, autofixing, ignored) |
662 |
662 |
663 self.__updateStatistics( |
663 self.__updateStatistics( |
664 codeStyleCheckerStats, fixes, ignoredErrors) |
664 codeStyleCheckerStats, fixes, ignoredErrors) |
697 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
697 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
698 self.statisticsButton.setEnabled(True) |
698 self.statisticsButton.setEnabled(True) |
699 self.showButton.setEnabled(True) |
699 self.showButton.setEnabled(True) |
700 self.startButton.setEnabled(True) |
700 self.startButton.setEnabled(True) |
701 |
701 |
702 if self.results < HAS_RESULTS: |
702 if self.results != CodeStyleCheckerDialog.hasResults: |
703 if self.results == NO_RESULTS: |
703 if self.results == CodeStyleCheckerDialog.noResults: |
704 QTreeWidgetItem( |
704 QTreeWidgetItem( |
705 self.resultList, [self.tr('No issues found.')]) |
705 self.resultList, [self.tr('No issues found.')]) |
706 else: |
706 else: |
707 QTreeWidgetItem( |
707 QTreeWidgetItem( |
708 self.resultList, |
708 self.resultList, |
760 self.__data = data |
760 self.__data = data |
761 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
761 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
762 self.__data) |
762 self.__data) |
763 |
763 |
764 self.resultList.clear() |
764 self.resultList.clear() |
765 self.results = NO_RESULTS |
765 self.results = CodeStyleCheckerDialog.noResults |
766 self.cancelled = False |
766 self.cancelled = False |
767 self.start(self.__fileOrFileList) |
767 self.start(self.__fileOrFileList) |
768 |
768 |
769 def __selectCodes(self, edit, showFixCodes): |
769 def __selectCodes(self, edit, showFixCodes): |
770 """ |
770 """ |
817 Private slot to handle the activation of an item. |
817 Private slot to handle the activation of an item. |
818 |
818 |
819 @param item reference to the activated item (QTreeWidgetItem) |
819 @param item reference to the activated item (QTreeWidgetItem) |
820 @param column column the item was activated in (integer) |
820 @param column column the item was activated in (integer) |
821 """ |
821 """ |
822 if self.results < HAS_RESULTS: |
822 if self.results != CodeStyleCheckerDialog.hasResults: |
823 return |
823 return |
824 |
824 |
825 if item.parent(): |
825 if item.parent(): |
826 fn = Utilities.normabspath(item.data(0, self.filenameRole)) |
826 fn = Utilities.normabspath(item.data(0, self.filenameRole)) |
827 lineno = item.data(0, self.lineRole) |
827 lineno = item.data(0, self.lineRole) |