954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Design problems

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

Jergosh
Newbie Poster
3 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

Is this part of your doctorial theses in computer science?

bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
 
Is this part of your doctorial theses in computer science?

No it's not. I do my homework myself ;)

Jergosh
Newbie Poster
3 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
each plugin .py file is executed (via execfile()) by the PluginManager

I am not 100% sure what you are doing, but wouldn't you want the PluginManager to be an inherited class. It should also have methods to keep track of all plugins created, which "self.Plugins[newplugin.name] = newplugin" should provide, if that is your problem, and as well should be able to pass them to any other object asking for them. If you have several separate classes calling the plugin manager, then you want a wrapper program of some sort that can pass the identity of the single PluginManager instance to those classes, so they are all using the same instance. Info can also be stored on disk in a single database that any process can access, but that is likely overkill. If I understand what you are trying to do.

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You