eric6/E5XML/ShortcutsReader.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.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2010 - 2020 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
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
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from .Config import shortcutsFileFormatVersion
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .XMLStreamReaderBase import XMLStreamReaderBase
86d4732c5084 Migrated the shortcuts handler to shortcuts 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
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class ShortcutsReader(XMLStreamReaderBase):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 Class for reading an XML shortcuts file.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 supportedVersions = ["3.6"]
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, device):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @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
26 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 XMLStreamReaderBase.__init__(self, device)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.version = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.shortcuts = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
32 def readXML(self):
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 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
35 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 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
40 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
41 "version", shortcutsFileFormatVersion)
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 if self.version not in self.supportedVersions:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.raiseUnsupportedFormatVersion(self.version)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 elif self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.__readShortCut()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.raiseUnexpectedStartTag(self.name())
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
49 self.showErrorMessage()
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 def __readShortCut(self):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Private method to read the shortcut data.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 category = self.attribute("category")
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 name = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 accel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 altAccel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if self.isEndElement() and self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if category:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if category not in self.shortcuts:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.shortcuts[category] = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.shortcuts[category][name] = (accel, altAccel)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 break
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if self.name() == "Name":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 name = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 elif self.name() == "Accel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 accel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 elif self.name() == "AltAccel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 altAccel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.raiseUnexpectedStartTag(self.name())
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def getShortcuts(self):
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Public method to retrieve the shortcuts.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @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
84 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
85 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
86 a tuple of accelerators as their value.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 return self.shortcuts

eric ide

mercurial