38 messageRole = Qt.UserRole + 4 |
38 messageRole = Qt.UserRole + 4 |
39 fixableRole = Qt.UserRole + 5 |
39 fixableRole = Qt.UserRole + 5 |
40 codeRole = Qt.UserRole + 6 |
40 codeRole = Qt.UserRole + 6 |
41 ignoredRole = Qt.UserRole + 7 |
41 ignoredRole = Qt.UserRole + 7 |
42 |
42 |
|
43 availableFutures = [ |
|
44 'division', 'absolute_import', 'with_statement', |
|
45 'print_function', 'unicode_literals', 'generator_stop'] |
|
46 |
43 def __init__(self, styleCheckService, parent=None): |
47 def __init__(self, styleCheckService, parent=None): |
44 """ |
48 """ |
45 Constructor |
49 Constructor |
46 |
50 |
47 @param styleCheckService reference to the service |
51 @param styleCheckService reference to the service |
61 self.noFixIssuesSelectButton.setIcon( |
65 self.noFixIssuesSelectButton.setIcon( |
62 UI.PixmapCache.getIcon("select.png")) |
66 UI.PixmapCache.getIcon("select.png")) |
63 |
67 |
64 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257") |
68 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257") |
65 self.docTypeComboBox.addItem(self.tr("Eric"), "eric") |
69 self.docTypeComboBox.addItem(self.tr("Eric"), "eric") |
|
70 |
|
71 self.futuresList.addItems(self.availableFutures) |
66 |
72 |
67 self.statisticsButton = self.buttonBox.addButton( |
73 self.statisticsButton = self.buttonBox.addButton( |
68 self.tr("Statistics..."), QDialogButtonBox.ActionRole) |
74 self.tr("Statistics..."), QDialogButtonBox.ActionRole) |
69 self.statisticsButton.setToolTip( |
75 self.statisticsButton.setToolTip( |
70 self.tr("Press to show some statistics for the last run")) |
76 self.tr("Press to show some statistics for the last run")) |
305 self.__data["ValidEncodings"] = "latin-1, utf-8" |
311 self.__data["ValidEncodings"] = "latin-1, utf-8" |
306 if "CopyrightMinFileSize" not in self.__data or \ |
312 if "CopyrightMinFileSize" not in self.__data or \ |
307 "CopyrightAuthor" not in self.__data: |
313 "CopyrightAuthor" not in self.__data: |
308 self.__data["CopyrightMinFileSize"] = 0 |
314 self.__data["CopyrightMinFileSize"] = 0 |
309 self.__data["CopyrightAuthor"] = "" |
315 self.__data["CopyrightAuthor"] = "" |
|
316 if "FutureChecker" not in self.__data: |
|
317 self.__data["FutureChecker"] = "" |
310 |
318 |
311 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
319 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
312 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
320 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
313 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
321 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
314 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
322 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
323 self.complexitySpinBox.setValue(self.__data["MaxCodeComplexity"]) |
331 self.complexitySpinBox.setValue(self.__data["MaxCodeComplexity"]) |
324 self.encodingsEdit.setText(self.__data["ValidEncodings"]) |
332 self.encodingsEdit.setText(self.__data["ValidEncodings"]) |
325 self.copyrightFileSizeSpinBox.setValue( |
333 self.copyrightFileSizeSpinBox.setValue( |
326 self.__data["CopyrightMinFileSize"]) |
334 self.__data["CopyrightMinFileSize"]) |
327 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"]) |
335 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"]) |
|
336 self.__initFuturesList(self.__data["FutureChecker"]) |
328 |
337 |
329 def start(self, fn, save=False, repeat=None): |
338 def start(self, fn, save=False, repeat=None): |
330 """ |
339 """ |
331 Public slot to start the code style check. |
340 Public slot to start the code style check. |
332 |
341 |
407 miscellaneousArgs = { |
416 miscellaneousArgs = { |
408 "CodingChecker": self.encodingsEdit.text(), |
417 "CodingChecker": self.encodingsEdit.text(), |
409 "CopyrightChecker": { |
418 "CopyrightChecker": { |
410 "MinFilesize": self.copyrightFileSizeSpinBox.value(), |
419 "MinFilesize": self.copyrightFileSizeSpinBox.value(), |
411 "Author": self.copyrightAuthorEdit.text(), |
420 "Author": self.copyrightAuthorEdit.text(), |
412 } |
421 }, |
|
422 "FutureChecker": self.__getSelectedFutureImports(), |
413 } |
423 } |
414 |
424 |
415 self.__options = [excludeMessages, includeMessages, repeatMessages, |
425 self.__options = [excludeMessages, includeMessages, repeatMessages, |
416 fixCodes, noFixCodes, fixIssues, maxLineLength, |
426 fixCodes, noFixCodes, fixIssues, maxLineLength, |
417 hangClosing, docType, maxCodeComplexity, |
427 hangClosing, docType, maxCodeComplexity, |
696 self.docTypeComboBox.currentIndex()), |
706 self.docTypeComboBox.currentIndex()), |
697 "MaxCodeComplexity": self.complexitySpinBox.value(), |
707 "MaxCodeComplexity": self.complexitySpinBox.value(), |
698 "ValidEncodings": self.encodingsEdit.text(), |
708 "ValidEncodings": self.encodingsEdit.text(), |
699 "CopyrightMinFileSize": self.copyrightFileSizeSpinBox.value(), |
709 "CopyrightMinFileSize": self.copyrightFileSizeSpinBox.value(), |
700 "CopyrightAuthor": self.copyrightAuthorEdit.text(), |
710 "CopyrightAuthor": self.copyrightAuthorEdit.text(), |
|
711 "FutureChecker": self.__getSelectedFutureImports(), |
701 } |
712 } |
702 if data != self.__data: |
713 if data != self.__data: |
703 self.__data = data |
714 self.__data = data |
704 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
715 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
705 self.__data) |
716 self.__data) |
846 def on_loadDefaultButton_clicked(self): |
857 def on_loadDefaultButton_clicked(self): |
847 """ |
858 """ |
848 Private slot to load the default configuration values. |
859 Private slot to load the default configuration values. |
849 """ |
860 """ |
850 self.excludeFilesEdit.setText(Preferences.Prefs.settings.value( |
861 self.excludeFilesEdit.setText(Preferences.Prefs.settings.value( |
851 "PEP8/ExcludeFilePatterns")) |
862 "PEP8/ExcludeFilePatterns", "")) |
852 self.excludeMessagesEdit.setText(Preferences.Prefs.settings.value( |
863 self.excludeMessagesEdit.setText(Preferences.Prefs.settings.value( |
853 "PEP8/ExcludeMessages", pep8.DEFAULT_IGNORE)) |
864 "PEP8/ExcludeMessages", pep8.DEFAULT_IGNORE)) |
854 self.includeMessagesEdit.setText(Preferences.Prefs.settings.value( |
865 self.includeMessagesEdit.setText(Preferences.Prefs.settings.value( |
855 "PEP8/IncludeMessages")) |
866 "PEP8/IncludeMessages", "")) |
856 self.repeatCheckBox.setChecked(Preferences.toBool( |
867 self.repeatCheckBox.setChecked(Preferences.toBool( |
857 Preferences.Prefs.settings.value("PEP8/RepeatMessages"))) |
868 Preferences.Prefs.settings.value("PEP8/RepeatMessages", False))) |
858 self.fixIssuesEdit.setText(Preferences.Prefs.settings.value( |
869 self.fixIssuesEdit.setText(Preferences.Prefs.settings.value( |
859 "PEP8/FixCodes")) |
870 "PEP8/FixCodes", "")) |
860 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
871 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
861 "PEP8/NoFixCodes", "E501")) |
872 "PEP8/NoFixCodes", "E501")) |
862 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
873 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
863 Preferences.Prefs.settings.value("PEP8/FixIssues"))) |
874 Preferences.Prefs.settings.value("PEP8/FixIssues", False))) |
864 self.ignoredCheckBox.setChecked(Preferences.toBool( |
875 self.ignoredCheckBox.setChecked(Preferences.toBool( |
865 Preferences.Prefs.settings.value("PEP8/ShowIgnored"))) |
876 Preferences.Prefs.settings.value("PEP8/ShowIgnored", False))) |
866 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
877 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
867 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
878 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
868 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
879 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
869 Preferences.Prefs.settings.value("PEP8/HangClosing"))) |
880 Preferences.Prefs.settings.value("PEP8/HangClosing", False))) |
870 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
881 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
871 Preferences.Prefs.settings.value("PEP8/DocstringType", "pep257"))) |
882 Preferences.Prefs.settings.value("PEP8/DocstringType", "pep257"))) |
872 self.complexitySpinBox.setValue(int(Preferences.Prefs.settings.value( |
883 self.complexitySpinBox.setValue(int(Preferences.Prefs.settings.value( |
873 "PEP8/MaxCodeComplexity", 10))) |
884 "PEP8/MaxCodeComplexity", 10))) |
874 self.encodingsEdit.setText(Preferences.Prefs.settings.value( |
885 self.encodingsEdit.setText(Preferences.Prefs.settings.value( |
875 "PEP8/ValidEncodings", "latin-1, utf-8")) |
886 "PEP8/ValidEncodings", "latin-1, utf-8")) |
876 self.copyrightFileSizeSpinBox.setValue(int( |
887 self.copyrightFileSizeSpinBox.setValue(int( |
877 Preferences.Prefs.settings.value("PEP8/CopyrightMinFileSize", 0))) |
888 Preferences.Prefs.settings.value("PEP8/CopyrightMinFileSize", 0))) |
878 self.copyrightAuthorEdit.setText( |
889 self.copyrightAuthorEdit.setText( |
879 Preferences.Prefs.settings.value("PEP8/CopyrightAuthor")) |
890 Preferences.Prefs.settings.value("PEP8/CopyrightAuthor", "")) |
|
891 self.__initFuturesList( |
|
892 Preferences.Prefs.settings.value("PEP8/FutureChecker", "")) |
880 |
893 |
881 @pyqtSlot() |
894 @pyqtSlot() |
882 def on_storeDefaultButton_clicked(self): |
895 def on_storeDefaultButton_clicked(self): |
883 """ |
896 """ |
884 Private slot to store the current configuration values as |
897 Private slot to store the current configuration values as |
913 "PEP8/ValidEncodings", self.encodingsEdit.text()) |
926 "PEP8/ValidEncodings", self.encodingsEdit.text()) |
914 Preferences.Prefs.settings.setValue( |
927 Preferences.Prefs.settings.setValue( |
915 "PEP8/CopyrightMinFileSize", self.copyrightFileSizeSpinBox.value()) |
928 "PEP8/CopyrightMinFileSize", self.copyrightFileSizeSpinBox.value()) |
916 Preferences.Prefs.settings.setValue( |
929 Preferences.Prefs.settings.setValue( |
917 "PEP8/CopyrightAuthor", self.copyrightAuthorEdit.text()) |
930 "PEP8/CopyrightAuthor", self.copyrightAuthorEdit.text()) |
|
931 Preferences.Prefs.settings.setValue( |
|
932 "PEP8/FutureChecker", self.__getSelectedFutureImports()) |
918 |
933 |
919 @pyqtSlot() |
934 @pyqtSlot() |
920 def on_resetDefaultButton_clicked(self): |
935 def on_resetDefaultButton_clicked(self): |
921 """ |
936 """ |
922 Private slot to reset the configuration values to their default values. |
937 Private slot to reset the configuration values to their default values. |
937 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10) |
952 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10) |
938 Preferences.Prefs.settings.setValue( |
953 Preferences.Prefs.settings.setValue( |
939 "PEP8/ValidEncodings", "latin-1, utf-8") |
954 "PEP8/ValidEncodings", "latin-1, utf-8") |
940 Preferences.Prefs.settings.setValue("PEP8/CopyrightMinFileSize", 0) |
955 Preferences.Prefs.settings.setValue("PEP8/CopyrightMinFileSize", 0) |
941 Preferences.Prefs.settings.setValue("PEP8/CopyrightAuthor", "") |
956 Preferences.Prefs.settings.setValue("PEP8/CopyrightAuthor", "") |
|
957 Preferences.Prefs.settings.setValue("PEP8/FutureChecker", "") |
942 |
958 |
943 @pyqtSlot(QAbstractButton) |
959 @pyqtSlot(QAbstractButton) |
944 def on_buttonBox_clicked(self, button): |
960 def on_buttonBox_clicked(self, button): |
945 """ |
961 """ |
946 Private slot called by a button of the button box clicked. |
962 Private slot called by a button of the button box clicked. |
1036 @param itm item to be checked (QTreeWidgetItem) |
1052 @param itm item to be checked (QTreeWidgetItem) |
1037 @return flag indicating a fixable issue (boolean) |
1053 @return flag indicating a fixable issue (boolean) |
1038 """ |
1054 """ |
1039 return (itm.data(0, self.fixableRole) and |
1055 return (itm.data(0, self.fixableRole) and |
1040 not itm.data(0, self.ignoredRole)) |
1056 not itm.data(0, self.ignoredRole)) |
|
1057 |
|
1058 def __initFuturesList(self, selectedFutures): |
|
1059 """ |
|
1060 Private method to set the selected status of the future imports. |
|
1061 |
|
1062 @param selectedFutures comma separated list of expected future imports |
|
1063 @type str |
|
1064 """ |
|
1065 if selectedFutures: |
|
1066 expectedImports = [ |
|
1067 i.strip() for i in selectedFutures.split(",") |
|
1068 if bool(i.strip())] |
|
1069 else: |
|
1070 expectedImports = [] |
|
1071 for row in range(self.futuresList.count()): |
|
1072 itm = self.futuresList.item(row) |
|
1073 itm.setSelected(itm.text() in expectedImports) |
|
1074 |
|
1075 def __getSelectedFutureImports(self): |
|
1076 """ |
|
1077 Private method to get the expected future imports. |
|
1078 |
|
1079 @return expected future imports as a comma separated string |
|
1080 @rtype str |
|
1081 """ |
|
1082 selectedFutures = [i.text() for i in self.futuresList.selectedItems()] |
|
1083 return ", ".join(selectedFutures) |