diff -r 402d146da2f1 -r 8f4d794d8ee0 AssistantEric/Assistant.py --- a/AssistantEric/Assistant.py Sun May 22 11:33:46 2011 +0200 +++ b/AssistantEric/Assistant.py Sat Jul 30 10:46:53 2011 +0200 @@ -10,7 +10,7 @@ import re -from PyQt4.QtCore import * +from PyQt4.QtCore import QRegExp, QObject from E5Gui.E5Application import e5App @@ -20,33 +20,32 @@ import Preferences -AcsAPIs = 0x0001 +AcsAPIs = 0x0001 AcsDocument = 0x0002 -AcsProject = 0x0004 -AcsOther = 0x1000 +AcsProject = 0x0004 +AcsOther = 0x1000 + class Assistant(QObject): """ Class implementing the autocompletion and calltips system. """ - def __init__(self, plugin, newStyle, parent = None): + def __init__(self, plugin, parent=None): """ Constructor @param plugin reference to the plugin object - @param newStyle flag indicating usage of new style signals (bool) @param parent parent (QObject) """ QObject.__init__(self, parent) self.__plugin = plugin - self.__newStyle = newStyle self.__ui = parent self.__project = e5App().getObject("Project") self.__viewmanager = e5App().getObject("ViewManager") self.__pluginManager = e5App().getObject("PluginManager") - self.__apisManager = APIsManager(self.__newStyle, self) + self.__apisManager = APIsManager(self) self.__editors = [] self.__completingContext = False @@ -59,24 +58,12 @@ """ Public method to perform actions upon activation. """ - if self.__newStyle: - self.__pluginManager.shutdown.connect(self.__shutdown) - - self.__ui.preferencesChanged.connect(self.__preferencesChanged) - - self.__viewmanager.editorOpenedEd.connect(self.__editorOpened) - self.__viewmanager.editorClosedEd.connect(self.__editorClosed) - else: - self.connect(self.__pluginManager, SIGNAL("shutdown()"), - self.__shutdown) - - self.connect(self.__ui, SIGNAL('preferencesChanged'), - self.__preferencesChanged) - - self.connect(self.__viewmanager, SIGNAL("editorOpenedEd"), - self.__editorOpened) - self.connect(self.__viewmanager, SIGNAL("editorClosedEd"), - self.__editorClosed) + self.__pluginManager.shutdown.connect(self.__shutdown) + + self.__ui.preferencesChanged.connect(self.__preferencesChanged) + + self.__viewmanager.editorOpenedEd.connect(self.__editorOpened) + self.__viewmanager.editorClosedEd.connect(self.__editorClosed) # preload the project APIs object self.__apisManager.getAPIs(ApisNameProject) @@ -88,24 +75,12 @@ """ Public method to perform actions upon deactivation. """ - if self.__newStyle: - self.__pluginManager.shutdown.disconnect(self.__shutdown) - - self.__ui.preferencesChanged.disconnect(self.__preferencesChanged) - - self.__viewmanager.editorOpenedEd.disconnect(self.__editorOpened) - self.__viewmanager.editorClosedEd.disconnect(self.__editorClosed) - else: - self.disconnect(self.__pluginManager, SIGNAL("shutdown()"), - self.__shutdown) - - self.disconnect(self.__ui, SIGNAL('preferencesChanged'), - self.__preferencesChanged) - - self.disconnect(self.__viewmanager, SIGNAL("editorOpenedEd"), - self.__editorOpened) - self.disconnect(self.__viewmanager, SIGNAL("editorClosedEd"), - self.__editorClosed) + self.__pluginManager.shutdown.disconnect(self.__shutdown) + + self.__ui.preferencesChanged.disconnect(self.__preferencesChanged) + + self.__viewmanager.editorOpenedEd.disconnect(self.__editorOpened) + self.__viewmanager.editorClosedEd.disconnect(self.__editorClosed) self.__shutdown() @@ -141,12 +116,8 @@ self.__setAutoCompletionHook(editor) if self.__plugin.getPreferences("CalltipsEnabled"): self.__setCalltipsHook(editor) - if self.__newStyle: - editor.editorSaved.connect( - self.__apisManager.getAPIs(ApisNameProject).editorSaved) - else: - self.connect(editor, SIGNAL("editorSaved"), - self.__apisManager.getAPIs(ApisNameProject).editorSaved) + editor.editorSaved.connect( + self.__apisManager.getAPIs(ApisNameProject).editorSaved) self.__editors.append(editor) # preload the api to give the manager a chance to prepare the database @@ -162,12 +133,8 @@ @param editor reference to the editor (QScintilla.Editor) """ if editor in self.__editors: - if self.__newStyle: - editor.editorSaved.disconnect( - self.__apisManager.getAPIs(ApisNameProject).editorSaved) - else: - self.disconnect(editor, SIGNAL("editorSaved"), - self.__apisManager.getAPIs(ApisNameProject).editorSaved) + editor.editorSaved.disconnect( + self.__apisManager.getAPIs(ApisNameProject).editorSaved) self.__editors.remove(editor) if editor.autoCompletionHook() == self.autocomplete: self.__unsetAutoCompletionHook(editor) @@ -203,7 +170,7 @@ return ch, pos ################################# - ## autocompletion methods below + ## autocompletion methods below ################################# def __completionListSelected(self, id, txt): @@ -246,11 +213,7 @@ @param editor reference to the editor (QScintilla.Editor) """ - if self.__newStyle: - editor.userListActivated.connect(self.__completionListSelected) - else: - self.connect(editor, SIGNAL('userListActivated(int, const QString)'), - self.__completionListSelected) + editor.userListActivated.connect(self.__completionListSelected) editor.setAutoCompletionHook(self.autocomplete) def __unsetAutoCompletionHook(self, editor): @@ -260,11 +223,7 @@ @param editor reference to the editor (QScintilla.Editor) """ editor.unsetAutoCompletionHook() - if self.__newStyle: - editor.userListActivated.disconnect(self.__completionListSelected) - else: - self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'), - self.__completionListSelected) + editor.userListActivated.disconnect(self.__completionListSelected) def autocomplete(self, editor, context): """ @@ -307,7 +266,7 @@ if ch == ')': depth = 1 - # ignore everything back to the start of the + # ignore everything back to the start of the # corresponding parenthesis col -= 1 while col > 0: @@ -364,7 +323,7 @@ completionsList = [] if api is not None: if context: - completions = api.getCompletions(context = word) + completions = api.getCompletions(context=word) for completion in completions: entry = completion["completion"] if completion["pictureId"]: @@ -372,13 +331,13 @@ if entry not in completionsList: completionsList.append(entry) else: - completions = api.getCompletions(start = word) + completions = api.getCompletions(start=word) for completion in completions: if not completion["context"]: entry = completion["completion"] else: entry = "{0} ({1})".format( - completion["completion"], + completion["completion"], completion["context"] ) if entry in completionsList: @@ -417,9 +376,9 @@ sword = word.encode("utf-8") else: sword = word - res = editor.findFirstTarget(sword, False, - editor.autoCompletionCaseSensitivity(), - False, begline = 0, begindex = 0, ws_ = True) + res = editor.findFirstTarget(sword, False, + editor.autoCompletionCaseSensitivity(), + False, begline=0, begindex=0, ws_=True) while res: start, length = editor.getFoundTarget() pos = start + length @@ -429,7 +388,7 @@ else: completion = word line, index = editor.lineIndexFromPosition(pos) - curWord = editor.getWord(line, index, useWordChars = False) + curWord = editor.getWord(line, index, useWordChars=False) completion += curWord[len(completion):] if completion and completion not in completionsList: completionsList.append( @@ -441,7 +400,7 @@ return completionsList ########################### - ## calltips methods below + ## calltips methods below ########################### def __setCalltipsHook(self, editor): @@ -488,14 +447,14 @@ if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: api = self.__apisManager.getAPIs(language) if api is not None: - apiCalltips = api.getCalltips(word, commas, self.__lastContext, - self.__lastFullContext, + apiCalltips = api.getCalltips(word, commas, self.__lastContext, + self.__lastFullContext, self.__plugin.getPreferences("CallTipsContextShown")) if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: api = self.__apisManager.getAPIs(ApisNameProject) - projectCalltips = api.getCalltips(word, commas, self.__lastContext, - self.__lastFullContext, + projectCalltips = api.getCalltips(word, commas, self.__lastContext, + self.__lastFullContext, self.__plugin.getPreferences("CallTipsContextShown")) return sorted(set(apiCalltips).union(set(projectCalltips)))