Refined the indication for bad indentation of Python files.

Sat, 26 Jul 2014 12:05:01 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 26 Jul 2014 12:05:01 +0200
changeset 3730
dccee91e9d8a
parent 3729
b6eda7d63e4c
child 3731
4d73662b6811

Refined the indication for bad indentation of Python files.

Preferences/ConfigurationPages/EditorPropertiesPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/EditorPropertiesPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
QScintilla/Lexers/LexerPython.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/EditorPropertiesPage.py	Thu Jul 24 22:34:05 2014 +0200
+++ b/Preferences/ConfigurationPages/EditorPropertiesPage.py	Sat Jul 26 12:05:01 2014 +0200
@@ -192,12 +192,19 @@
             self.propertiesInitialSpacesCheckBox.setEnabled(False)
         
         # Python
+        self.pythonBadIndentationComboBox.addItems([
+            self.tr("No Warning"),
+            self.tr("Inconsistent"),
+            self.tr("Tabs after Spaces"),
+            self.tr("Spaces"),
+            self.tr("Tabs"),
+        ])
+        self.pythonBadIndentationComboBox.setCurrentIndex(
+            Preferences.getEditor("PythonBadIndentation"))
         self.foldPythonCommentCheckBox.setChecked(
             Preferences.getEditor("PythonFoldComment"))
         self.foldPythonStringCheckBox.setChecked(
             Preferences.getEditor("PythonFoldString"))
-        self.pythonBadIndentationCheckBox.setChecked(
-            Preferences.getEditor("PythonBadIndentation"))
         self.pythonAutoindentCheckBox.setChecked(
             Preferences.getEditor("PythonAutoIndent"))
         self.pythonV2UnicodeAllowedCheckBox.setChecked(
@@ -481,7 +488,7 @@
             self.foldPythonStringCheckBox.isChecked())
         Preferences.setEditor(
             "PythonBadIndentation",
-            self.pythonBadIndentationCheckBox.isChecked())
+            self.pythonBadIndentationComboBox.currentIndex())
         Preferences.setEditor(
             "PythonAutoIndent",
             self.pythonAutoindentCheckBox.isChecked())
--- a/Preferences/ConfigurationPages/EditorPropertiesPage.ui	Thu Jul 24 22:34:05 2014 +0200
+++ b/Preferences/ConfigurationPages/EditorPropertiesPage.ui	Sat Jul 26 12:05:01 2014 +0200
@@ -686,26 +686,6 @@
        </widget>
       </item>
       <item row="2" column="0">
-       <widget class="QCheckBox" name="pythonBadIndentationCheckBox">
-        <property name="toolTip">
-         <string>Select whether bad indentation shall be highlighted</string>
-        </property>
-        <property name="text">
-         <string>Highlight bad indentation</string>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="1">
-       <widget class="QCheckBox" name="pythonHighlightSubidentifierCheckBox">
-        <property name="toolTip">
-         <string>Select to highlight sub-identifiers defined in keyword set 2</string>
-        </property>
-        <property name="text">
-         <string>Highlight sub-identifiers</string>
-        </property>
-       </widget>
-      </item>
-      <item row="3" column="0">
        <widget class="QCheckBox" name="pythonAutoindentCheckBox">
         <property name="toolTip">
          <string>Select whether text should be autoindented after a ':'</string>
@@ -715,7 +695,7 @@
         </property>
        </widget>
       </item>
-      <item row="4" column="0">
+      <item row="3" column="0">
        <widget class="QCheckBox" name="pythonStringsOverNewlineCheckBox">
         <property name="toolTip">
          <string>Select to allow strings to span newline characters</string>
@@ -725,7 +705,7 @@
         </property>
        </widget>
       </item>
-      <item row="5" column="0">
+      <item row="4" column="0">
        <widget class="QCheckBox" name="pythonV2UnicodeAllowedCheckBox">
         <property name="toolTip">
          <string>Select to allow Python v2 unicode string literals (e.g. u&quot;utf8&quot;)</string>
@@ -735,7 +715,7 @@
         </property>
        </widget>
       </item>
-      <item row="6" column="0">
+      <item row="5" column="0">
        <widget class="QCheckBox" name="pythonV3BinaryAllowedCheckBox">
         <property name="toolTip">
          <string>Select to allow Python v3 binary and octal literals (e.g. 0b1011, 0o712)</string>
@@ -745,7 +725,7 @@
         </property>
        </widget>
       </item>
-      <item row="6" column="1">
+      <item row="5" column="1">
        <widget class="QCheckBox" name="pythonV3BytesAllowedCheckBox">
         <property name="toolTip">
          <string>Select to allow Python v3 bytes string literals (e.g. b&quot;bytes&quot;)</string>
@@ -755,6 +735,40 @@
         </property>
        </widget>
       </item>
+      <item row="6" column="0">
+       <widget class="QCheckBox" name="pythonHighlightSubidentifierCheckBox">
+        <property name="toolTip">
+         <string>Select to highlight sub-identifiers defined in keyword set 2</string>
+        </property>
+        <property name="text">
+         <string>Highlight sub-identifiers</string>
+        </property>
+       </widget>
+      </item>
+      <item row="7" column="0" colspan="2">
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QLabel" name="label_2">
+          <property name="text">
+           <string>Highlight bad indentation:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QComboBox" name="pythonBadIndentationComboBox">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="toolTip">
+           <string>Select whether bad indentation shall be highlighted</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>
@@ -1046,13 +1060,13 @@
   <tabstop>foldPythonCommentCheckBox</tabstop>
   <tabstop>foldPythonStringCheckBox</tabstop>
   <tabstop>foldPythonQuotesCheckBox</tabstop>
-  <tabstop>pythonBadIndentationCheckBox</tabstop>
-  <tabstop>pythonHighlightSubidentifierCheckBox</tabstop>
   <tabstop>pythonAutoindentCheckBox</tabstop>
   <tabstop>pythonStringsOverNewlineCheckBox</tabstop>
   <tabstop>pythonV2UnicodeAllowedCheckBox</tabstop>
   <tabstop>pythonV3BinaryAllowedCheckBox</tabstop>
   <tabstop>pythonV3BytesAllowedCheckBox</tabstop>
+  <tabstop>pythonHighlightSubidentifierCheckBox</tabstop>
+  <tabstop>pythonBadIndentationComboBox</tabstop>
   <tabstop>foldRubyCommentCheckBox</tabstop>
   <tabstop>foldSqlCommentCheckBox</tabstop>
   <tabstop>sqlFoldAtElseCheckBox</tabstop>
--- a/Preferences/__init__.py	Thu Jul 24 22:34:05 2014 +0200
+++ b/Preferences/__init__.py	Sat Jul 26 12:05:01 2014 +0200
@@ -30,7 +30,7 @@
 from PyQt5.QtWidgets import QInputDialog, QApplication
 from PyQt5.QtNetwork import QNetworkRequest
 from PyQt5.QtWebKit import QWebSettings
-from PyQt5.Qsci import QsciScintilla
+from PyQt5.Qsci import QsciScintilla, QsciLexerPython
 
 from E5Gui import E5FileDialog
 
@@ -401,7 +401,7 @@
         "PropertiesInitialSpaces": True,
         
         # Python specifics
-        "PythonBadIndentation": True,
+        "PythonBadIndentation": QsciLexerPython.Inconsistent,
         "PythonFoldComment": True,
         "PythonFoldString": True,
         "PythonAutoIndent": True,
@@ -1657,6 +1657,14 @@
                  "PreviewQssFileNameExtensions"]:
         return toList(prefClass.settings.value(
             "Editor/" + key, prefClass.editorDefaults[key]))
+    elif key in ["PythonBadIndentation"]:
+        value = prefClass.settings.value(
+            "Editor/" + key, prefClass.editorDefaults[key])
+        if value in ["true", "True"]:
+            value = 1
+        elif value in ["false", "False"]:
+            value = 0
+        return QsciLexerPython.IndentationWarning(int(value))
     else:
         return toBool(prefClass.settings.value(
             "Editor/" + key, prefClass.editorDefaults[key]))
--- a/QScintilla/Lexers/LexerPython.py	Thu Jul 24 22:34:05 2014 +0200
+++ b/QScintilla/Lexers/LexerPython.py	Sat Jul 26 12:05:01 2014 +0200
@@ -49,10 +49,8 @@
         """
         Public slot to initialize the properties.
         """
-        if Preferences.getEditor("PythonBadIndentation"):
-            self.setIndentationWarning(QsciLexerPython.Inconsistent)
-        else:
-            self.setIndentationWarning(QsciLexerPython.NoWarning)
+        self.setIndentationWarning(
+            Preferences.getEditor("PythonBadIndentation"))
         self.setFoldComments(Preferences.getEditor("PythonFoldComment"))
         self.setFoldQuotes(Preferences.getEditor("PythonFoldString"))
         if not Preferences.getEditor("PythonAutoIndent"):

eric ide

mercurial