58 |
60 |
59 @return dictionary containing the relevant data |
61 @return dictionary containing the relevant data |
60 """ |
62 """ |
61 if e5App().getObject("UserInterface").versionIsNewer('5.0.99', '20120101'): |
63 if e5App().getObject("UserInterface").versionIsNewer('5.0.99', '20120101'): |
62 return { |
64 return { |
63 "pyramidPage": \ |
65 "pyramidPage": [ |
64 [QCoreApplication.translate("ProjectPyramidPlugin", "Pyramid"), |
66 QCoreApplication.translate("ProjectPyramidPlugin", "Pyramid"), |
65 os.path.join("ProjectPyramid", "icons", |
67 os.path.join("ProjectPyramid", "icons", "pyramid.png"), |
66 "pyramid.png"), |
68 createPyramidPage, None, None], |
67 createPyramidPage, None, None], |
|
68 } |
69 } |
69 else: |
70 else: |
70 return {} |
71 return {} |
71 |
72 |
72 |
73 |
73 def apiFiles(language): |
74 def apiFiles(language): |
74 """ |
75 """ |
75 Module function to return the API files made available by this plugin. |
76 Module function to return the API files made available by this plugin. |
76 |
77 |
|
78 @param language language to get APIs for (string) |
77 @return list of API filenames (list of string) |
79 @return list of API filenames (list of string) |
78 """ |
80 """ |
79 if language in ["Python3", "Python2"]: |
81 if language in ["Python3", "Python2"]: |
80 apisDir = \ |
82 apisDir = \ |
81 os.path.join(os.path.dirname(__file__), "ProjectPyramid", "APIs") |
83 os.path.join(os.path.dirname(__file__), "ProjectPyramid", "APIs") |
120 self.__defaults = { |
122 self.__defaults = { |
121 "VirtualEnvironmentPy2": "", |
123 "VirtualEnvironmentPy2": "", |
122 "VirtualEnvironmentPy3": "", |
124 "VirtualEnvironmentPy3": "", |
123 "Python2ConsoleType": "python", |
125 "Python2ConsoleType": "python", |
124 "Python3ConsoleType": "python", |
126 "Python3ConsoleType": "python", |
125 "PyramidDocUrl": "http://docs.pylonsproject.org/en/latest/docs/pyramid.html", |
127 "PyramidDocUrl": "http://docs.pylonsproject.org/en/latest/" |
|
128 "docs/pyramid.html", |
126 "TranslationsEditor": "", |
129 "TranslationsEditor": "", |
127 } |
130 } |
128 if isWindowsPlatform(): |
131 if isWindowsPlatform(): |
129 self.__defaults["ConsoleCommand"] = "cmd.exe /c" |
132 self.__defaults["ConsoleCommand"] = "cmd.exe /c" |
130 elif isMacPlatform(): |
133 elif isMacPlatform(): |
185 |
189 |
186 self.__supportedVariants = self.__object.supportedPythonVariants() |
190 self.__supportedVariants = self.__object.supportedPythonVariants() |
187 |
191 |
188 if self.__supportedVariants: |
192 if self.__supportedVariants: |
189 try: |
193 try: |
190 self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"), |
194 self.__e5project.registerProjectType( |
|
195 "Pyramid", self.trUtf8("Pyramid"), |
191 self.fileTypesCallback, |
196 self.fileTypesCallback, |
192 lexerAssociationCallback=self.lexerAssociationCallback, |
197 lexerAssociationCallback=self.lexerAssociationCallback, |
193 binaryTranslationsCallback=self.binaryTranslationsCallback, |
198 binaryTranslationsCallback=self.binaryTranslationsCallback, |
194 progLanguages=self.__supportedVariants[:]) |
199 progLanguages=self.__supportedVariants[:]) |
195 except TypeError: |
200 except TypeError: |
196 # for backward compatibility |
201 # for backward compatibility |
197 self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"), |
202 self.__e5project.registerProjectType( |
|
203 "Pyramid", self.trUtf8("Pyramid"), |
198 self.fileTypesCallback, |
204 self.fileTypesCallback, |
199 lexerAssociationCallback=self.lexerAssociationCallback, |
205 lexerAssociationCallback=self.lexerAssociationCallback, |
200 binaryTranslationsCallback=self.binaryTranslationsCallback) |
206 binaryTranslationsCallback=self.binaryTranslationsCallback) |
201 |
207 |
202 from Project.ProjectBrowser import SourcesBrowserFlag, FormsBrowserFlag, \ |
208 from Project.ProjectBrowser import SourcesBrowserFlag, \ |
203 TranslationsBrowserFlag, OthersBrowserFlag |
209 FormsBrowserFlag, TranslationsBrowserFlag, OthersBrowserFlag |
204 Preferences.setProjectBrowserFlagsDefault("Pyramid", |
210 Preferences.setProjectBrowserFlagsDefault( |
205 SourcesBrowserFlag | \ |
211 "Pyramid", |
206 FormsBrowserFlag | \ |
212 SourcesBrowserFlag | FormsBrowserFlag | |
207 TranslationsBrowserFlag | \ |
213 TranslationsBrowserFlag | OthersBrowserFlag, |
208 OthersBrowserFlag, |
|
209 ) |
214 ) |
210 |
215 |
211 if self.__e5project.isOpen(): |
216 if self.__e5project.isOpen(): |
212 self.__projectOpened() |
217 self.__projectOpened() |
213 self.__object.projectOpenedHooks() |
218 self.__object.projectOpenedHooks() |
214 |
219 |
215 e5App().getObject("Project").projectOpened.connect(self.__projectOpened) |
220 e5App().getObject("Project").projectOpened.connect( |
216 e5App().getObject("Project").projectClosed.connect(self.__projectClosed) |
221 self.__projectOpened) |
217 e5App().getObject("Project").newProject.connect(self.__projectOpened) |
222 e5App().getObject("Project").projectClosed.connect( |
|
223 self.__projectClosed) |
|
224 e5App().getObject("Project").newProject.connect( |
|
225 self.__projectOpened) |
218 |
226 |
219 e5App().getObject("Project").projectOpenedHooks.connect( |
227 e5App().getObject("Project").projectOpenedHooks.connect( |
220 self.__object.projectOpenedHooks) |
228 self.__object.projectOpenedHooks) |
221 e5App().getObject("Project").projectClosedHooks.connect( |
229 e5App().getObject("Project").projectClosedHooks.connect( |
222 self.__object.projectClosedHooks) |
230 self.__object.projectClosedHooks) |
223 e5App().getObject("Project").newProjectHooks.connect( |
231 e5App().getObject("Project").newProjectHooks.connect( |
224 self.__object.projectOpenedHooks) |
232 self.__object.projectOpenedHooks) |
225 |
233 |
226 return None, True |
234 return None, True |
227 |
235 |
228 def deactivate(self): |
236 def deactivate(self): |
229 """ |
237 """ |
230 Public method to deactivate this plugin. |
238 Public method to deactivate this plugin. |
231 """ |
239 """ |
232 e5App().unregisterPluginObject("ProjectPyramid") |
240 e5App().unregisterPluginObject("ProjectPyramid") |
233 |
241 |
234 e5App().getObject("Project").projectOpened.disconnect(self.__projectOpened) |
242 e5App().getObject("Project").projectOpened.disconnect( |
235 e5App().getObject("Project").projectClosed.disconnect(self.__projectClosed) |
243 self.__projectOpened) |
236 e5App().getObject("Project").newProject.disconnect(self.__projectOpened) |
244 e5App().getObject("Project").projectClosed.disconnect( |
|
245 self.__projectClosed) |
|
246 e5App().getObject("Project").newProject.disconnect( |
|
247 self.__projectOpened) |
237 |
248 |
238 e5App().getObject("Project").projectOpenedHooks.disconnect( |
249 e5App().getObject("Project").projectOpenedHooks.disconnect( |
239 self.__object.projectOpenedHooks) |
250 self.__object.projectOpenedHooks) |
240 e5App().getObject("Project").projectClosedHooks.disconnect( |
251 e5App().getObject("Project").projectClosedHooks.disconnect( |
241 self.__object.projectClosedHooks) |
252 self.__object.projectClosedHooks) |
254 Private method to load the translation file. |
265 Private method to load the translation file. |
255 """ |
266 """ |
256 if self.__ui is not None: |
267 if self.__ui is not None: |
257 loc = self.__ui.getLocale() |
268 loc = self.__ui.getLocale() |
258 if loc and loc != "C": |
269 if loc and loc != "C": |
259 locale_dir = \ |
270 locale_dir = os.path.join( |
260 os.path.join(os.path.dirname(__file__), "ProjectPyramid", "i18n") |
271 os.path.dirname(__file__), "ProjectPyramid", "i18n") |
261 translation = "pyramid_%s" % loc |
272 translation = "pyramid_%s" % loc |
262 translator = QTranslator(None) |
273 translator = QTranslator(None) |
263 loaded = translator.load(translation, locale_dir) |
274 loaded = translator.load(translation, locale_dir) |
264 if loaded: |
275 if loaded: |
265 self.__translator = translator |
276 self.__translator = translator |
266 e5App().installTranslator(self.__translator) |
277 e5App().installTranslator(self.__translator) |
267 else: |
278 else: |
268 print("Warning: translation file '{0}' could not be loaded.".format( |
279 print("Warning: translation file '{0}' could not be" |
269 translation)) |
280 " loaded.".format(translation)) |
270 print("Using default.") |
281 print("Using default.") |
271 |
282 |
272 def __projectOpened(self): |
283 def __projectOpened(self): |
273 """ |
284 """ |
274 Private slot to handle the projectOpened signal. |
285 Private slot to handle the projectOpened signal. |
275 """ |
286 """ |
276 if self.__e5project.getProjectType() == "Pyramid": |
287 if self.__e5project.getProjectType() == "Pyramid": |
277 projectAct = self.__ui.getMenuBarAction("project") |
288 projectAct = self.__ui.getMenuBarAction("project") |
278 actions = self.__ui.menuBar().actions() |
289 actions = self.__ui.menuBar().actions() |
279 insertAct = actions[actions.index(projectAct) + 1] |
290 insertAct = actions[actions.index(projectAct) + 1] |
280 self.__mainAct = self.__ui.menuBar().insertMenu(insertAct, self.__mainMenu) |
291 self.__mainAct = self.__ui.menuBar().insertMenu( |
|
292 insertAct, self.__mainMenu) |
281 |
293 |
282 def __projectClosed(self): |
294 def __projectClosed(self): |
283 """ |
295 """ |
284 Private slot to handle the projectClosed signal. |
296 Private slot to handle the projectClosed signal. |
285 """ |
297 """ |
339 def getPreferences(self, key): |
353 def getPreferences(self, key): |
340 """ |
354 """ |
341 Public method to retrieve the various settings. |
355 Public method to retrieve the various settings. |
342 |
356 |
343 @param key the key of the value to get |
357 @param key the key of the value to get |
344 @param prefClass preferences class used as the storage area |
|
345 @return the requested setting |
358 @return the requested setting |
346 """ |
359 """ |
347 return Preferences.Prefs.settings.value(self.PreferencesKey + "/" + key, |
360 return Preferences.Prefs.settings.value( |
348 self.__defaults[key]) |
361 self.PreferencesKey + "/" + key, self.__defaults[key]) |
349 |
362 |
350 def setPreferences(self, key, value): |
363 def setPreferences(self, key, value): |
351 """ |
364 """ |
352 Public method to store the various settings. |
365 Public method to store the various settings. |
353 |
366 |
354 @param key the key of the setting to be set (string) |
367 @param key the key of the setting to be set (string) |
355 @param value the value to be set |
368 @param value the value to be set |
356 @param prefClass preferences class used as the storage area |
369 """ |
357 """ |
370 Preferences.Prefs.settings.setValue( |
358 Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) |
371 self.PreferencesKey + "/" + key, value) |
359 |
372 |
360 if key in ["VirtualEnvironmentPy2", "VirtualEnvironmentPy3"]: |
373 if key in ["VirtualEnvironmentPy2", "VirtualEnvironmentPy3"]: |
361 self.__reregisterProjectType() |
374 self.__reregisterProjectType() |
362 elif key == "TranslationsEditor": |
375 elif key == "TranslationsEditor": |
363 if self.__object: |
376 if self.__object: |
374 |
387 |
375 # step 2: register again with new language settings |
388 # step 2: register again with new language settings |
376 self.__supportedVariants = supportedVariants |
389 self.__supportedVariants = supportedVariants |
377 if self.__supportedVariants: |
390 if self.__supportedVariants: |
378 try: |
391 try: |
379 self.__e5project.registerProjectType("Pyramid", |
392 self.__e5project.registerProjectType( |
|
393 "Pyramid", |
380 self.trUtf8("Pyramid"), self.fileTypesCallback, |
394 self.trUtf8("Pyramid"), self.fileTypesCallback, |
381 lexerAssociationCallback=self.lexerAssociationCallback, |
395 lexerAssociationCallback=self.lexerAssociationCallback, |
382 binaryTranslationsCallback=self.binaryTranslationsCallback, |
396 binaryTranslationsCallback= |
|
397 self.binaryTranslationsCallback, |
383 progLanguages=self.__supportedVariants[:]) |
398 progLanguages=self.__supportedVariants[:]) |
384 except TypeError: |
399 except TypeError: |
385 # for backward compatibility |
400 # for backward compatibility |
386 self.__e5project.registerProjectType("Pyramid", |
401 self.__e5project.registerProjectType( |
|
402 "Pyramid", |
387 self.trUtf8("Pyramid"), self.fileTypesCallback, |
403 self.trUtf8("Pyramid"), self.fileTypesCallback, |
388 lexerAssociationCallback=self.lexerAssociationCallback, |
404 lexerAssociationCallback=self.lexerAssociationCallback, |
389 binaryTranslationsCallback=self.binaryTranslationsCallback) |
405 binaryTranslationsCallback= |
|
406 self.binaryTranslationsCallback) |