I'm working on an IM client in Python and my idea was to make it fully modular. It seemed to me that the obvious approach is to make all plugins derive from a Plugin class (with ProtocolPlugin, UIPlugin subclasses) and to be loaded on program startup by yet another object, the PluginManager. It works as following: each plugin .py file is executed (via execfile()) by the PluginManager, creates an object deriving from the Plugin class and calls registerPlugin method in the PluginManager with that object:
the main file:
class PluginManager:
def registerPlugin(self, newplugin):
newplugin.UIObject = self.UI
self.Plugins[newplugin.name] = newplugin
if isinstance(newplugin, ThreadedPlugin):
self.Protocols[newplugin.name].start()
self.triggerPluginRegistered()
def loadPlugin(pluginfile):
execfile(pluginfile)
the plugin file:
class someProtocol(ProtocolPlugin):
pass # self refers to the PluginManager since the code is ran inside it
self.registerProtocol(someProtocol())
Such design turns out not only to be rather clumsy but also leads to all sorts of problems and conundrums (eg. imports in the plugin files work strangely; I have to include a reference to the UI object in each plugin etc.). Are there any obvious improvements/simplifications? I'd rather keep the flexibility provided by modular design (easy to implement different user interfaces etc.)
TIA,
Grzegorz Slodkowicz