--- a/AssistantEric/APIsManager.py Sun May 22 11:33:46 2011 +0200 +++ b/AssistantEric/APIsManager.py Sat Jul 30 10:46:53 2011 +0200 @@ -9,7 +9,8 @@ import os -from PyQt4.QtCore import * +from PyQt4.QtCore import QTimer, QThread, QFileInfo, pyqtSignal, QCoreApplication, \ + QEvent, QDateTime, QObject, Qt from PyQt4.QtSql import QSqlDatabase, QSqlQuery from E5Gui.E5Application import e5App @@ -27,12 +28,13 @@ ApisNameProject = "__Project__" + class DbAPIsWorker(QThread): """ Class implementing a worker thread to prepare the API database. """ populate_api_stmt = """ - INSERT INTO api (acWord, context, fullContext, signature, fileId, pictureId) + INSERT INTO api (acWord, context, fullContext, signature, fileId, pictureId) VALUES (:acWord, :context, :fullContext, :signature, :fileId, :pictureId) """ populate_del_api_stmt = """ @@ -55,7 +57,7 @@ DELETE FROM file WHERE id = :id """ - def __init__(self, proxy, language, apiFiles, projectPath = "", refresh = False): + def __init__(self, proxy, language, apiFiles, projectPath="", refresh=False): """ Constructor @@ -71,7 +73,7 @@ self.setTerminationEnabled(True) # Get the AC word separators for all of the languages that the editor supports. - # This has to be before we create a new thread, because access to GUI elements + # This has to be before we create a new thread, because access to GUI elements # is not allowed from non-gui threads. self.__wseps = {} for lang in QScintilla.Lexers.getSupportedLanguages(): @@ -138,9 +140,9 @@ if self.__language == ApisNameProject: try: module = Utilities.ModuleParser.readModule( - os.path.join(self.__projectPath, apiFile), - basename = self.__projectPath + os.sep, - caching = False) + os.path.join(self.__projectPath, apiFile), + basename=self.__projectPath + os.sep, + caching=False) language = module.getType() if language: apiGenerator = APIGenerator(module) @@ -325,13 +327,14 @@ else: QCoreApplication.postEvent(self.__proxy, QEvent(QEvent.Type(WorkerFinished))) + class DbAPIs(QObject): """ Class implementing an API storage entity. @signal apiPreparationFinished() emitted after the API preparation has finished @signal apiPreparationStarted() emitted after the API preparation has started - @signal apiPreparationCancelled() emitted after the API preparation has been + @signal apiPreparationCancelled() emitted after the API preparation has been cancelled """ apiPreparationFinished = pyqtSignal() @@ -348,9 +351,9 @@ create_api_stmt = """ CREATE TABLE api - (acWord TEXT, - context TEXT, - fullContext TEXT, + (acWord TEXT, + context TEXT, + fullContext TEXT, signature TEXT, fileId INTEGER, pictureId INTEGER, @@ -385,12 +388,12 @@ """ ac_stmt = """ - SELECT DISTINCT acWord, fullContext, pictureId FROM api + SELECT DISTINCT acWord, fullContext, pictureId FROM api WHERE acWord GLOB :acWord ORDER BY acWord """ ac_context_stmt = """ - SELECT DISTINCT acWord, fullContext, pictureId FROM api + SELECT DISTINCT acWord, fullContext, pictureId FROM api WHERE context = :context ORDER BY acWord """ @@ -415,18 +418,16 @@ INSERT INTO mgmt (format) VALUES ({0:d}) """.format(DB_VERSION) - def __init__(self, language, newStyle, parent = None): + def __init__(self, language, parent=None): """ Constructor @param language language of the APIs object (string) - @param newStyle flag indicating usage of new style signals (bool) @param parent reference to the parent object (QObject) """ QObject.__init__(self, parent) self.setObjectName("DbAPIs_{0}".format(language)) - self.__newStyle = newStyle self.__inPreparation = False self.__worker = None self.__workerQueue = [] @@ -444,14 +445,9 @@ self.__lexer = None self.__project = e5App().getObject("Project") - if self.__newStyle: - self.__project.projectOpened.connect(self.__projectOpened) - self.__project.newProject.connect(self.__projectOpened) - self.__project.projectClosed.connect(self.__projectClosed) - else: - self.connect(self.__project, SIGNAL("projectOpened"), self.__projectOpened) - self.connect(self.__project, SIGNAL("newProject"), self.__projectOpened) - self.connect(self.__project, SIGNAL("projectClosed"), self.__projectClosed) + self.__project.projectOpened.connect(self.__projectOpened) + self.__project.newProject.connect(self.__projectOpened) + self.__project.projectClosed.connect(self.__projectClosed) if self.__project.isOpen(): self.__projectOpened() @@ -476,7 +472,7 @@ @return name of the database file (string) """ if self.__language == ApisNameProject: - return os.path.join(self.__project.getProjectManagementDir(), + return os.path.join(self.__project.getProjectManagementDir(), "project-apis.db") else: apiDir = os.path.join(Utilities.getConfigDir(), "APIs") @@ -589,11 +585,11 @@ db.commit() return prepared - def getCompletions(self, start = None, context = None): + def getCompletions(self, start=None, context=None): """ Public method to determine the possible completions. - @keyparam start string giving the start of the word to be + @keyparam start string giving the start of the word to be completed (string) @keyparam context string giving the context (e.g. classname) to be completed (string) @@ -622,17 +618,17 @@ if query is not None: query.exec_() while query.next(): - completions.append({"completion" : query.value(0), - "context" : query.value(1), - "pictureId" : query.value(2)}) + completions.append({"completion": query.value(0), + "context": query.value(1), + "pictureId": query.value(2)}) del query finally: db.commit() return completions - def getCalltips(self, acWord, commas, context = None, fullContext = None, - showContext = True): + def getCalltips(self, acWord, commas, context=None, fullContext=None, + showContext=True): """ Public method to determine the calltips. @@ -685,7 +681,7 @@ if context and len(calltips) == 0: # nothing found, try without a context - calltips = self.getCalltips(acWord, commas, showContext = showContext) + calltips = self.getCalltips(acWord, commas, showContext=showContext) return calltips @@ -716,7 +712,7 @@ # prepare the database if neccessary self.prepareAPIs() - def prepareAPIs(self, rawList = None): + def prepareAPIs(self, rawList=None): """ Public method to prepare the APIs if neccessary. @@ -750,8 +746,8 @@ apiFiles = [apiFiles[0].replace(projectPath + os.sep, "")] else: projectPath = "" - self.__worker = DbAPIsWorker(self, self.__language, apiFiles, projectPath, - refresh = True) + self.__worker = DbAPIsWorker(self, self.__language, apiFiles, projectPath, + refresh=True) self.__worker.start() def getLexer(self): @@ -781,27 +777,18 @@ """ if evt.type() == WorkerStarted: self.__inPreparation = True - if self.__newStyle: - self.apiPreparationStarted.emit() - else: - self.emit(SIGNAL('apiPreparationStarted()')) + self.apiPreparationStarted.emit() return True elif evt.type() == WorkerFinished: self.__inPreparation = False - if self.__newStyle: - self.apiPreparationFinished.emit() - else: - self.emit(SIGNAL('apiPreparationFinished()')) + self.apiPreparationFinished.emit() QTimer.singleShot(0, self.__processQueue) return True elif evt.type() == WorkerAborted: self.__inPreparation = False - if self.__newStyle: - self.apiPreparationCancelled.emit() - else: - self.emit(SIGNAL('apiPreparationCancelled()')) + self.apiPreparationCancelled.emit() QTimer.singleShot(0, self.__processQueue) return True @@ -839,23 +826,21 @@ self.__workerQueue.append(filename) self.__processQueue() + class APIsManager(QObject): """ Class implementing the APIsManager class, which is the central store for API information used by autocompletion and calltips. """ - def __init__(self, newStyle, parent = None): + def __init__(self, parent=None): """ Constructor - @param newStyle flag indicating usage of new style signals (bool) @param parent reference to the parent object (QObject) """ QObject.__init__(self, parent) self.setObjectName("APIsManager") - self.__newStyle = newStyle - # initialize the apis dictionary self.__apis = {} @@ -870,7 +855,7 @@ """ Public method to get an apis object for autocompletion/calltips. - This method creates and loads an APIs object dynamically upon request. + This method creates and loads an APIs object dynamically upon request. This saves memory for languages, that might not be needed at the moment. @param language the language of the requested api object (string) @@ -882,7 +867,7 @@ if language in QScintilla.Lexers.getSupportedLanguages() or \ language == ApisNameProject: # create the api object - self.__apis[language] = DbAPIs(language, self.__newStyle) + self.__apis[language] = DbAPIs(language) return self.__apis[language] else: return None