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