Plugins/CheckerPlugins/Pep8/Pep8Dialog.py

changeset 2928
4f74d3f595ce
parent 2920
054ac3c88754
child 2929
28ab0bc63d69
equal deleted inserted replaced
2927:f36b757378f1 2928:4f74d3f595ce
85 85
86 @param parent reference to the parent widget (QWidget) 86 @param parent reference to the parent widget (QWidget)
87 """ 87 """
88 super().__init__(parent) 88 super().__init__(parent)
89 self.setupUi(self) 89 self.setupUi(self)
90
91 self.docTypeComboBox.addItem(self.trUtf8("PEP-257"), "pep257")
92 self.docTypeComboBox.addItem(self.trUtf8("Eric"), "eric")
90 93
91 self.statisticsButton = self.buttonBox.addButton( 94 self.statisticsButton = self.buttonBox.addButton(
92 self.trUtf8("Statistics..."), QDialogButtonBox.ActionRole) 95 self.trUtf8("Statistics..."), QDialogButtonBox.ActionRole)
93 self.statisticsButton.setToolTip( 96 self.statisticsButton.setToolTip(
94 self.trUtf8("Press to show some statistics for the last run")) 97 self.trUtf8("Press to show some statistics for the last run"))
267 self.__data["MaxLineLength"] = pep8.MAX_LINE_LENGTH 270 self.__data["MaxLineLength"] = pep8.MAX_LINE_LENGTH
268 if "HangClosing" not in self.__data: 271 if "HangClosing" not in self.__data:
269 self.__data["HangClosing"] = False 272 self.__data["HangClosing"] = False
270 if "NoFixCodes" not in self.__data: 273 if "NoFixCodes" not in self.__data:
271 self.__data["NoFixCodes"] = "E501" 274 self.__data["NoFixCodes"] = "E501"
275 if "DocstringType" not in self.__data:
276 self.__data["DocstringType"] = "pep257"
272 277
273 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) 278 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
274 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) 279 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"])
275 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) 280 self.includeMessagesEdit.setText(self.__data["IncludeMessages"])
276 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) 281 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"])
277 self.fixIssuesEdit.setText(self.__data["FixCodes"]) 282 self.fixIssuesEdit.setText(self.__data["FixCodes"])
278 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"]) 283 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"])
279 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"]) 284 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"])
280 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"]) 285 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"])
281 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"]) 286 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"])
287 self.docTypeComboBox.setCurrentIndex(
288 self.docTypeComboBox.findData(self.__data["DocstringType"]))
282 289
283 def start(self, fn, save=False, repeat=None): 290 def start(self, fn, save=False, repeat=None):
284 """ 291 """
285 Public slot to start the PEP 8 check. 292 Public slot to start the PEP 8 check.
286 293
352 fixCodes = self.fixIssuesEdit.text() 359 fixCodes = self.fixIssuesEdit.text()
353 noFixCodes = self.noFixIssuesEdit.text() 360 noFixCodes = self.noFixIssuesEdit.text()
354 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages 361 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages
355 maxLineLength = self.lineLengthSpinBox.value() 362 maxLineLength = self.lineLengthSpinBox.value()
356 hangClosing = self.hangClosingCheckBox.isChecked() 363 hangClosing = self.hangClosingCheckBox.isChecked()
364 docType = self.docTypeComboBox.itemData(
365 self.docTypeComboBox.currentIndex())
357 366
358 try: 367 try:
359 # disable updates of the list for speed 368 # disable updates of the list for speed
360 self.resultList.setUpdatesEnabled(False) 369 self.resultList.setUpdatesEnabled(False)
361 self.resultList.setSortingEnabled(False) 370 self.resultList.setSortingEnabled(False)
401 self.__project.isOpen() and \ 410 self.__project.isOpen() and \
402 self.__project.isProjectFile(file) and \ 411 self.__project.isProjectFile(file) and \
403 self.__project.getProjectLanguage() in ["Python", 412 self.__project.getProjectLanguage() in ["Python",
404 "Python2"]): 413 "Python2"]):
405 from .Pep8Checker import Pep8Py2Checker 414 from .Pep8Checker import Pep8Py2Checker
415 # TODO: add the docType into the Py2 variant
406 report = Pep8Py2Checker(file, [], 416 report = Pep8Py2Checker(file, [],
407 repeat=repeatMessages, 417 repeat=repeatMessages,
408 select=includeMessages, 418 select=includeMessages,
409 ignore=excludeMessages, 419 ignore=excludeMessages,
410 max_line_length=maxLineLength, 420 max_line_length=maxLineLength,
437 stats.update(report.counters) 447 stats.update(report.counters)
438 448
439 # check PEP-257 449 # check PEP-257
440 pep257Checker = Pep257Checker( 450 pep257Checker = Pep257Checker(
441 source, file, select, ignore, [], repeatMessages, 451 source, file, select, ignore, [], repeatMessages,
442 maxLineLength=maxLineLength) 452 maxLineLength=maxLineLength, docType=docType)
443 pep257Checker.run() 453 pep257Checker.run()
444 stats.update(pep257Checker.counters) 454 stats.update(pep257Checker.counters)
445 455
446 errors = report.errors + pep257Checker.errors 456 errors = report.errors + pep257Checker.errors
447 457
535 "FixCodes": self.fixIssuesEdit.text(), 545 "FixCodes": self.fixIssuesEdit.text(),
536 "NoFixCodes": self.noFixIssuesEdit.text(), 546 "NoFixCodes": self.noFixIssuesEdit.text(),
537 "FixIssues": self.fixIssuesCheckBox.isChecked(), 547 "FixIssues": self.fixIssuesCheckBox.isChecked(),
538 "MaxLineLength": self.lineLengthSpinBox.value(), 548 "MaxLineLength": self.lineLengthSpinBox.value(),
539 "HangClosing": self.hangClosingCheckBox.isChecked(), 549 "HangClosing": self.hangClosingCheckBox.isChecked(),
550 "DocstringType": self.docTypeComboBox.itemData(
551 self.docTypeComboBox.currentIndex()),
540 } 552 }
541 if data != self.__data: 553 if data != self.__data:
542 self.__data = data 554 self.__data = data
543 self.__project.setData("CHECKERSPARMS", "Pep8Checker", 555 self.__project.setData("CHECKERSPARMS", "Pep8Checker",
544 self.__data) 556 self.__data)
696 Preferences.Prefs.settings.value("PEP8/FixIssues"))) 708 Preferences.Prefs.settings.value("PEP8/FixIssues")))
697 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( 709 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value(
698 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) 710 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH)))
699 self.hangClosingCheckBox.setChecked(Preferences.toBool( 711 self.hangClosingCheckBox.setChecked(Preferences.toBool(
700 Preferences.Prefs.settings.value("PEP8/HangClosing"))) 712 Preferences.Prefs.settings.value("PEP8/HangClosing")))
713 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData(
714 Preferences.Prefs.settings.value("PEP8/DocstringType", "pep257")))
701 715
702 @pyqtSlot() 716 @pyqtSlot()
703 def on_storeDefaultButton_clicked(self): 717 def on_storeDefaultButton_clicked(self):
704 """ 718 """
705 Private slot to store the current configuration values as 719 Private slot to store the current configuration values as
721 self.fixIssuesCheckBox.isChecked()) 735 self.fixIssuesCheckBox.isChecked())
722 Preferences.Prefs.settings.setValue("PEP8/MaxLineLength", 736 Preferences.Prefs.settings.setValue("PEP8/MaxLineLength",
723 self.lineLengthSpinBox.value()) 737 self.lineLengthSpinBox.value())
724 Preferences.Prefs.settings.setValue("PEP8/HangClosing", 738 Preferences.Prefs.settings.setValue("PEP8/HangClosing",
725 self.hangClosingCheckBox.isChecked()) 739 self.hangClosingCheckBox.isChecked())
740 Preferences.Prefs.settings.setValue("PEP8/DocstringType",
741 self.docTypeComboBox.itemData(
742 self.docTypeComboBox.currentIndex()))
726 743
727 @pyqtSlot() 744 @pyqtSlot()
728 def on_resetDefaultButton_clicked(self): 745 def on_resetDefaultButton_clicked(self):
729 """ 746 """
730 Slot documentation goes here. 747 Private slot to reset the configuration values to their default values.
731 """ 748 """
732 raise NotImplementedError
733 Preferences.Prefs.settings.setValue("PEP8/ExcludeFilePatterns", "") 749 Preferences.Prefs.settings.setValue("PEP8/ExcludeFilePatterns", "")
734 Preferences.Prefs.settings.setValue("PEP8/ExcludeMessages", 750 Preferences.Prefs.settings.setValue("PEP8/ExcludeMessages",
735 pep8.DEFAULT_IGNORE) 751 pep8.DEFAULT_IGNORE)
736 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "") 752 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "")
737 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False) 753 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False)
739 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501") 755 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501")
740 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False) 756 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False)
741 Preferences.Prefs.settings.setValue("PEP8/MaxLineLength", 757 Preferences.Prefs.settings.setValue("PEP8/MaxLineLength",
742 pep8.MAX_LINE_LENGTH) 758 pep8.MAX_LINE_LENGTH)
743 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False) 759 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False)
760 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257")
744 761
745 @pyqtSlot(QAbstractButton) 762 @pyqtSlot(QAbstractButton)
746 def on_buttonBox_clicked(self, button): 763 def on_buttonBox_clicked(self, button):
747 """ 764 """
748 Private slot called by a button of the button box clicked. 765 Private slot called by a button of the button box clicked.
811 # skip silently because that should not happen 828 # skip silently because that should not happen
812 progress += 1 829 progress += 1
813 continue 830 continue
814 831
815 deferredFixes = {} 832 deferredFixes = {}
833 # TODO: add docstring type
816 fixer = Pep8Fixer(self.__project, file, source, 834 fixer = Pep8Fixer(self.__project, file, source,
817 fixCodes, noFixCodes, maxLineLength, 835 fixCodes, noFixCodes, maxLineLength,
818 True) # always fix in place 836 True) # always fix in place
819 errors = fixesDict[file] 837 errors = fixesDict[file]
820 errors.sort(key=lambda a: a[0][0]) 838 errors.sort(key=lambda a: a[0][0])

eric ide

mercurial