eric6/E5XML/TemplatesReader.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7780
41420f82c0ac
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7253
diff changeset
3 # Copyright (c) 2010 - 2020 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
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
10
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from .Config import templatesFileFormatVersion
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .XMLStreamReaderBase import XMLStreamReaderBase
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
14
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class TemplatesReader(XMLStreamReaderBase):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 Class for reading an XML tasks file.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
19 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
20
6425
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
21 def __init__(self, device, viewer):
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @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
26 @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
27 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 XMLStreamReaderBase.__init__(self, device)
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
6425
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
30 self.__viewer = viewer
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.version = ""
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.groupName = "DEFAULT"
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def readXML(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 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
38 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.readNext()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43 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
44 "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
45 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
46 self.raiseUnsupportedFormatVersion(self.version)
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 elif self.name() == "TemplateGroup":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 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
49 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
50 self.raiseUnexpectedStartTag(self.name())
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.showErrorMessage()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def __readTemplateGroup(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Private method to read a template group.
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.groupName = self.attribute('name', "DEFAULT")
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 language = self.attribute('language', "All")
6425
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 self.__viewer.addGroup(self.groupName, language)
587
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 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.readNext()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if self.isEndElement() and self.name() == "TemplateGroup":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 break
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if self.name() == "Template":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 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
70 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
71 self.raiseUnexpectedStartTag(self.name())
587
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 def __readTemplate(self):
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private method to read the template definition.
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 templateName = self.attribute('name', '')
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 templateDescription = ""
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 templateText = ""
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 while not self.atEnd():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.readNext()
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
83 if (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
84 self.isEndElement() and
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
85 self.name() == "Template" and
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
86 templateName
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
87 ):
6425
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
88 self.__viewer.addEntry(self.groupName, templateName,
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
89 templateDescription, templateText,
2f37e52a6c70 TemplatesReader: changed code to always require a reference to a templates viewer instance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
90 quiet=True)
587
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 break
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 if self.isStartElement():
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if self.name() == "TemplateDescription":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 templateDescription = self.readElementText()
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 elif self.name() == "TemplateText":
3078a9781573 Migrated the templates handler to templates reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 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
98 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
99 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial