Extended the PEP-8 dialog.

Sat, 24 Aug 2013 14:44:55 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 24 Aug 2013 14:44:55 +0200
changeset 2866
c77e08c38a5c
parent 2864
d973dab8b715
child 2867
eb325d7f7335

Extended the PEP-8 dialog.

Plugins/CheckerPlugins/Pep8/Pep8Dialog.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/Pep8/Pep8Dialog.ui file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/Pep8/pep8.py file | annotate | diff | comparison | revisions
UtilitiesPython2/pep8.py file | annotate | diff | comparison | revisions
--- a/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py	Sat Aug 24 12:22:40 2013 +0200
+++ b/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py	Sat Aug 24 14:44:55 2013 +0200
@@ -203,8 +203,7 @@
         
         self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker")
         if self.__data is None or \
-           "ExcludeFiles" not in self.__data or \
-           len(self.__data) != 6:
+           len(self.__data) < 6:
             # initialize the data structure
             self.__data = {
                 "ExcludeFiles": "",
@@ -214,12 +213,19 @@
                 "FixCodes": "",
                 "FixIssues": False,
             }
+        if "MaxLineLength" not in self.__data:
+            self.__data["MaxLineLength"] = pep8.MAX_LINE_LENGTH,
+        if "HangClosing" not in self.__data:
+            self.__data["HangClosing"] = False
+        
         self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
         self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"])
         self.includeMessagesEdit.setText(self.__data["IncludeMessages"])
         self.repeatCheckBox.setChecked(self.__data["RepeatMessages"])
         self.fixIssuesEdit.setText(self.__data["FixCodes"])
         self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"])
+        self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"])
+        self.hangClosingCheckBox.setChecked(self.__data["HangClosing"])
     
     def start(self, fn, save=False, repeat=None):
         """
@@ -290,6 +296,8 @@
             repeatMessages = self.repeatCheckBox.isChecked()
             fixCodes = self.fixIssuesEdit.text()
             fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages
+            maxLineLength = self.lineLengthSpinBox.value()
+            hangClosing = self.hangClosingCheckBox.isChecked()
             
             try:
                 # disable updates of the list for speed
@@ -341,8 +349,8 @@
                             repeat=repeatMessages,
                             select=includeMessages,
                             ignore=excludeMessages,
-                            max_line_length=79,     # TODO: make configurable
-                            hang_closing=False,     # TODO: make configurable
+                            max_line_length=maxLineLength,
+                            hang_closing=hangClosing,
                         )
                         report.errors.sort(key=lambda a: a[1])
                     else:
@@ -361,8 +369,8 @@
                             repeat=repeatMessages,
                             select=select,
                             ignore=ignore,
-                            max_line_length=79,     # TODO: make configurable
-                            hang_closing=False,     # TODO: make configurable
+                            max_line_length=maxLineLength,
+                            hang_closing=hangClosing,
                         )
                         report = styleGuide.check_files([file])
                         report.errors.sort(key=lambda a: a[1])
@@ -433,6 +441,8 @@
                 "RepeatMessages": self.repeatCheckBox.isChecked(),
                 "FixCodes": self.fixIssuesEdit.text(),
                 "FixIssues": self.fixIssuesCheckBox.isChecked(),
+                "MaxLineLength": self.lineLengthSpinBox.value(),
+                "HangClosing": self.hangClosingCheckBox.isChecked(),
             }
             if data != self.__data:
                 self.__data = data
@@ -565,6 +575,10 @@
             "PEP8/FixCodes"))
         self.fixIssuesCheckBox.setChecked(Preferences.toBool(
             Preferences.Prefs.settings.value("PEP8/FixIssues")))
+        self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value(
+            "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH)))
+        self.hangClosingCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value("PEP8/HangClosing")))
     
     @pyqtSlot()
     def on_storeDefaultButton_clicked(self):
@@ -582,6 +596,11 @@
             self.fixIssuesEdit.text())
         Preferences.Prefs.settings.setValue("PEP8/FixIssues",
             self.fixIssuesCheckBox.isChecked())
+        # TODO: extend for max_line_length and hang_closing
+        Preferences.Prefs.settings.setValue("PEP8/MaxLineLength",
+            self.lineLengthSpinBox.value())
+        Preferences.Prefs.settings.setValue("PEP8/HangClosing",
+            self.hangClosingCheckBox.isChecked())
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
--- a/Plugins/CheckerPlugins/Pep8/Pep8Dialog.ui	Sat Aug 24 12:22:40 2013 +0200
+++ b/Plugins/CheckerPlugins/Pep8/Pep8Dialog.ui	Sat Aug 24 14:44:55 2013 +0200
@@ -28,78 +28,31 @@
       <enum>QFrame::NoFrame</enum>
      </property>
      <layout class="QGridLayout" name="gridLayout">
-      <item row="1" column="2">
-       <widget class="QToolButton" name="excludeMessagesSelectButton">
-        <property name="toolTip">
-         <string>Press to select the message codes from a list</string>
-        </property>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_2">
         <property name="text">
-         <string>...</string>
+         <string>Exclude Files:</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="0" colspan="3">
-       <layout class="QHBoxLayout" name="horizontalLayout">
-        <item>
-         <widget class="QCheckBox" name="repeatCheckBox">
-          <property name="toolTip">
-           <string>Select to repeat each message type</string>
-          </property>
-          <property name="text">
-           <string>Repeat messages</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QCheckBox" name="fixIssuesCheckBox">
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-          <property name="toolTip">
-           <string>Select to fix some issues</string>
-          </property>
-          <property name="text">
-           <string>Fix issues automatically</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <spacer name="horizontalSpacer">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-       </layout>
-      </item>
-      <item row="1" column="0">
-       <widget class="QLabel" name="label">
-        <property name="text">
-         <string>Exclude Messages:</string>
+      <item row="0" column="1">
+       <widget class="E5ClearableLineEdit" name="excludeFilesEdit">
+        <property name="toolTip">
+         <string>Enter filename patterns of files to be excluded separated by a comma</string>
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
-       <widget class="QLabel" name="label_4">
-        <property name="text">
-         <string>Fix Issues:</string>
+      <item row="0" column="3" rowspan="7">
+       <widget class="Line" name="line">
+        <property name="lineWidth">
+         <number>2</number>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
         </property>
        </widget>
       </item>
-      <item row="3" column="1">
-       <widget class="E5ClearableLineEdit" name="fixIssuesEdit">
-        <property name="toolTip">
-         <string>Enter message codes of issues to be fixed automatically (leave empty to fix all)</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="4" rowspan="5">
+      <item row="0" column="4" rowspan="7">
        <layout class="QVBoxLayout" name="verticalLayout_2">
         <item>
          <widget class="QPushButton" name="startButton">
@@ -146,10 +99,10 @@
         </item>
        </layout>
       </item>
-      <item row="2" column="1">
-       <widget class="E5ClearableLineEdit" name="includeMessagesEdit">
-        <property name="toolTip">
-         <string>Enter message codes or categories to be included separated by a comma</string>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Exclude Messages:</string>
         </property>
        </widget>
       </item>
@@ -160,32 +113,8 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="0">
-       <widget class="QLabel" name="label_2">
-        <property name="text">
-         <string>Exclude Files:</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="E5ClearableLineEdit" name="excludeFilesEdit">
-        <property name="toolTip">
-         <string>Enter filename patterns of files to be excluded separated by a comma</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="3" rowspan="5">
-       <widget class="Line" name="line">
-        <property name="lineWidth">
-         <number>2</number>
-        </property>
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="2">
-       <widget class="QToolButton" name="includeMessagesSelectButton">
+      <item row="1" column="2">
+       <widget class="QToolButton" name="excludeMessagesSelectButton">
         <property name="toolTip">
          <string>Press to select the message codes from a list</string>
         </property>
@@ -201,6 +130,37 @@
         </property>
        </widget>
       </item>
+      <item row="2" column="1">
+       <widget class="E5ClearableLineEdit" name="includeMessagesEdit">
+        <property name="toolTip">
+         <string>Enter message codes or categories to be included separated by a comma</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="2">
+       <widget class="QToolButton" name="includeMessagesSelectButton">
+        <property name="toolTip">
+         <string>Press to select the message codes from a list</string>
+        </property>
+        <property name="text">
+         <string>...</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="label_4">
+        <property name="text">
+         <string>Fix Issues:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <widget class="E5ClearableLineEdit" name="fixIssuesEdit">
+        <property name="toolTip">
+         <string>Enter message codes of issues to be fixed automatically (leave empty to fix all)</string>
+        </property>
+       </widget>
+      </item>
       <item row="3" column="2">
        <widget class="QToolButton" name="fixIssuesSelectButton">
         <property name="toolTip">
@@ -211,6 +171,116 @@
         </property>
        </widget>
       </item>
+      <item row="4" column="0">
+       <widget class="QLabel" name="label_5">
+        <property name="text">
+         <string>Max. Line Length:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="1">
+       <layout class="QHBoxLayout" name="horizontalLayout_3">
+        <item>
+         <widget class="QSpinBox" name="lineLengthSpinBox">
+          <property name="statusTip">
+           <string>Enter the maximum allowed line length (PEP-8: 79 characters)</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
+          <property name="minimum">
+           <number>60</number>
+          </property>
+          <property name="maximum">
+           <number>119</number>
+          </property>
+          <property name="value">
+           <number>79</number>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_3">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item row="5" column="0" colspan="3">
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QCheckBox" name="repeatCheckBox">
+          <property name="toolTip">
+           <string>Select to repeat each message type</string>
+          </property>
+          <property name="text">
+           <string>Repeat messages</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QCheckBox" name="fixIssuesCheckBox">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+          <property name="toolTip">
+           <string>Select to fix some issues</string>
+          </property>
+          <property name="text">
+           <string>Fix issues automatically</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item row="6" column="0" colspan="3">
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QCheckBox" name="hangClosingCheckBox">
+          <property name="toolTip">
+           <string>Select to allow hanging closing brackets</string>
+          </property>
+          <property name="text">
+           <string>Allow hanging closing brackets</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>
@@ -292,8 +362,10 @@
   <tabstop>includeMessagesSelectButton</tabstop>
   <tabstop>fixIssuesEdit</tabstop>
   <tabstop>fixIssuesSelectButton</tabstop>
+  <tabstop>lineLengthSpinBox</tabstop>
   <tabstop>repeatCheckBox</tabstop>
   <tabstop>fixIssuesCheckBox</tabstop>
+  <tabstop>hangClosingCheckBox</tabstop>
   <tabstop>storeDefaultButton</tabstop>
   <tabstop>resultList</tabstop>
   <tabstop>buttonBox</tabstop>
--- a/Plugins/CheckerPlugins/Pep8/pep8.py	Sat Aug 24 12:22:40 2013 +0200
+++ b/Plugins/CheckerPlugins/Pep8/pep8.py	Sat Aug 24 14:44:55 2013 +0200
@@ -1114,6 +1114,7 @@
         yield match.start(), "E721"
 
 
+def python_3000_has_key(logical_line):
     r"""
     The {}.has_key() method is removed in the Python 3.
     Use the 'in' operation instead.
--- a/UtilitiesPython2/pep8.py	Sat Aug 24 12:22:40 2013 +0200
+++ b/UtilitiesPython2/pep8.py	Sat Aug 24 14:44:55 2013 +0200
@@ -956,6 +956,7 @@
         yield match.start(), "E721"
 
 
+def python_3000_has_key(logical_line):
     r"""
     The {}.has_key() method is removed in the Python 3.
     Use the 'in' operation instead.

eric ide

mercurial