Design problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jergosh
    New Member
    • Jan 2007
    • 7

    #1

    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:
    Code:
    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:
    Code:
    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
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Hello Grzegorz, and welcome to the pytyon forum on TSDN.
    There is a ton of source code available for you to use as a model for this type of project. Two apps that come to mind are Stani's Python Editor and Boa Constructor. Get SPE here. Boa is on sourceforge. Both of these IDEs use wxPython for their GUIs. I'm sure that there are others.

    Comment

    Working...