AssistantEric/APIsManager.py

changeset 54
89d28458ff40
parent 50
005b6127b978
child 59
2b361d34d241
diff -r cc91f2132635 -r 89d28458ff40 AssistantEric/APIsManager.py
--- a/AssistantEric/APIsManager.py	Sun Feb 05 16:31:50 2012 +0100
+++ b/AssistantEric/APIsManager.py	Sat May 19 18:32:26 2012 +0200
@@ -16,6 +16,7 @@
 from E5Gui.E5Application import e5App
 
 import QScintilla.Lexers
+from QScintilla.Editor import Editor
 
 from DocumentationTools.APIGenerator import APIGenerator
 import Utilities.ModuleParser
@@ -143,6 +144,31 @@
         if loadTime < modTime:
             self.__loadApiFile(apiFile)
     
+    def __classesAttributesApi(self, module):
+        """
+        Private method to generate class api section for class attributes.
+        
+        @param module module object to get the info from (Module)
+        @return API information (list of strings)
+        """
+        api = []
+        modulePath = module.name.split('.')
+        moduleName = "{0}.".format('.'.join(modulePath))
+        
+        for className in sorted(module.classes.keys()):
+            _class = module.classes[className]
+            classNameStr = "{0}{1}.".format(moduleName, className)
+            for variable in sorted(_class.attributes.keys()):
+                if not _class.attributes[variable].isPrivate():
+                    if _class.attributes[variable].isPublic():
+                        id = Editor.AttributeID
+                    elif _class.attributes[variable].isProtected():
+                        id = Editor.AttributeProtectedID
+                    else:
+                        id = Editor.AttributePrivateID
+                    api.append('{0}{1}?{2:d}'.format(classNameStr, variable, id))
+        return api
+    
     def __loadApiFile(self, apiFile):
         """
         Private method to read a raw API file into the database.
@@ -162,6 +188,9 @@
                 if language:
                     apiGenerator = APIGenerator(module)
                     apis = apiGenerator.genAPI(True, "", True)
+                    if os.path.basename(apiFile).startswith("Ui_"):
+                        # it is a forms source file, extract public attributes as well
+                        apis.extend(self.__classesAttributesApi(module))
                     try:
                         basesDict = apiGenerator.genBases(True)
                         for baseEntry in basesDict:
@@ -523,6 +552,11 @@
         self.__project.projectOpened.connect(self.__projectOpened)
         self.__project.newProject.connect(self.__projectOpened)
         self.__project.projectClosed.connect(self.__projectClosed)
+        try:
+            self.__project.projectFormCompiled.connect(self.__projectFormCompiled)
+        except AttributeError:
+            # older eric5 versions don't have this signal
+            pass
         if self.__project.isOpen():
             self.__projectOpened()
     
@@ -828,6 +862,30 @@
         # prepare the database if neccessary
         self.prepareAPIs()
     
+    def __getProjectFormSources(self, normalized=False):
+        """
+        Private method to get the source files for the project forms.
+        
+        @keyparam normalized flag indicating a normalized filename is wanted (boolean)
+        @return list of project form sources (list of strings)
+        """
+        if self.__project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]:
+            sourceExt = ".py"
+        elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
+            sourceExt = ".rb"
+        else:
+            return []
+        
+        formsSources = []
+        for fn in self.__project.pdata["FORMS"]:
+            ofn = os.path.splitext(fn)[0]
+            dirname, filename = os.path.split(ofn)
+            formSource = os.path.join(dirname, "Ui_" + filename + sourceExt)
+            if normalized:
+                formSource = os.path.join(self.__project.getProjectPath(), formSource)
+            formsSources.append(formSource)
+        return formsSources
+    
     def prepareAPIs(self, rawList=None):
         """
         Public method to prepare the APIs if neccessary.
@@ -841,7 +899,9 @@
         if rawList:
             apiFiles = rawList[:]
         elif self.__language == ApisNameProject:
-            apiFiles = self.__project.getSources()
+            apiFiles = self.__project.getSources()[:]
+            apiFiles.extend(
+                [f for f in self.__getProjectFormSources() if f not in apiFiles])
             projectPath = self.__project.getProjectPath()
         else:
             apiFiles = Preferences.getEditorAPI(self.__language)
@@ -932,6 +992,15 @@
         """
         self.close()
     
+    def __projectFormCompiled(self, filename):
+        """
+        Private slot to handle the projectFormCompiled signal.
+        
+        @param filename name of the form file that was compiled (string)
+        """
+        self.__workerQueue.append(filename)
+        self.__processQueue()
+    
     def editorSaved(self, filename):
         """
         Public slot to handle the editorSaved signal.

eric ide

mercurial