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

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
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>
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
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
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .Config import shortcutsFileFormatVersion
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .XMLStreamReaderBase import XMLStreamReaderBase
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
15
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class ShortcutsReader(XMLStreamReaderBase):
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 Class for reading an XML shortcuts file.
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 supportedVersions = ["3.6"]
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 def __init__(self, device):
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 Constructor
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 @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
27 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 XMLStreamReaderBase.__init__(self, device)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.version = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.shortcuts = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
33 def readXML(self):
597
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 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
36 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 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
41 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
42 "version", shortcutsFileFormatVersion)
597
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if self.version not in self.supportedVersions:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.raiseUnsupportedFormatVersion(self.version)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 elif self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__readShortCut()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.raiseUnexpectedStartTag(self.name())
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
598
76c36b6ebbdb Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 597
diff changeset
50 self.showErrorMessage()
597
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 def __readShortCut(self):
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 Private method to read the shortcut data.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 category = self.attribute("category")
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 name = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 accel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 altAccel = ""
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 while not self.atEnd():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.readNext()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if self.isEndElement() and self.name() == "Shortcut":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if category:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 if category not in self.shortcuts:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.shortcuts[category] = {}
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.shortcuts[category][name] = (accel, altAccel)
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 break
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if self.isStartElement():
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 if self.name() == "Name":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 name = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 elif self.name() == "Accel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 accel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 elif self.name() == "AltAccel":
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 altAccel = self.readElementText()
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 else:
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.raiseUnexpectedStartTag(self.name())
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 def getShortcuts(self):
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 Public method to retrieve the shortcuts.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @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
85 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
86 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
87 a tuple of accelerators as their value.
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
86d4732c5084 Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return self.shortcuts

eric ide

mercurial