E5XML/HighlightingStylesReader.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3656
441956d8fce5
child 4021
195a471c327b
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 Module implementing a class for reading a highlighting styles XML file.
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3058
diff changeset
11 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
12
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
13 from PyQt5.QtGui import QColor, QFont
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Config import highlightingStylesFileFormatVersion
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .XMLStreamReaderBase import XMLStreamReaderBase
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
18
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class HighlightingStylesReader(XMLStreamReaderBase):
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class for reading a highlighting styles XML file.
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 supportedVersions = ["4.3"]
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self, device, lexers):
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param device reference to the I/O device to read from (QIODevice)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param lexers list of lexer objects for which to export the styles
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 XMLStreamReaderBase.__init__(self, device)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.lexers = lexers
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.version = ""
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def readXML(self):
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Public method to read and parse the XML document.
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 while not self.atEnd():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.readNext()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 if self.isStartElement():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 if self.name() == "HighlightingStyles":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
46 self.version = self.attribute(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
47 "version",
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 highlightingStylesFileFormatVersion)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 if self.version not in self.supportedVersions:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.raiseUnsupportedFormatVersion(self.version)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 elif self.name() == "Lexer":
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__readLexer()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.raiseUnexpectedStartTag(self.name())
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.showErrorMessage()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def __readLexer(self):
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Private method to read the lexer info.
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 language = self.attribute("name")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if language and language in self.lexers:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 lexer = self.lexers[language]
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 lexer = None
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 while not self.atEnd():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.readNext()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if self.isEndElement() and self.name() == "Lexer":
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 break
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if self.isStartElement():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if self.name() == "Style":
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__readStyle(lexer)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.raiseUnexpectedStartTag(self.name())
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def __readStyle(self, lexer):
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Private method to read the style info.
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param lexer reference to the lexer object
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 """
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if lexer is not None:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 style = self.attribute("style")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if style:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 style = int(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 color = self.attribute("color")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if color:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 color = QColor(color)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 color = lexer.defaultColor(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 lexer.setColor(color, style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 paper = self.attribute("paper")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if paper:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 paper = QColor(paper)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 paper = lexer.defaultPaper(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 lexer.setPaper(paper, style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 fontStr = self.attribute("font")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 if fontStr:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 font = QFont()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 font.fromString(fontStr)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 font = lexer.defaultFont(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 lexer.setFont(font, style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 eolfill = self.attribute("eolfill")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 if eolfill:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 eolfill = self.toBool(eolfill)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 if eolfill is None:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 eolfill = lexer.defaulEolFill(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 else:
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 eolfill = lexer.defaulEolFill(style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 lexer.setEolFill(eolfill, style)
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 while not self.atEnd():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.readNext()
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 if self.isEndElement() and self.name() == "Style":
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 break
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if self.isStartElement():
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial