Show
Ignore:
Timestamp:
06/03/08 15:40:27 (6 months ago)
Author:
vardo
Message:

Added plug-in deactivation mechanism, which allows plug-ins to clean up after themselves (eg. disconnecting handlers made in GUI); GUI extension points handlers are removed from list.

Updated Length Notifier plug-in so that it can be properly deactivated.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/plugin-system/src/plugins/pluginmanager.py

    r9752 r9754  
    5050        :todo: implement mechanism to dynamically load plugins where GUI extension 
    5151                   points have been already called (i.e. when plugin is activated 
    52                    after GUI object creation) 
     52                   after GUI object creation). [DONE?] 
    5353        :todo: implement mechanism to dynamically deactive plugins (call plugin's 
    54                    deactivation handler) 
     54                   deactivation handler) [DONE?] 
     55        :todo: when plug-in is deactivated all GUI extension points are removed 
     56                   from `PluginManager.gui_extension_points_handlers`. But when 
     57                   object that invoked GUI extension point is abandoned by Gajim, eg. 
     58                   closed ChatControl object, the reference to called GUI extension 
     59                   points is still in `PluginManager.gui_extension_points`. These 
     60                   should be removed, so that object can be destroyed by Python. 
     61                   Possible solution: add call to clean up method in classes 
     62                   'destructors' (classes that register GUI extension points) 
    5563        ''' 
    5664         
    5765        __metaclass__ = Singleton 
    5866 
    59         @log_calls('PluginManager') 
     67        #@log_calls('PluginManager') 
    6068        def __init__(self): 
    6169                self.plugins = [] 
     
    6977                self.active_plugins = [] 
    7078                ''' 
    71                 Objectsof active plugins. 
     79                Instance objects of active plugins. 
    7280                 
    7381                These are object instances of classes held `plugins`, but only those 
     
    9199                log.debug('plugins: %s'%(self.plugins)) 
    92100 
    93                 #self._activate_all_plugins() 
     101                self.activate_all_plugins() 
    94102 
    95103                log.debug('active: %s'%(self.active_plugins)) 
     
    134142 
    135143        @log_calls('PluginManager') 
    136         def _activate_plugin(self, plugin): 
     144        def activate_plugin(self, plugin): 
    137145                ''' 
    138146                :param plugin: plugin to be activated 
     
    151159 
    152160                return success 
     161         
     162        def deactivate_plugin(self, plugin_object): 
     163                # detaching plug-in from handler GUI extension points (calling 
     164                # cleaning up method that must be provided by plug-in developer 
     165                # for each handled GUI extension point) 
     166                for gui_extpoint_name, gui_extpoint_handlers in \ 
     167                                plugin_object.gui_extension_points.iteritems(): 
     168                        for gui_extension_point_args in self.gui_extension_points[gui_extpoint_name]: 
     169                                gui_extpoint_handlers[1](*gui_extension_point_args) 
     170                                 
     171                # remove GUI extension points handlers (provided by plug-in) from 
     172                # handlers list 
     173                for gui_extpoint_name, gui_extpoint_handlers in \ 
     174                                plugin_object.gui_extension_points.iteritems(): 
     175                        self.gui_extension_points_handlers[gui_extpoint_name].remove(gui_extpoint_handlers) 
     176                         
     177                # removing plug-in from active plug-ins list 
     178                self.active_plugins.remove(plugin_object) 
     179                 
     180        def deactivate_all_plugins(self): 
     181                for plugin_object in self.active_plugins: 
     182                        self.deactivate_plugin(plugin_object) 
    153183         
    154184        @log_calls('PluginManager') 
     
    168198 
    169199        @log_calls('PluginManager') 
    170         def _activate_all_plugins(self): 
     200        def activate_all_plugins(self): 
    171201                ''' 
    172202                Activates all plugins in `plugins`. 
     
    176206                self.active_plugins = [] 
    177207                for plugin in self.plugins: 
    178                         self._activate_plugin(plugin) 
     208                        self.activate_plugin(plugin) 
    179209 
    180210        @staticmethod