AssistantEric/Assistant.py

changeset 19
7eb775bb326b
parent 18
b8ece0b784e8
child 25
6a68405feb84
--- a/AssistantEric/Assistant.py	Sun Aug 01 13:08:23 2010 +0200
+++ b/AssistantEric/Assistant.py	Thu Aug 12 19:06:24 2010 +0200
@@ -29,22 +29,24 @@
     """
     Class implementing the autocompletion and calltips system.
     """
-    def __init__(self, plugin, parent = None):
+    def __init__(self, plugin, newStyle, 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)
+        self.__apisManager = APIsManager(self.__newStyle, self)
         
         self.__editors = []
         self.__completingContext = False
@@ -57,16 +59,24 @@
         """
         Public method to perform actions upon activation.
         """
-        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)
+        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)
         
         # preload the project APIs object
         self.__apisManager.getAPIs(ApisNameProject)
@@ -78,16 +88,24 @@
         """
         Public method to perform actions upon deactivation.
         """
-        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)
+        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.__shutdown()
     
@@ -123,8 +141,12 @@
             self.__setAutoCompletionHook(editor)
         if self.__plugin.getPreferences("CalltipsEnabled"):
             self.__setCalltipsHook(editor)
-        self.connect(editor, SIGNAL("editorSaved"), 
-                     self.__apisManager.getAPIs(ApisNameProject).editorSaved)
+        if self.__newStyle:
+            editor.editorSaved.connect(
+                self.__apisManager.getAPIs(ApisNameProject).editorSaved)
+        else:
+            self.connect(editor, SIGNAL("editorSaved"), 
+                         self.__apisManager.getAPIs(ApisNameProject).editorSaved)
         self.__editors.append(editor)
         
         # preload the api to give the manager a chance to prepare the database
@@ -140,8 +162,12 @@
         @param editor reference to the editor (QScintilla.Editor)
         """
         if editor in self.__editors:
-            self.disconnect(editor, SIGNAL("editorSaved"), 
-                            self.__apisManager.getAPIs(ApisNameProject).editorSaved)
+            if self.__newStyle:
+                editor.editorSaved.disconnect(
+                    self.__apisManager.getAPIs(ApisNameProject).editorSaved)
+            else:
+                self.disconnect(editor, SIGNAL("editorSaved"), 
+                                self.__apisManager.getAPIs(ApisNameProject).editorSaved)
             self.__editors.remove(editor)
             if editor.autoCompletionHook() == self.autocomplete:
                 self.__unsetAutoCompletionHook(editor)
@@ -220,8 +246,11 @@
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        self.connect(editor, SIGNAL('userListActivated(int, const QString)'),
-                     self.__completionListSelected)
+        if self.__newStyle:
+            editor.userListActivated.connect(self.__completionListSelected)
+        else:
+            self.connect(editor, SIGNAL('userListActivated(int, const QString)'),
+                         self.__completionListSelected)
         editor.setAutoCompletionHook(self.autocomplete)
     
     def __unsetAutoCompletionHook(self, editor):
@@ -231,8 +260,11 @@
         @param editor reference to the editor (QScintilla.Editor)
         """
         editor.unsetAutoCompletionHook()
-        self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'),
-                        self.__completionListSelected)
+        if self.__newStyle:
+            editor.userListActivated.disconnect(self.__completionListSelected)
+        else:
+            self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'),
+                            self.__completionListSelected)
     
     def autocomplete(self, editor, context):
         """

eric ide

mercurial