src/eric7/EricXML/SpellCheckDictionariesReader.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class SpellCheckDictionariesReader(XMLStreamReaderBase): 16 class SpellCheckDictionariesReader(XMLStreamReaderBase):
17 """ 17 """
18 Class to read the web browser spell check dictionaries list file. 18 Class to read the web browser spell check dictionaries list file.
19 """ 19 """
20 supportedVersions = ["1.0", ] 20
21 21 supportedVersions = [
22 "1.0",
23 ]
24
22 def __init__(self, data, entryCallback): 25 def __init__(self, data, entryCallback):
23 """ 26 """
24 Constructor 27 Constructor
25 28
26 @param data reference to the data array to read XML from (QByteArray) 29 @param data reference to the data array to read XML from (QByteArray)
27 @param entryCallback reference to a function to be called once the 30 @param entryCallback reference to a function to be called once the
28 data for a dictionary has been read (function) 31 data for a dictionary has been read (function)
29 """ 32 """
30 XMLStreamReaderBase.__init__(self, data) 33 XMLStreamReaderBase.__init__(self, data)
31 34
32 self.__entryCallback = entryCallback 35 self.__entryCallback = entryCallback
33 36
34 self.version = "" 37 self.version = ""
35 self.baseUrl = "" 38 self.baseUrl = ""
36 39
37 def readXML(self): 40 def readXML(self):
38 """ 41 """
39 Public method to read and parse the XML document. 42 Public method to read and parse the XML document.
40 """ 43 """
41 while not self.atEnd(): 44 while not self.atEnd():
42 self.readNext() 45 self.readNext()
43 if self.isStartElement(): 46 if self.isStartElement():
44 if self.name() == "Dictionaries": 47 if self.name() == "Dictionaries":
45 self.version = self.attribute( 48 self.version = self.attribute(
46 "version", 49 "version", dictionariesListFileFormatVersion
47 dictionariesListFileFormatVersion) 50 )
48 self.baseUrl = self.attribute("baseurl", "") 51 self.baseUrl = self.attribute("baseurl", "")
49 if self.version not in self.supportedVersions: 52 if self.version not in self.supportedVersions:
50 self.raiseUnsupportedFormatVersion(self.version) 53 self.raiseUnsupportedFormatVersion(self.version)
51 elif self.name() == "DictionariesUrl": 54 elif self.name() == "DictionariesUrl":
52 url = self.readElementText() 55 url = self.readElementText()
53 Preferences.setWebBrowser("SpellCheckDictionariesUrl", url) 56 Preferences.setWebBrowser("SpellCheckDictionariesUrl", url)
54 elif self.name() == "Dictionary": 57 elif self.name() == "Dictionary":
55 self.__readDictionary() 58 self.__readDictionary()
56 else: 59 else:
57 self._skipUnknownElement() 60 self._skipUnknownElement()
58 61
59 self.showErrorMessage() 62 self.showErrorMessage()
60 63
61 def __readDictionary(self): 64 def __readDictionary(self):
62 """ 65 """
63 Private method to read the plug-in info. 66 Private method to read the plug-in info.
64 """ 67 """
65 dictionaryInfo = {"short": "", 68 dictionaryInfo = {
66 "filename": "", 69 "short": "",
67 "documentation": "", 70 "filename": "",
68 "locales": [], 71 "documentation": "",
69 } 72 "locales": [],
70 73 }
74
71 while not self.atEnd(): 75 while not self.atEnd():
72 self.readNext() 76 self.readNext()
73 if self.isEndElement() and self.name() == "Dictionary": 77 if self.isEndElement() and self.name() == "Dictionary":
74 self.__entryCallback( 78 self.__entryCallback(
75 dictionaryInfo["short"], dictionaryInfo["filename"], 79 dictionaryInfo["short"],
80 dictionaryInfo["filename"],
76 self.baseUrl + dictionaryInfo["filename"], 81 self.baseUrl + dictionaryInfo["filename"],
77 dictionaryInfo["documentation"], dictionaryInfo["locales"]) 82 dictionaryInfo["documentation"],
83 dictionaryInfo["locales"],
84 )
78 break 85 break
79 86
80 if self.isStartElement(): 87 if self.isStartElement():
81 if self.name() == "Short": 88 if self.name() == "Short":
82 dictionaryInfo["short"] = self.readElementText() 89 dictionaryInfo["short"] = self.readElementText()
83 elif self.name() == "Filename": 90 elif self.name() == "Filename":
84 dictionaryInfo["filename"] = self.readElementText() 91 dictionaryInfo["filename"] = self.readElementText()

eric ide

mercurial