eric6/E5XML/ShortcutsReader.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
permissions
-rw-r--r--

Updated copyright for 2021.

597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class for reading an XML shortcuts file.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from .Config import shortcutsFileFormatVersion
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from .XMLStreamReaderBase import XMLStreamReaderBase
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
13
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 class ShortcutsReader(XMLStreamReaderBase):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 Class for reading an XML shortcuts file.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 supportedVersions = ["3.6"]
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def __init__(self, device):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Constructor
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param device reference to the I/O device to read from (QIODevice)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 XMLStreamReaderBase.__init__(self, device)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.version = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.shortcuts = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
31 def readXML(self):
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Public method to read and parse the XML document.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 if self.name() == "Shortcuts":
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
39 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
40 "version", shortcutsFileFormatVersion)
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 if self.version not in self.supportedVersions:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.raiseUnsupportedFormatVersion(self.version)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 elif self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__readShortCut()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.raiseUnexpectedStartTag(self.name())
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
48 self.showErrorMessage()
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def __readShortCut(self):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Private method to read the shortcut data.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 category = self.attribute("category")
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 name = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 accel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 altAccel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 if self.isEndElement() and self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if category:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if category not in self.shortcuts:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.shortcuts[category] = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.shortcuts[category][name] = (accel, altAccel)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 break
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 if self.name() == "Name":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 name = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 elif self.name() == "Accel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 accel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 elif self.name() == "AltAccel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 altAccel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.raiseUnexpectedStartTag(self.name())
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def getShortcuts(self):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Public method to retrieve the shortcuts.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @return Dictionary of dictionaries of shortcuts. The keys of the
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 dictionary are the categories, the values are dictionaries.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 These dictionaries have the shortcut name as their key and
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 a tuple of accelerators as their value.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 return self.shortcuts

eric ide

mercurial