AssistantEric/APIsManager.py

changeset 54
89d28458ff40
parent 50
005b6127b978
child 59
2b361d34d241
equal deleted inserted replaced
53:cc91f2132635 54:89d28458ff40
14 from PyQt4.QtSql import QSqlDatabase, QSqlQuery 14 from PyQt4.QtSql import QSqlDatabase, QSqlQuery
15 15
16 from E5Gui.E5Application import e5App 16 from E5Gui.E5Application import e5App
17 17
18 import QScintilla.Lexers 18 import QScintilla.Lexers
19 from QScintilla.Editor import Editor
19 20
20 from DocumentationTools.APIGenerator import APIGenerator 21 from DocumentationTools.APIGenerator import APIGenerator
21 import Utilities.ModuleParser 22 import Utilities.ModuleParser
22 import Utilities 23 import Utilities
23 import Preferences 24 import Preferences
141 if modTimeBases > modTime: 142 if modTimeBases > modTime:
142 modTime = modTimeBases 143 modTime = modTimeBases
143 if loadTime < modTime: 144 if loadTime < modTime:
144 self.__loadApiFile(apiFile) 145 self.__loadApiFile(apiFile)
145 146
147 def __classesAttributesApi(self, module):
148 """
149 Private method to generate class api section for class attributes.
150
151 @param module module object to get the info from (Module)
152 @return API information (list of strings)
153 """
154 api = []
155 modulePath = module.name.split('.')
156 moduleName = "{0}.".format('.'.join(modulePath))
157
158 for className in sorted(module.classes.keys()):
159 _class = module.classes[className]
160 classNameStr = "{0}{1}.".format(moduleName, className)
161 for variable in sorted(_class.attributes.keys()):
162 if not _class.attributes[variable].isPrivate():
163 if _class.attributes[variable].isPublic():
164 id = Editor.AttributeID
165 elif _class.attributes[variable].isProtected():
166 id = Editor.AttributeProtectedID
167 else:
168 id = Editor.AttributePrivateID
169 api.append('{0}{1}?{2:d}'.format(classNameStr, variable, id))
170 return api
171
146 def __loadApiFile(self, apiFile): 172 def __loadApiFile(self, apiFile):
147 """ 173 """
148 Private method to read a raw API file into the database. 174 Private method to read a raw API file into the database.
149 175
150 @param apiFile filename of the raw API file (string) 176 @param apiFile filename of the raw API file (string)
160 caching=False) 186 caching=False)
161 language = module.getType() 187 language = module.getType()
162 if language: 188 if language:
163 apiGenerator = APIGenerator(module) 189 apiGenerator = APIGenerator(module)
164 apis = apiGenerator.genAPI(True, "", True) 190 apis = apiGenerator.genAPI(True, "", True)
191 if os.path.basename(apiFile).startswith("Ui_"):
192 # it is a forms source file, extract public attributes as well
193 apis.extend(self.__classesAttributesApi(module))
165 try: 194 try:
166 basesDict = apiGenerator.genBases(True) 195 basesDict = apiGenerator.genBases(True)
167 for baseEntry in basesDict: 196 for baseEntry in basesDict:
168 if basesDict[baseEntry]: 197 if basesDict[baseEntry]:
169 bases.append("{0} {1}\n".format( 198 bases.append("{0} {1}\n".format(
521 550
522 self.__project = e5App().getObject("Project") 551 self.__project = e5App().getObject("Project")
523 self.__project.projectOpened.connect(self.__projectOpened) 552 self.__project.projectOpened.connect(self.__projectOpened)
524 self.__project.newProject.connect(self.__projectOpened) 553 self.__project.newProject.connect(self.__projectOpened)
525 self.__project.projectClosed.connect(self.__projectClosed) 554 self.__project.projectClosed.connect(self.__projectClosed)
555 try:
556 self.__project.projectFormCompiled.connect(self.__projectFormCompiled)
557 except AttributeError:
558 # older eric5 versions don't have this signal
559 pass
526 if self.__project.isOpen(): 560 if self.__project.isOpen():
527 self.__projectOpened() 561 self.__projectOpened()
528 562
529 def __initAsLanguage(self): 563 def __initAsLanguage(self):
530 """ 564 """
826 self.__createApiDB() 860 self.__createApiDB()
827 861
828 # prepare the database if neccessary 862 # prepare the database if neccessary
829 self.prepareAPIs() 863 self.prepareAPIs()
830 864
865 def __getProjectFormSources(self, normalized=False):
866 """
867 Private method to get the source files for the project forms.
868
869 @keyparam normalized flag indicating a normalized filename is wanted (boolean)
870 @return list of project form sources (list of strings)
871 """
872 if self.__project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]:
873 sourceExt = ".py"
874 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
875 sourceExt = ".rb"
876 else:
877 return []
878
879 formsSources = []
880 for fn in self.__project.pdata["FORMS"]:
881 ofn = os.path.splitext(fn)[0]
882 dirname, filename = os.path.split(ofn)
883 formSource = os.path.join(dirname, "Ui_" + filename + sourceExt)
884 if normalized:
885 formSource = os.path.join(self.__project.getProjectPath(), formSource)
886 formsSources.append(formSource)
887 return formsSources
888
831 def prepareAPIs(self, rawList=None): 889 def prepareAPIs(self, rawList=None):
832 """ 890 """
833 Public method to prepare the APIs if neccessary. 891 Public method to prepare the APIs if neccessary.
834 892
835 @keyparam rawList list of raw API files (list of strings) 893 @keyparam rawList list of raw API files (list of strings)
839 897
840 projectPath = "" 898 projectPath = ""
841 if rawList: 899 if rawList:
842 apiFiles = rawList[:] 900 apiFiles = rawList[:]
843 elif self.__language == ApisNameProject: 901 elif self.__language == ApisNameProject:
844 apiFiles = self.__project.getSources() 902 apiFiles = self.__project.getSources()[:]
903 apiFiles.extend(
904 [f for f in self.__getProjectFormSources() if f not in apiFiles])
845 projectPath = self.__project.getProjectPath() 905 projectPath = self.__project.getProjectPath()
846 else: 906 else:
847 apiFiles = Preferences.getEditorAPI(self.__language) 907 apiFiles = Preferences.getEditorAPI(self.__language)
848 self.__worker = DbAPIsWorker(self, self.__language, apiFiles, projectPath) 908 self.__worker = DbAPIsWorker(self, self.__language, apiFiles, projectPath)
849 self.__worker.start() 909 self.__worker.start()
930 """ 990 """
931 Private slot to perform actions after a project has been closed. 991 Private slot to perform actions after a project has been closed.
932 """ 992 """
933 self.close() 993 self.close()
934 994
995 def __projectFormCompiled(self, filename):
996 """
997 Private slot to handle the projectFormCompiled signal.
998
999 @param filename name of the form file that was compiled (string)
1000 """
1001 self.__workerQueue.append(filename)
1002 self.__processQueue()
1003
935 def editorSaved(self, filename): 1004 def editorSaved(self, filename):
936 """ 1005 """
937 Public slot to handle the editorSaved signal. 1006 Public slot to handle the editorSaved signal.
938 1007
939 @param filename name of the file that was saved (string) 1008 @param filename name of the file that was saved (string)

eric ide

mercurial