QScintilla/MiniEditor.py

changeset 1197
59fa9eae9123
parent 1131
7781e396c903
child 1198
214fb8967707
--- a/QScintilla/MiniEditor.py	Sun Jul 24 19:22:40 2011 +0200
+++ b/QScintilla/MiniEditor.py	Tue Jul 26 19:57:24 2011 +0200
@@ -2047,6 +2047,11 @@
         
         filename = os.path.basename(filename)
         language = Preferences.getEditorLexerAssoc(filename)
+        if language == "Python":
+            if self.__isPy2File():
+                language = "Python2"
+            else:
+                language = "Python3"
         if language.startswith("Pygments|"):
             pyname = language.split("|", 1)[1]
             language = ""
@@ -2077,6 +2082,36 @@
         # now set the lexer properties
         self.lexer_.initProperties()
         
+    def __isPy2File(self):
+        """
+        Private method to return a flag indicating a Python 2 file.
+        
+        @return flag indicating a Python 2 file (boolean)
+        """
+        if self.filetype in ["Python", "Python2"]:
+            return True
+        
+        if self.filetype == "":
+            line0 = self.__textEdit.text(0)
+            if line0.startswith("#!") and \
+               ("python2" in line0 or \
+                ("python" in line0 and not "python3" in line0)):
+                return True
+            
+            if self.__curFile is not None:
+                exts = []
+                for ext in Preferences.getDebugger("PythonExtensions").split():
+                    if ext.startswith("."):
+                        exts.append(ext)
+                    else:
+                        exts.append(".{0}".format(ext))
+                
+                ext = os.path.splitext(self.__curFile)[1]
+                if ext in exts:
+                    return True
+        
+        return False
+        
     def __styleNeeded(self, position):
         """
         Private slot to handle the need for more styling.
@@ -2098,7 +2133,7 @@
             bindName = "dummy.xml"
         
         # check filetype
-        if self.filetype in ["Python", "Python3"]:
+        if self.filetype in ["Python", "Python2", "Python3"]:
             bindName = "dummy.py"
         elif self.filetype == "Ruby":
             bindName = "dummy.rb"

eric ide

mercurial