QScintilla/Editor.py

branch
Py2 comp.
changeset 3056
9986ec0e559a
parent 2791
a9577f248f04
parent 2926
ae7c9d9f3b4a
child 3057
10516539f238
--- a/QScintilla/Editor.py	Sun Sep 08 19:04:07 2013 +0200
+++ b/QScintilla/Editor.py	Tue Oct 15 22:03:54 2013 +0200
@@ -102,6 +102,9 @@
     lastEditPositionAvailable = pyqtSignal()
     refreshed = pyqtSignal()
     
+    WarningCode = 1
+    WarningStyle = 2
+    
     # Autocompletion icon definitions
     ClassID = 1
     ClassProtectedID = 2
@@ -159,15 +162,19 @@
         self.lastErrorMarker = None   # remember the last error line
         self.lastCurrMarker = None   # remember the last current line
         
-        self.breaks = {}            # key:   marker handle,
-                                    # value: (lineno, condition, temporary,
-                                    #         enabled, ignorecount)
-        self.bookmarks = []         # bookmarks are just a list of handles to the
-                                    # bookmark markers
-        self.syntaxerrors = {}      # key:   marker handle
-                                    # value: error message, error index
-        self.warnings = {}          # key:   marker handle
-                                    # value: list of warning messages
+        self.breaks = {}
+            # key:   marker handle,
+            # value: (lineno, condition, temporary,
+            #         enabled, ignorecount)
+        self.bookmarks = []
+            # bookmarks are just a list of handles to the
+            # bookmark markers
+        self.syntaxerrors = {}
+            # key:   marker handle
+            # value: list of (error message, error index)
+        self.warnings = {}
+            # key:   marker handle
+            # value: list of (warning message, warning type)
         self.notcoveredMarkers = []  # just a list of marker handles
         self.showingNotcoveredMarkers = False
         
@@ -181,13 +188,20 @@
         self.line = -1
         self.inReopenPrompt = False
             # true if the prompt to reload a changed source is present
-        self.inFileRenamed = False      # true if we are propagating a rename action
-        self.inLanguageChanged = False  # true if we are propagating a language change
-        self.inEolChanged = False       # true if we are propagating an eol change
-        self.inEncodingChanged = False  # true if we are propagating an encoding change
-        self.inDragDrop = False         # true if we are in drop mode
-        self.inLinesChanged = False     # true if we are propagating a lines changed event
-        self.__hasTaskMarkers = False   # no task markers present
+        self.inFileRenamed = False
+            # true if we are propagating a rename action
+        self.inLanguageChanged = False
+            # true if we are propagating a language change
+        self.inEolChanged = False
+            # true if we are propagating an eol change
+        self.inEncodingChanged = False
+            # true if we are propagating an encoding change
+        self.inDragDrop = False
+            # true if we are in drop mode
+        self.inLinesChanged = False
+            # true if we are propagating a lines changed event
+        self.__hasTaskMarkers = False
+            # no task markers present
             
         self.macros = {}    # list of defined macros
         self.curMacro = None
@@ -1414,10 +1428,10 @@
         if not language:
             ext = os.path.splitext(filename)[1]
             if ext in [".py", ".pyw"]:
-                if self.isPy2File():
+                if self.isPy3File():
+                    language = "Python3"
+                elif self.isPy2File():
                     language = "Python2"
-                elif self.isPy3File():
-                    language = "Python3"
                 else:
                     # default is Python 3
                     language = "Python3"
@@ -1536,10 +1550,10 @@
         filename = os.path.basename(filename)
         apiLanguage = Preferences.getEditorLexerAssoc(filename)
         if apiLanguage == "":
-            if self.isPy2File():
+            if self.isPy3File():
+                apiLanguage = "Python3"
+            elif self.isPy2File():
                 apiLanguage = "Python2"
-            elif self.isPy3File():
-                apiLanguage = "Python3"
             elif self.isRubyFile():
                 apiLanguage = "Ruby"
         
@@ -1667,10 +1681,10 @@
         if not ftype:
             ftype = self.getFileTypeByFlag()
         if not ftype:
-            if self.isPy2File():
+            if self.isPy3File():
+                ftype = "Python3"
+            elif self.isPy2File():
                 ftype = "Python2"
-            elif self.isPy3File():
-                ftype = "Python3"
             elif self.isRubyFile():
                 ftype = "Ruby"
             else:
@@ -2838,7 +2852,7 @@
             self.setWindowTitle(self.fileName)
             # get eric specific flags
             self.__processFlags()
-            if self.lexer_ is None and not self.__lexerReset:
+            if not self.__lexerReset:
                 self.setLanguage(self.fileName)
             
             if saveas:
@@ -5088,11 +5102,16 @@
             if not (markers & (1 << self.syntaxerror)):
                 handle = self.markerAdd(line - 1, self.syntaxerror)
                 index += self.indentation(line - 1)
-                self.syntaxerrors[handle] = (msg, index)
+                self.syntaxerrors[handle] = [(msg, index)]
                 self.syntaxerrorToggled.emit(self)
-                if show:
-                    self.setCursorPosition(line - 1, index)
-                    self.ensureLineVisible(line - 1)
+            else:
+                for handle in list(self.syntaxerrors.keys()):
+                    if self.markerLine(handle) == line - 1 and \
+                       (msg, index) not in self.syntaxerrors[handle]:
+                        self.syntaxerrors[handle].append((msg, index))
+            if show:
+                self.setCursorPosition(line - 1, index)
+                self.ensureLineVisible(line - 1)
         else:
             for handle in list(self.syntaxerrors.keys()):
                 if self.markerLine(handle) == line - 1:
@@ -5133,7 +5152,7 @@
             index = 0
             for handle in self.syntaxerrors.keys():
                 if self.markerLine(handle) == seline:
-                    index = self.syntaxerrors[handle][1]
+                    index = self.syntaxerrors[handle][0][1]
             self.setCursorPosition(seline, index)
         self.ensureLineVisible(seline)
         
@@ -5157,9 +5176,10 @@
         
         for handle in list(self.syntaxerrors.keys()):
             if self.markerLine(handle) == line:
+                errors = [e[0] for e in self.syntaxerrors[handle]]
                 E5MessageBox.critical(self,
                     self.trUtf8("Syntax Error"),
-                    self.syntaxerrors[handle][0])
+                    "\n".join(errors))
                 break
         else:
             E5MessageBox.critical(self,
@@ -5169,8 +5189,9 @@
     ############################################################################
     ## Flakes warning handling methods below
     ############################################################################
-
-    def toggleFlakesWarning(self, line, warning, msg=""):
+    
+    def toggleFlakesWarning(self, line, warning, msg="",
+                            warningType=WarningCode):
         """
         Public method to toggle a flakes warning indicator.
         
@@ -5180,22 +5201,24 @@
         @param warning flag indicating if the warning marker should be
             set or deleted (boolean)
         @param msg warning message (string)
+        @keyparam warningType type of warning message (integer)
         """
         if line == 0:
             line = 1
             # hack to show a warning marker, if line is reported to be 0
         if warning:
             # set/ammend a new warning marker
+            warn = (msg, warningType)
             markers = self.markersAtLine(line - 1)
             if not (markers & (1 << self.warning)):
                 handle = self.markerAdd(line - 1, self.warning)
-                self.warnings[handle] = [msg]
+                self.warnings[handle] = [warn]
                 self.syntaxerrorToggled.emit(self)
             else:
                 for handle in list(self.warnings.keys()):
                     if self.markerLine(handle) == line - 1 and \
-                       msg not in self.warnings[handle]:
-                        self.warnings[handle].append(msg)
+                       warn not in self.warnings[handle]:
+                        self.warnings[handle].append(warn)
         else:
             for handle in list(self.warnings.keys()):
                 if self.markerLine(handle) == line - 1:
@@ -5284,13 +5307,13 @@
         for handle in list(self.warnings.keys()):
             if self.markerLine(handle) == line:
                 E5MessageBox.warning(self,
-                    self.trUtf8("py3flakes Warning"),
+                    self.trUtf8("Warning"),
                     '\n'.join(self.warnings[handle]))
                 break
         else:
             E5MessageBox.warning(self,
-                self.trUtf8("py3flakes Warning"),
-                self.trUtf8("No py3flakes warning message available."))
+                self.trUtf8("Warning"),
+                self.trUtf8("No warning messages available."))
     
     ############################################################################
     ## Annotation handling methods below
@@ -5316,6 +5339,14 @@
             self.SendScintilla(QsciScintilla.SCI_STYLESETBACK,
                 self.annotationErrorStyle,
                 Preferences.getEditorColour("AnnotationsErrorBackground"))
+            
+            self.annotationStyleStyle = self.annotationErrorStyle + 1
+            self.SendScintilla(QsciScintilla.SCI_STYLESETFORE,
+                self.annotationStyleStyle,
+                Preferences.getEditorColour("AnnotationsStyleForeground"))
+            self.SendScintilla(QsciScintilla.SCI_STYLESETBACK,
+                self.annotationStyleStyle,
+                Preferences.getEditorColour("AnnotationsStyleBackground"))
         
     def __setAnnotation(self, line):
         """
@@ -5326,25 +5357,38 @@
         if hasattr(QsciScintilla, "annotate"):
             warningAnnotations = []
             errorAnnotations = []
+            styleAnnotations = []
             
-            # step 1: do py3flakes warnings
+            # step 1: do warnings
             for handle in list(self.warnings.keys()):
                 if self.markerLine(handle) == line:
-                    for msg in self.warnings[handle]:
-                        warningAnnotations.append(
-                            self.trUtf8("Warning: {0}").format(msg))
+                    for msg, warningType in self.warnings[handle]:
+                        if warningType == self.WarningStyle:
+                            styleAnnotations.append(
+                                self.trUtf8("Style: {0}").format(msg))
+                        else:
+                            warningAnnotations.append(
+                                self.trUtf8("Warning: {0}").format(msg))
             
             # step 2: do syntax errors
             for handle in list(self.syntaxerrors.keys()):
                 if self.markerLine(handle) == line:
-                    errorAnnotations.append(
-                        self.trUtf8("Error: {0}").format(
-                            self.syntaxerrors[handle][0]))
+                    for msg, _ in self.syntaxerrors[handle]:
+                        errorAnnotations.append(
+                            self.trUtf8("Error: {0}").format(msg))
             
             wLen = len(warningAnnotations)
             eLen = len(errorAnnotations)
+            sLen = len(styleAnnotations)
             annotations = []
             
+            if sLen:
+                annotationStyleTxt = "\n".join(styleAnnotations)
+                if wLen:
+                    annotationStyleTxt += "\n"
+                annotations.append(QsciStyledText(annotationStyleTxt,
+                    self.annotationStyleStyle))
+            
             if wLen:
                 annotationWarningTxt = "\n".join(warningAnnotations)
                 if eLen:

eric ide

mercurial