E5XML/HighlightingStylesReader.py

branch
sub_styles
changeset 6863
e900929889dd
parent 6857
59f6251587fa
equal deleted inserted replaced
6862:6f4237ccf576 6863:e900929889dd
14 14
15 from .Config import highlightingStylesFileFormatVersion 15 from .Config import highlightingStylesFileFormatVersion
16 from .XMLStreamReaderBase import XMLStreamReaderBase 16 from .XMLStreamReaderBase import XMLStreamReaderBase
17 17
18 18
19 # TODO: add support for sub-styling
20 class HighlightingStylesReader(XMLStreamReaderBase): 19 class HighlightingStylesReader(XMLStreamReaderBase):
21 """ 20 """
22 Class for reading a highlighting styles XML file. 21 Class for reading a highlighting styles XML file.
23 """ 22 """
24 supportedVersions = ["4.3"] 23 supportedVersions = ["4.3", "6.0"]
25 24
26 def __init__(self, device, lexers): 25 def __init__(self, device, lexers):
27 """ 26 """
28 Constructor 27 Constructor
29 28
85 """ 84 """
86 if lexer is not None: 85 if lexer is not None:
87 style = self.attribute("style") 86 style = self.attribute("style")
88 if style: 87 if style:
89 style = int(style) 88 style = int(style)
89 substyle = int(self.attribute("substyle", "-1"))
90 # -1 is default for base styles
91
92 # add sub-style if not already there
93 if not lexer.hasStyle(style, substyle):
94 substyle = lexer.addSubstyle(style)
90 95
91 color = self.attribute("color") 96 color = self.attribute("color")
92 if color: 97 if color:
93 color = QColor(color) 98 color = QColor(color)
94 else: 99 else:
95 color = lexer.defaultColor(style) 100 color = lexer.defaultColor(style, substyle)
96 lexer.setColor(color, style) 101 lexer.setColor(color, style, substyle)
97 102
98 paper = self.attribute("paper") 103 paper = self.attribute("paper")
99 if paper: 104 if paper:
100 paper = QColor(paper) 105 paper = QColor(paper)
101 else: 106 else:
102 paper = lexer.defaultPaper(style) 107 paper = lexer.defaultPaper(style, substyle)
103 lexer.setPaper(paper, style) 108 lexer.setPaper(paper, style, substyle)
104 109
105 fontStr = self.attribute("font") 110 fontStr = self.attribute("font")
106 if fontStr: 111 if fontStr:
107 font = QFont() 112 font = QFont()
108 font.fromString(fontStr) 113 font.fromString(fontStr)
109 else: 114 else:
110 font = lexer.defaultFont(style) 115 font = lexer.defaultFont(style, substyle)
111 lexer.setFont(font, style) 116 lexer.setFont(font, style, substyle)
112 117
113 eolfill = self.attribute("eolfill") 118 eolfill = self.attribute("eolfill")
114 if eolfill: 119 if eolfill:
115 eolfill = self.toBool(eolfill) 120 eolfill = self.toBool(eolfill)
116 if eolfill is None: 121 if eolfill is None:
117 eolfill = lexer.defaulEolFill(style) 122 eolfill = lexer.defaulEolFill(style, substyle)
118 else: 123 else:
119 eolfill = lexer.defaulEolFill(style) 124 eolfill = lexer.defaulEolFill(style, substyle)
120 lexer.setEolFill(eolfill, style) 125 lexer.setEolFill(eolfill, style, substyle)
126
127 while not self.atEnd():
128 self.readNext()
129 if self.isStartElement():
130 if self.name() == "Description" and substyle >= 0:
131 # description can only be set for sub-styles
132 description = self.readElementText().strip()
133 if not description:
134 description = lexer.defaultDescription(
135 style, substyle)
136 lexer.setDescription(description, style, substyle)
137 elif self.name() == "Words" and substyle >= 0:
138 # words can only be set for sub-styles
139 words = self.readElementText().strip()
140 if not words:
141 words = lexer.defaultWords(style, substyle)
142 lexer.setWords(words, style, substyle)
143
144 if self.isEndElement() and self.name() == "Style":
145 return
121 146
122 while not self.atEnd(): 147 while not self.atEnd():
123 self.readNext() 148 self.readNext()
124 if self.isEndElement() and self.name() == "Style": 149 if self.isEndElement() and self.name() == "Style":
125 break 150 break
126
127 if self.isStartElement():
128 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial