QScintilla/APIsManager.py

changeset 3011
18292228c724
parent 2614
9c49b4419ea7
child 3057
10516539f238
child 3096
23856c207f81
equal deleted inserted replaced
3010:befeff46ec0f 3011:18292228c724
19 19
20 class APIs(QObject): 20 class APIs(QObject):
21 """ 21 """
22 Class implementing an API storage entity. 22 Class implementing an API storage entity.
23 23
24 @signal apiPreparationFinished() emitted after the API preparation has finished 24 @signal apiPreparationFinished() emitted after the API preparation has
25 @signal apiPreparationCancelled() emitted after the API preparation has been cancelled 25 finished
26 @signal apiPreparationStarted() emitted after the API preparation has started 26 @signal apiPreparationCancelled() emitted after the API preparation has
27 been cancelled
28 @signal apiPreparationStarted() emitted after the API preparation has
29 started
27 """ 30 """
28 apiPreparationFinished = pyqtSignal() 31 apiPreparationFinished = pyqtSignal()
29 apiPreparationCancelled = pyqtSignal() 32 apiPreparationCancelled = pyqtSignal()
30 apiPreparationStarted = pyqtSignal() 33 apiPreparationStarted = pyqtSignal()
31 34
49 self.__apifiles.sort() 52 self.__apifiles.sort()
50 if self.__lexer is None: 53 if self.__lexer is None:
51 self.__apis = None 54 self.__apis = None
52 else: 55 else:
53 self.__apis = QsciAPIs(self.__lexer) 56 self.__apis = QsciAPIs(self.__lexer)
54 self.__apis.apiPreparationFinished.connect(self.__apiPreparationFinished) 57 self.__apis.apiPreparationFinished.connect(
55 self.__apis.apiPreparationCancelled.connect(self.__apiPreparationCancelled) 58 self.__apiPreparationFinished)
56 self.__apis.apiPreparationStarted.connect(self.__apiPreparationStarted) 59 self.__apis.apiPreparationCancelled.connect(
60 self.__apiPreparationCancelled)
61 self.__apis.apiPreparationStarted.connect(
62 self.__apiPreparationStarted)
57 self.__loadAPIs() 63 self.__loadAPIs()
58 64
59 def __loadAPIs(self): 65 def __loadAPIs(self):
60 """ 66 """
61 Private method to load the APIs. 67 Private method to load the APIs.
62 """ 68 """
63 if self.__apis.isPrepared(): 69 if self.__apis.isPrepared():
64 # load a prepared API file 70 # load a prepared API file
65 if not self.__forPreparation and Preferences.getEditor("AutoPrepareAPIs"): 71 if not self.__forPreparation and \
72 Preferences.getEditor("AutoPrepareAPIs"):
66 self.prepareAPIs() 73 self.prepareAPIs()
67 self.__apis.loadPrepared() 74 self.__apis.loadPrepared()
68 else: 75 else:
69 # load the raw files and prepare the API file 76 # load the raw files and prepare the API file
70 if not self.__forPreparation and Preferences.getEditor("AutoPrepareAPIs"): 77 if not self.__forPreparation and \
78 Preferences.getEditor("AutoPrepareAPIs"):
71 self.prepareAPIs(ondemand=True) 79 self.prepareAPIs(ondemand=True)
72 80
73 def reloadAPIs(self): 81 def reloadAPIs(self):
74 """ 82 """
75 Public method to reload the API information. 83 Public method to reload the API information.
76 """ 84 """
77 if not self.__forPreparation and Preferences.getEditor("AutoPrepareAPIs"): 85 if not self.__forPreparation and \
86 Preferences.getEditor("AutoPrepareAPIs"):
78 self.prepareAPIs() 87 self.prepareAPIs()
79 self.__loadAPIs() 88 self.__loadAPIs()
80 89
81 def getQsciAPIs(self): 90 def getQsciAPIs(self):
82 """ 91 """
83 Public method to get a reference to QsciAPIs object. 92 Public method to get a reference to QsciAPIs object.
84 93
85 @return reference to the QsciAPIs object (QsciAPIs) 94 @return reference to the QsciAPIs object (QsciAPIs)
86 """ 95 """
87 if not self.__forPreparation and Preferences.getEditor("AutoPrepareAPIs"): 96 if not self.__forPreparation and \
97 Preferences.getEditor("AutoPrepareAPIs"):
88 self.prepareAPIs() 98 self.prepareAPIs()
89 return self.__apis 99 return self.__apis
90 100
91 def __apiPreparationFinished(self): 101 def __apiPreparationFinished(self):
92 """ 102 """
96 self.__inPreparation = False 106 self.__inPreparation = False
97 self.apiPreparationFinished.emit() 107 self.apiPreparationFinished.emit()
98 108
99 def __apiPreparationCancelled(self): 109 def __apiPreparationCancelled(self):
100 """ 110 """
101 Private method called, after the API preparation process has been cancelled. 111 Private method called, after the API preparation process has been
112 cancelled.
102 """ 113 """
103 self.__inPreparation = False 114 self.__inPreparation = False
104 self.apiPreparationCancelled.emit() 115 self.apiPreparationCancelled.emit()
105 116
106 def __apiPreparationStarted(self): 117 def __apiPreparationStarted(self):
130 preparedAPIsInfo = QFileInfo(preparedAPIs) 141 preparedAPIsInfo = QFileInfo(preparedAPIs)
131 if not preparedAPIsInfo.exists(): 142 if not preparedAPIsInfo.exists():
132 needsPreparation = True 143 needsPreparation = True
133 else: 144 else:
134 preparedAPIsTime = preparedAPIsInfo.lastModified() 145 preparedAPIsTime = preparedAPIsInfo.lastModified()
135 apifiles = sorted(Preferences.getEditorAPI(self.__language)) 146 apifiles = sorted(
147 Preferences.getEditorAPI(self.__language))
136 if self.__apifiles != apifiles: 148 if self.__apifiles != apifiles:
137 needsPreparation = True 149 needsPreparation = True
138 for apifile in apifiles: 150 for apifile in apifiles:
139 if QFileInfo(apifile).lastModified() > preparedAPIsTime: 151 if QFileInfo(apifile).lastModified() > \
152 preparedAPIsTime:
140 needsPreparation = True 153 needsPreparation = True
141 break 154 break
142 155
143 if needsPreparation: 156 if needsPreparation:
144 # do the preparation 157 # do the preparation
164 177
165 @return list of installed API files (list of strings) 178 @return list of installed API files (list of strings)
166 """ 179 """
167 if self.__apis is not None: 180 if self.__apis is not None:
168 if Globals.isWindowsPlatform(): 181 if Globals.isWindowsPlatform():
169 qsciPath = os.path.join(Globals.getPyQt4ModulesDirectory(), "qsci") 182 qsciPath = os.path.join(
183 Globals.getPyQt4ModulesDirectory(), "qsci")
170 if os.path.exists(qsciPath): 184 if os.path.exists(qsciPath):
171 # it's the installer 185 # it's the installer
172 apidir = os.path.join(qsciPath, "api", self.__lexer.lexer()) 186 apidir = os.path.join(qsciPath, "api",
187 self.__lexer.lexer())
173 fnames = [] 188 fnames = []
174 filist = QDir(apidir).entryInfoList(["*.api"], QDir.Files, 189 filist = QDir(apidir).entryInfoList(["*.api"], QDir.Files,
175 QDir.IgnoreCase) 190 QDir.IgnoreCase)
176 for fi in filist: 191 for fi in filist:
177 fnames.append(fi.absoluteFilePath()) 192 fnames.append(fi.absoluteFilePath())
219 def getAPIs(self, language, forPreparation=False): 234 def getAPIs(self, language, forPreparation=False):
220 """ 235 """
221 Public method to get an apis object for autocompletion/calltips. 236 Public method to get an apis object for autocompletion/calltips.
222 237
223 This method creates and loads an APIs object dynamically upon request. 238 This method creates and loads an APIs object dynamically upon request.
224 This saves memory for languages, that might not be needed at the moment. 239 This saves memory for languages, that might not be needed at the
240 moment.
225 241
226 @param language the language of the requested api object (string) 242 @param language the language of the requested api object (string)
227 @param forPreparation flag indicating the requested api object is just needed 243 @param forPreparation flag indicating the requested api object is just
228 for a preparation process (boolean) 244 needed for a preparation process (boolean)
229 @return the apis object (APIs) 245 @return the apis object (APIs)
230 """ 246 """
231 if forPreparation: 247 if forPreparation:
232 return APIs(language, forPreparation=forPreparation) 248 return APIs(language, forPreparation=forPreparation)
233 else: 249 else:

eric ide

mercurial