src/eric7/EricXML/ShortcutsReader.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
13 13
14 class ShortcutsReader(XMLStreamReaderBase): 14 class ShortcutsReader(XMLStreamReaderBase):
15 """ 15 """
16 Class for reading an XML shortcuts file. 16 Class for reading an XML shortcuts file.
17 """ 17 """
18
18 supportedVersions = ["3.6"] 19 supportedVersions = ["3.6"]
19 20
20 def __init__(self, device): 21 def __init__(self, device):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param device reference to the I/O device to read from (QIODevice) 25 @param device reference to the I/O device to read from (QIODevice)
25 """ 26 """
26 XMLStreamReaderBase.__init__(self, device) 27 XMLStreamReaderBase.__init__(self, device)
27 28
28 self.version = "" 29 self.version = ""
29 self.shortcuts = {} 30 self.shortcuts = {}
30 31
31 def readXML(self): 32 def readXML(self):
32 """ 33 """
33 Public method to read and parse the XML document. 34 Public method to read and parse the XML document.
34 """ 35 """
35 while not self.atEnd(): 36 while not self.atEnd():
36 self.readNext() 37 self.readNext()
37 if self.isStartElement(): 38 if self.isStartElement():
38 if self.name() == "Shortcuts": 39 if self.name() == "Shortcuts":
39 self.version = self.attribute( 40 self.version = self.attribute("version", shortcutsFileFormatVersion)
40 "version", shortcutsFileFormatVersion)
41 if self.version not in self.supportedVersions: 41 if self.version not in self.supportedVersions:
42 self.raiseUnsupportedFormatVersion(self.version) 42 self.raiseUnsupportedFormatVersion(self.version)
43 elif self.name() == "Shortcut": 43 elif self.name() == "Shortcut":
44 self.__readShortCut() 44 self.__readShortCut()
45 else: 45 else:
46 self.raiseUnexpectedStartTag(self.name()) 46 self.raiseUnexpectedStartTag(self.name())
47 47
48 self.showErrorMessage() 48 self.showErrorMessage()
49 49
50 def __readShortCut(self): 50 def __readShortCut(self):
51 """ 51 """
52 Private method to read the shortcut data. 52 Private method to read the shortcut data.
53 """ 53 """
54 category = self.attribute("category") 54 category = self.attribute("category")
55 name = "" 55 name = ""
56 accel = "" 56 accel = ""
57 altAccel = "" 57 altAccel = ""
58 58
59 while not self.atEnd(): 59 while not self.atEnd():
60 self.readNext() 60 self.readNext()
61 if self.isEndElement() and self.name() == "Shortcut": 61 if self.isEndElement() and self.name() == "Shortcut":
62 if category: 62 if category:
63 if category not in self.shortcuts: 63 if category not in self.shortcuts:
64 self.shortcuts[category] = {} 64 self.shortcuts[category] = {}
65 self.shortcuts[category][name] = (accel, altAccel) 65 self.shortcuts[category][name] = (accel, altAccel)
66 break 66 break
67 67
68 if self.isStartElement(): 68 if self.isStartElement():
69 if self.name() == "Name": 69 if self.name() == "Name":
70 name = self.readElementText() 70 name = self.readElementText()
71 elif self.name() == "Accel": 71 elif self.name() == "Accel":
72 accel = self.readElementText() 72 accel = self.readElementText()
73 elif self.name() == "AltAccel": 73 elif self.name() == "AltAccel":
74 altAccel = self.readElementText() 74 altAccel = self.readElementText()
75 else: 75 else:
76 self.raiseUnexpectedStartTag(self.name()) 76 self.raiseUnexpectedStartTag(self.name())
77 77
78 def getShortcuts(self): 78 def getShortcuts(self):
79 """ 79 """
80 Public method to retrieve the shortcuts. 80 Public method to retrieve the shortcuts.
81 81
82 @return Dictionary of dictionaries of shortcuts. The keys of the 82 @return Dictionary of dictionaries of shortcuts. The keys of the
83 dictionary are the categories, the values are dictionaries. 83 dictionary are the categories, the values are dictionaries.
84 These dictionaries have the shortcut name as their key and 84 These dictionaries have the shortcut name as their key and
85 a tuple of accelerators as their value. 85 a tuple of accelerators as their value.
86 """ 86 """

eric ide

mercurial