[PyQt] question about dip plugins

Phil Thompson phil at riverbankcomputing.com
Wed Jul 28 17:21:15 BST 2010


On Tue, 27 Jul 2010 15:20:12 -0400, Darren Dale <dsdale24 at gmail.com>
wrote:
> The dip documentation at
> http://www.riverbankcomputing.com/static/Docs/dip/plugins_tutorial.html
> mentions:
> 
> "... When a plugin requests a service the plugin manager will choose
> which service is actually used. The plugin does not care about the
> particular service, its only concern is that it has an object that
> implements the interface. ..."
> 
> I am starting work on a project that will simulate spectra based on
> physical reference data. There are several databases to choose from,
> so in a sense the task is similar to the recipe chooser example in the
> plugins tutorial. I would like to be able to compare the results of
> one "recipe" with the next. Is it possible for the client to request a
> particular service or plugin, rather than simply accept whatever the
> plugin manager decides to provide?

Not with the current implementation but, of course, you can replace the
current implementation with your own (probably a sub-class) that does what
you want. However, providing an alternative plugin manager is probably not
a good idea as it makes it more difficult to re-use code later on - you
might want to re-use code that depends on different plugin managers.

A better approach would be to define a spectra database manager plugin.
This would itself be a service. It would define an extension point that
accepts contributions from individual database plugins. You could then
design the API of the manager to allow you to compare the results from one
database with another. Defining the behaviour of the database manager in
terms of an interface will allow you to replace it with another
implementation at a later date without changing any of the database plugins
or any code that calls the database manager API.

> Also, from the same tutorial:
> 
> @implements(IPlugin)
> class RecipeChooserPlugin(Plugin):
> 
> Why is it necessary to decorate subclasses of Plugin with
> @implements(IPlugin)? Are there cases when subclasses of Plugin would
> not implement the IPlugin interface?

Good point, it should probably be...

@implements(IPlugin)
class Plugin(Model):

...so that the decorator is not needed by anything that sub-classes
Plugin.

Phil


More information about the PyQt mailing list