eric6/E5XML/HighlightingStylesReader.py

branch
jsonfiles
changeset 8026
d3eacdbcb18b
parent 8022
2da0139f4f91
child 8066
1208cdae96b6
--- a/eric6/E5XML/HighlightingStylesReader.py	Fri Jan 29 14:18:50 2021 +0100
+++ b/eric6/E5XML/HighlightingStylesReader.py	Fri Jan 29 14:19:41 2021 +0100
@@ -8,8 +8,6 @@
 Module implementing a class for reading a highlighting styles XML file.
 """
 
-from PyQt5.QtGui import QColor, QFont
-
 from .Config import highlightingStylesFileFormatVersion
 from .XMLStreamReaderBase import XMLStreamReaderBase
 
@@ -38,6 +36,8 @@
         """
         Public method to read and parse the XML document.
         """
+        self.__lexersList = []
+        
         while not self.atEnd():
             self.readNext()
             if self.isStartElement():
@@ -53,12 +53,18 @@
                     self.raiseUnexpectedStartTag(self.name())
         
         self.showErrorMessage()
+        
+        return self.__lexersList
     
     def __readLexer(self):
         """
         Private method to read the lexer info.
         """
         language = self.attribute("name")
+        self.__lexersList.append({
+            "name": language,
+            "styles": [],
+        })
         if language and language in self.lexers:
             lexer = self.lexers[language]
         else:
@@ -88,31 +94,34 @@
                 substyle = int(self.attribute("substyle", "-1"))
                 # -1 is default for base styles
                 
-                # add sub-style if not already there
-                if not lexer.hasStyle(style, substyle):
-                    substyle = lexer.addSubstyle(style)
+                styleDict = {
+                    "style": style,
+                    "substyle": substyle,
+                }
                 
                 color = self.attribute("color")
                 if color:
-                    color = QColor(color)
+                    styleDict["color"] = color
                 else:
-                    color = lexer.defaultColor(style, substyle)
-                lexer.setColor(color, style, substyle)
+                    styleDict["color"] = (
+                        lexer.defaultColor(style, substyle).name()
+                    )
                 
                 paper = self.attribute("paper")
                 if paper:
-                    paper = QColor(paper)
+                    styleDict["paper"] = paper
                 else:
-                    paper = lexer.defaultPaper(style, substyle)
-                lexer.setPaper(paper, style, substyle)
+                    styleDict["paper"] = (
+                        lexer.defaultPaper(style, substyle).name()
+                    )
                 
                 fontStr = self.attribute("font")
                 if fontStr:
-                    font = QFont()
-                    font.fromString(fontStr)
+                    styleDict["font"] = fontStr
                 else:
-                    font = lexer.defaultFont(style, substyle)
-                lexer.setFont(font, style, substyle)
+                    styleDict["font"] = (
+                        lexer.defaultFont(style, substyle).toString()
+                    )
                 
                 eolfill = self.attribute("eolfill")
                 if eolfill:
@@ -121,26 +130,29 @@
                         eolfill = lexer.defaulEolFill(style, substyle)
                 else:
                     eolfill = lexer.defaulEolFill(style, substyle)
-                lexer.setEolFill(eolfill, style, substyle)
+                styleDict["eolfill"] = eolfill
         
                 while not self.atEnd():
                     self.readNext()
                     if self.isStartElement():
-                        if self.name() == "Description" and substyle >= 0:
-                            # description can only be set for sub-styles
+                        if self.name() == "Description":
                             description = self.readElementText().strip()
                             if not description:
                                 description = lexer.defaultDescription(
                                     style, substyle)
-                            lexer.setDescription(description, style, substyle)
-                        elif self.name() == "Words" and substyle >= 0:
-                            # words can only be set for sub-styles
+                            styleDict["description"] = description
+                        elif self.name() == "Words":
                             words = self.readElementText().strip()
                             if not words:
                                 words = lexer.defaultWords(style, substyle)
-                            lexer.setWords(words, style, substyle)
+                            styleDict["words"] = words
                     
                     if self.isEndElement() and self.name() == "Style":
+                        if "description" not in styleDict:
+                            styleDict["description"] = ""
+                        if "words" not in styleDict:
+                            styleDict["words"] = ""
+                        self.__lexersList[-1]["styles"].append(styleDict)
                         return
         
         while not self.atEnd():

eric ide

mercurial