AssistantEric/Assistant.py

changeset 19
7eb775bb326b
parent 18
b8ece0b784e8
child 25
6a68405feb84
equal deleted inserted replaced
18:b8ece0b784e8 19:7eb775bb326b
27 27
28 class Assistant(QObject): 28 class Assistant(QObject):
29 """ 29 """
30 Class implementing the autocompletion and calltips system. 30 Class implementing the autocompletion and calltips system.
31 """ 31 """
32 def __init__(self, plugin, parent = None): 32 def __init__(self, plugin, newStyle, parent = None):
33 """ 33 """
34 Constructor 34 Constructor
35 35
36 @param plugin reference to the plugin object 36 @param plugin reference to the plugin object
37 @param newStyle flag indicating usage of new style signals (bool)
37 @param parent parent (QObject) 38 @param parent parent (QObject)
38 """ 39 """
39 QObject.__init__(self, parent) 40 QObject.__init__(self, parent)
40 41
41 self.__plugin = plugin 42 self.__plugin = plugin
43 self.__newStyle = newStyle
42 self.__ui = parent 44 self.__ui = parent
43 self.__project = e5App().getObject("Project") 45 self.__project = e5App().getObject("Project")
44 self.__viewmanager = e5App().getObject("ViewManager") 46 self.__viewmanager = e5App().getObject("ViewManager")
45 self.__pluginManager = e5App().getObject("PluginManager") 47 self.__pluginManager = e5App().getObject("PluginManager")
46 48
47 self.__apisManager = APIsManager(self) 49 self.__apisManager = APIsManager(self.__newStyle, self)
48 50
49 self.__editors = [] 51 self.__editors = []
50 self.__completingContext = False 52 self.__completingContext = False
51 self.__lastContext = None 53 self.__lastContext = None
52 self.__lastFullContext = None 54 self.__lastFullContext = None
55 57
56 def activate(self): 58 def activate(self):
57 """ 59 """
58 Public method to perform actions upon activation. 60 Public method to perform actions upon activation.
59 """ 61 """
60 self.connect(self.__pluginManager, SIGNAL("shutdown()"), 62 if self.__newStyle:
61 self.__shutdown) 63 self.__pluginManager.shutdown.connect(self.__shutdown)
62 64
63 self.connect(self.__ui, SIGNAL('preferencesChanged'), 65 self.__ui.preferencesChanged.connect(self.__preferencesChanged)
64 self.__preferencesChanged) 66
65 67 self.__viewmanager.editorOpenedEd.connect(self.__editorOpened)
66 self.connect(self.__viewmanager, SIGNAL("editorOpenedEd"), 68 self.__viewmanager.editorClosedEd.connect(self.__editorClosed)
67 self.__editorOpened) 69 else:
68 self.connect(self.__viewmanager, SIGNAL("editorClosedEd"), 70 self.connect(self.__pluginManager, SIGNAL("shutdown()"),
69 self.__editorClosed) 71 self.__shutdown)
72
73 self.connect(self.__ui, SIGNAL('preferencesChanged'),
74 self.__preferencesChanged)
75
76 self.connect(self.__viewmanager, SIGNAL("editorOpenedEd"),
77 self.__editorOpened)
78 self.connect(self.__viewmanager, SIGNAL("editorClosedEd"),
79 self.__editorClosed)
70 80
71 # preload the project APIs object 81 # preload the project APIs object
72 self.__apisManager.getAPIs(ApisNameProject) 82 self.__apisManager.getAPIs(ApisNameProject)
73 83
74 for editor in self.__viewmanager.getOpenEditors(): 84 for editor in self.__viewmanager.getOpenEditors():
76 86
77 def deactivate(self): 87 def deactivate(self):
78 """ 88 """
79 Public method to perform actions upon deactivation. 89 Public method to perform actions upon deactivation.
80 """ 90 """
81 self.disconnect(self.__pluginManager, SIGNAL("shutdown()"), 91 if self.__newStyle:
82 self.__shutdown) 92 self.__pluginManager.shutdown.disconnect(self.__shutdown)
83 93
84 self.disconnect(self.__ui, SIGNAL('preferencesChanged'), 94 self.__ui.preferencesChanged.disconnect(self.__preferencesChanged)
85 self.__preferencesChanged) 95
86 96 self.__viewmanager.editorOpenedEd.disconnect(self.__editorOpened)
87 self.disconnect(self.__viewmanager, SIGNAL("editorOpenedEd"), 97 self.__viewmanager.editorClosedEd.disconnect(self.__editorClosed)
88 self.__editorOpened) 98 else:
89 self.disconnect(self.__viewmanager, SIGNAL("editorClosedEd"), 99 self.disconnect(self.__pluginManager, SIGNAL("shutdown()"),
90 self.__editorClosed) 100 self.__shutdown)
101
102 self.disconnect(self.__ui, SIGNAL('preferencesChanged'),
103 self.__preferencesChanged)
104
105 self.disconnect(self.__viewmanager, SIGNAL("editorOpenedEd"),
106 self.__editorOpened)
107 self.disconnect(self.__viewmanager, SIGNAL("editorClosedEd"),
108 self.__editorClosed)
91 109
92 self.__shutdown() 110 self.__shutdown()
93 111
94 def __shutdown(self): 112 def __shutdown(self):
95 """ 113 """
121 """ 139 """
122 if self.__plugin.getPreferences("AutoCompletionEnabled"): 140 if self.__plugin.getPreferences("AutoCompletionEnabled"):
123 self.__setAutoCompletionHook(editor) 141 self.__setAutoCompletionHook(editor)
124 if self.__plugin.getPreferences("CalltipsEnabled"): 142 if self.__plugin.getPreferences("CalltipsEnabled"):
125 self.__setCalltipsHook(editor) 143 self.__setCalltipsHook(editor)
126 self.connect(editor, SIGNAL("editorSaved"), 144 if self.__newStyle:
127 self.__apisManager.getAPIs(ApisNameProject).editorSaved) 145 editor.editorSaved.connect(
146 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
147 else:
148 self.connect(editor, SIGNAL("editorSaved"),
149 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
128 self.__editors.append(editor) 150 self.__editors.append(editor)
129 151
130 # preload the api to give the manager a chance to prepare the database 152 # preload the api to give the manager a chance to prepare the database
131 language = editor.getLanguage() 153 language = editor.getLanguage()
132 if language == "": 154 if language == "":
138 Private slot called, when an editor was closed. 160 Private slot called, when an editor was closed.
139 161
140 @param editor reference to the editor (QScintilla.Editor) 162 @param editor reference to the editor (QScintilla.Editor)
141 """ 163 """
142 if editor in self.__editors: 164 if editor in self.__editors:
143 self.disconnect(editor, SIGNAL("editorSaved"), 165 if self.__newStyle:
144 self.__apisManager.getAPIs(ApisNameProject).editorSaved) 166 editor.editorSaved.disconnect(
167 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
168 else:
169 self.disconnect(editor, SIGNAL("editorSaved"),
170 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
145 self.__editors.remove(editor) 171 self.__editors.remove(editor)
146 if editor.autoCompletionHook() == self.autocomplete: 172 if editor.autoCompletionHook() == self.autocomplete:
147 self.__unsetAutoCompletionHook(editor) 173 self.__unsetAutoCompletionHook(editor)
148 if editor.callTipHook() == self.calltips: 174 if editor.callTipHook() == self.calltips:
149 self.__unsetCalltipsHook(editor) 175 self.__unsetCalltipsHook(editor)
218 """ 244 """
219 Private method to set the autocompletion hook. 245 Private method to set the autocompletion hook.
220 246
221 @param editor reference to the editor (QScintilla.Editor) 247 @param editor reference to the editor (QScintilla.Editor)
222 """ 248 """
223 self.connect(editor, SIGNAL('userListActivated(int, const QString)'), 249 if self.__newStyle:
224 self.__completionListSelected) 250 editor.userListActivated.connect(self.__completionListSelected)
251 else:
252 self.connect(editor, SIGNAL('userListActivated(int, const QString)'),
253 self.__completionListSelected)
225 editor.setAutoCompletionHook(self.autocomplete) 254 editor.setAutoCompletionHook(self.autocomplete)
226 255
227 def __unsetAutoCompletionHook(self, editor): 256 def __unsetAutoCompletionHook(self, editor):
228 """ 257 """
229 Private method to unset the autocompletion hook. 258 Private method to unset the autocompletion hook.
230 259
231 @param editor reference to the editor (QScintilla.Editor) 260 @param editor reference to the editor (QScintilla.Editor)
232 """ 261 """
233 editor.unsetAutoCompletionHook() 262 editor.unsetAutoCompletionHook()
234 self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'), 263 if self.__newStyle:
235 self.__completionListSelected) 264 editor.userListActivated.disconnect(self.__completionListSelected)
265 else:
266 self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'),
267 self.__completionListSelected)
236 268
237 def autocomplete(self, editor, context): 269 def autocomplete(self, editor, context):
238 """ 270 """
239 Public method to determine the autocompletion proposals. 271 Public method to determine the autocompletion proposals.
240 272

eric ide

mercurial