E5XML/TemplatesReader.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 3178
f25fc1364c88
child 4021
195a471c327b
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class for reading an XML templates file.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
10 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
11
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from E5Gui.E5Application import e5App
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .Config import templatesFileFormatVersion
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .XMLStreamReaderBase import XMLStreamReaderBase
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
17
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class TemplatesReader(XMLStreamReaderBase):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class for reading an XML tasks file.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
22 supportedVersions = ["4.0"]
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
23
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
24 def __init__(self, device, viewer=None):
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param device reference to the I/O device to read from (QIODevice)
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param viewer reference to the template viewer object (TemplateViewer)
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 XMLStreamReaderBase.__init__(self, device)
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 if viewer:
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.viewer = viewer
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 else:
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.viewer = e5App().getObject("TemplateViewer")
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.version = ""
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.groupName = "DEFAULT"
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def readXML(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Public method to read and parse the XML document.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.readNext()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 if self.name() == "Templates":
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
49 self.version = self.attribute(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
50 "version", templatesFileFormatVersion)
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
51 if self.version not in self.supportedVersions:
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
52 self.raiseUnsupportedFormatVersion(self.version)
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 elif self.name() == "TemplateGroup":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__readTemplateGroup()
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
55 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
56 self.raiseUnexpectedStartTag(self.name())
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.showErrorMessage()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def __readTemplateGroup(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Private method to read a template group.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.groupName = self.attribute('name', "DEFAULT")
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 language = self.attribute('language', "All")
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.viewer.addGroup(self.groupName, language)
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.readNext()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if self.isEndElement() and self.name() == "TemplateGroup":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 break
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if self.name() == "Template":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__readTemplate()
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
76 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
77 self.raiseUnexpectedStartTag(self.name())
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def __readTemplate(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Private method to read the template definition.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 templateName = self.attribute('name', '')
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 templateDescription = ""
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 templateText = ""
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.readNext()
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
89 if self.isEndElement() and \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
90 self.name() == "Template" and \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
91 templateName:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
92 self.viewer.addEntry(self.groupName, templateName,
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 templateDescription, templateText,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
94 quiet=True)
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 break
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if self.name() == "TemplateDescription":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 templateDescription = self.readElementText()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 elif self.name() == "TemplateText":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 templateText = self.readElementText()
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
102 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
103 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial