eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
jsonfiles
changeset 8026
d3eacdbcb18b
parent 8022
2da0139f4f91
child 8028
a4f1b68c0737
diff -r aaad60a23960 -r d3eacdbcb18b eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py
--- a/eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Fri Jan 29 14:18:50 2021 +0100
+++ b/eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Fri Jan 29 14:19:41 2021 +0100
@@ -10,7 +10,7 @@
 import os
 
 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
-from PyQt5.QtGui import QPalette, QFont
+from PyQt5.QtGui import QPalette, QFont, QColor
 from PyQt5.QtWidgets import (
     QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog
 )
@@ -607,8 +607,8 @@
                 HighlightingStylesFile
             )
             highlightingStylesFile = HighlightingStylesFile()
-            res = highlightingStylesFile.readFile(fn, lexers)
-            if not res:
+            styles = highlightingStylesFile.readFile(fn, lexers)
+            if not styles:
                 return
         else:
             # old XML based file
@@ -618,8 +618,10 @@
                     HighlightingStylesReader
                 )
                 reader = HighlightingStylesReader(f, lexers)
-                reader.readXML()
+                styles = reader.readXML()
                 f.close()
+                if not styles:
+                    return
             else:
                 E5MessageBox.critical(
                     self,
@@ -631,9 +633,37 @@
                 )
                 return
         
+        self.__applyStyles(styles, lexers)
         self.on_lexerLanguageComboBox_activated(
             self.lexerLanguageComboBox.currentText())
     
+    def __applyStyles(self, stylesList, lexersList):
+        """
+        Private method to apply the imported styles to this dialog.
+        
+        @param stylesList list of imported lexer styles
+        @type list of dict
+        @param lexersList list of lexers to apply the styles to
+        @type list of PreferencesLexer
+        """
+        for lexerDict in stylesList:
+            if lexerDict["name"] in lexersList:
+                lexer = lexersList[lexerDict["name"]]
+                for styleDict in lexerDict["styles"]:
+                    style = styleDict["style"]
+                    substyle = styleDict["substyle"]
+                    lexer.setColor(QColor(styleDict["color"]), style, substyle)
+                    lexer.setPaper(QColor(styleDict["paper"]), style, substyle)
+                    font = QFont()
+                    font.fromString(styleDict["font"])
+                    lexer.setFont(font, style, substyle)
+                    lexer.setEolFill(styleDict["eolfill"], style, substyle)
+                    if substyle >= 0:
+                        # description and words can only be set for sub-styles
+                        lexer.setDescription(styleDict["description"],
+                                             style, substyle)
+                        lexer.setWords(styleDict["words"], style, substyle)
+    
     #######################################################################
     ## Methods to save and restore the state
     #######################################################################

eric ide

mercurial