PluginProjectPyramid.py

changeset 44
989c961c33ab
parent 39
94e448a362b2
child 48
c313efdb01de
diff -r 14e0bd707f16 -r 989c961c33ab PluginProjectPyramid.py
--- a/PluginProjectPyramid.py	Tue Mar 26 16:47:15 2013 +0100
+++ b/PluginProjectPyramid.py	Mon Apr 01 19:40:41 2013 +0200
@@ -26,7 +26,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "1.1.1"
+version = "1.2.0"
 className = "ProjectPyramidPlugin"
 packageName = "ProjectPyramid"
 shortDescription = "Project support for Pyramid projects."
@@ -144,6 +144,8 @@
         self.__mainMenu = None
         
         self.__e5project = e5App().getObject("Project")
+        
+        self.__supportedVariants = []
     
     def __checkVersions(self):
         """
@@ -180,18 +182,21 @@
         
         self.__mainMenu = self.__object.initMenu()
         
-        try:
-            self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"),
-                self.fileTypesCallback,
-                lexerAssociationCallback=self.lexerAssociationCallback,
-                binaryTranslationsCallback=self.binaryTranslationsCallback,
-                progLanguages=["Python2", "Python3"])
-        except TypeError:
-            # for backward compatibility
-            self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"),
-                self.fileTypesCallback,
-                lexerAssociationCallback=self.lexerAssociationCallback,
-                binaryTranslationsCallback=self.binaryTranslationsCallback)
+        self.__supportedVariants = self.__object.supportedPythonVariants()
+        
+        if self.__supportedVariants:
+            try:
+                self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"),
+                    self.fileTypesCallback,
+                    lexerAssociationCallback=self.lexerAssociationCallback,
+                    binaryTranslationsCallback=self.binaryTranslationsCallback,
+                    progLanguages=self.__supportedVariants[:])
+            except TypeError:
+                # for backward compatibility
+                self.__e5project.registerProjectType("Pyramid", self.trUtf8("Pyramid"),
+                    self.fileTypesCallback,
+                    lexerAssociationCallback=self.lexerAssociationCallback,
+                    binaryTranslationsCallback=self.binaryTranslationsCallback)
         
         from Project.ProjectBrowser import SourcesBrowserFlag, FormsBrowserFlag, \
             TranslationsBrowserFlag, OthersBrowserFlag
@@ -350,3 +355,31 @@
         @param prefClass preferences class used as the storage area
         """
         Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value)
+        
+        if key in ["VirtualEnvironmentPy2", "VirtualEnvironmentPy3"]:
+            self.__reregisterProjectType()
+    
+    def __reregisterProjectType(self):
+        """
+        Private method to re-register the project type.
+        """
+        supportedVariants = self.__object.supportedPythonVariants()
+        if supportedVariants != self.__supportedVariants:
+            # step 1: unregister
+            self.__e5project.unregisterProjectType("Pyramid")
+            
+            # step 2: register again with new language settings
+            self.__supportedVariants = supportedVariants
+            if self.__supportedVariants:
+                try:
+                    self.__e5project.registerProjectType("Pyramid",
+                        self.trUtf8("Pyramid"), self.fileTypesCallback,
+                        lexerAssociationCallback=self.lexerAssociationCallback,
+                        binaryTranslationsCallback=self.binaryTranslationsCallback,
+                        progLanguages=self.__supportedVariants[:])
+                except TypeError:
+                    # for backward compatibility
+                    self.__e5project.registerProjectType("Pyramid",
+                        self.trUtf8("Pyramid"), self.fileTypesCallback,
+                        lexerAssociationCallback=self.lexerAssociationCallback,
+                        binaryTranslationsCallback=self.binaryTranslationsCallback)

eric ide

mercurial