LexerPygments: fixed the settings handling of the Pygments based lexer.

Sat, 13 Mar 2021 15:55:35 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 13 Mar 2021 15:55:35 +0100
changeset 8158
16a34a0167ba
parent 8157
800c09ec0956
child 8159
08b8b3d2deb1

LexerPygments: fixed the settings handling of the Pygments based lexer.

eric6/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Lexers/LexerPygments.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
--- a/eric6/QScintilla/Editor.py	Sat Mar 13 11:52:01 2021 +0100
+++ b/eric6/QScintilla/Editor.py	Sat Mar 13 15:55:35 2021 +0100
@@ -1813,7 +1813,10 @@
             self.SCN_STYLENEEDED.connect(self.__styleNeeded)
         
         # get the font for style 0 and set it as the default font
-        key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
+        if pyname and pyname.startswith("Pygments|"):
+            key = 'Scintilla/Guessed/style0/font'
+        else:
+            key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
         fdesc = Preferences.Prefs.settings.value(key)
         if fdesc is not None:
             font = QFont(fdesc[0], int(fdesc[1]))
--- a/eric6/QScintilla/Lexers/LexerPygments.py	Sat Mar 13 11:52:01 2021 +0100
+++ b/eric6/QScintilla/Lexers/LexerPygments.py	Sat Mar 13 15:55:35 2021 +0100
@@ -182,7 +182,9 @@
         @param parent parent widget of this lexer
         @param name name of the pygments lexer to use (string)
         """
-        LexerContainer.__init__(self, parent)
+        super(LexerPygments, self).__init__(parent)
+        
+        self.__inReadSettings = False
         
         if name.startswith("Pygments|"):
             self.__forcedPygmentsName = True
@@ -313,13 +315,28 @@
             PYGMENTS_BACKTICKSTRING: True,
         }
     
+    def readSettings(self, qs, prefix="/Scintilla" ):
+        """
+        Public method to read the lexer settings.
+        
+        Note: Overridden to treat the Pygments lexer specially.
+        
+        @param qs reference to the settings object
+        @type QSettings
+        @param prefix prefix for the settings key (defaults to "/Scintilla")
+        @type str (optional)
+        """
+        self.__inReadSettings = True
+        super(LexerPygments, self).readSettings(qs, prefix=prefix)
+        self.__inReadSettings = False
+    
     def language(self):
         """
         Public method returning the language of the lexer.
         
         @return language of the lexer (string)
         """
-        if self.__pygmentsName:
+        if self.__pygmentsName and not self.__inReadSettings:
             return self.__pygmentsName
         else:
             return "Guessed"
--- a/eric6/QScintilla/MiniEditor.py	Sat Mar 13 11:52:01 2021 +0100
+++ b/eric6/QScintilla/MiniEditor.py	Sat Mar 13 15:55:35 2021 +0100
@@ -3379,7 +3379,10 @@
             self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded)
         
         # get the font for style 0 and set it as the default font
-        key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
+        if pyname and pyname.startswith("Pygments|"):
+            key = 'Scintilla/Guessed/style0/font'
+        else:
+            key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
         fdesc = Preferences.Prefs.settings.value(key)
         if fdesc is not None:
             font = QFont(fdesc[0], int(fdesc[1]))

eric ide

mercurial