Python plug-in framework

Hi Tom. I know nothing about plug-in frameworks, but will throw in
$0.02…
First, Boa Constructor also has plug-ins, of all different sorts, if that is

helpful to know.

Based on how you described your goals, maybe a simple starting thing to do
(not really a plug-in) would be to just create all your apps/plugins/applets
as
panels (what Boa calls “FramePanels”), just a panel class saved in its own

module to used, for example, as a page in a wxNotebook. Then when the
user selects using that app, the module is imported then and the panel is
added to the notebook with .AddPage(). If the app requires a more complex

and multi-frame/panel layout, sure, maybe this won’t work, but if it is
something that can work on one panel, this might at least be fine to get
started.

btw, Chris Barker: thanks for posting Ed Leafe’s talk about Springboard.

Interesting idea, and kudos to Ed for making it.

Che

Thanks Che,

That was indeed the initial way I was thinking about it. Have all separate applications running in a wx.Panel and add the panel to a tabpage in the main application.

The question then would be how to get the panel from loading the plugin. Obviously, I could have a function GetPanel() which returns the panel containing the sub-application (or plugin), but then I guess that would mean the main application should already be aware of the class containing the new sub-application.

So e.g. say I have a plugin file called “newPlugin.py” which contains a class newPlugin. This class contains a derived panel where all functionality is provided. In addition the newPlugin class contains a method GetPlugin() which returns this panel. The question now is, how could I get the main application to know the “newPlugin” class without hardcoding it, such that I could load the plugin simply by loading the newPlugin.py file in the main app.

Best regards,

Tom.

You need establish a convention (as that's what a plugin
API is about):

module name == plugin class name

module contains global constant thisPluginClass aliasing real class name

module contains a list of plugin classes in this module

module contains a global factory function instantiate_plugin()

Karsten

···

On Wed, Apr 22, 2009 at 08:25:27AM +0200, Tom Clerckx wrote:

So e.g. say I have a plugin file called "newPlugin.py" which contains a
class newPlugin. This class contains a derived panel where all functionality
is provided. In addition the newPlugin class contains a method GetPlugin()
which returns this panel. The question now is, how could I get the main
application to know the "newPlugin" class without hardcoding it, such that I
could load the plugin simply by loading the newPlugin.py file in the main
app.

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Hi, Tom. Here’s some thoughts…(not tested)

  1. Put your plug-ins in a plug-in folder. Each plugin is a .py file and you should just
    think of it as a module. Make it a convention that each plugin has a standard

PlugInPanel that all the stuff is on.

  1. When the user wants to select a plug-in, use a wxFileDialog aimed
    at that folder (or if you want it to be neater, a wxChoice with the plug-in
    names generated from looking at that folder)

plugin_name = filedialog.GetFilename()

  1. You need to import that plugin’s namespace.
    Something like:

plug_in = import(plugin_name)

( import allows you to import using a string)

  1. Add the panel in it to the notebook:

page = plug_in.PlugInPanel(self.notebook, -1)
self.notebook.AddPage(page, plugin_name)

HTH,
Che

···

On Wed, Apr 22, 2009 at 2:25 AM, Tom Clerckx tclerckx@gmail.com wrote:

Hi Tom. I know nothing about plug-in frameworks, but will throw in
$0.02…
First, Boa Constructor also has plug-ins, of all different sorts, if that is

helpful to know.

Based on how you described your goals, maybe a simple starting thing to do
(not really a plug-in) would be to just create all your apps/plugins/applets
as
panels (what Boa calls “FramePanels”), just a panel class saved in its own

module to used, for example, as a page in a wxNotebook. Then when the
user selects using that app, the module is imported then and the panel is
added to the notebook with .AddPage(). If the app requires a more complex

and multi-frame/panel layout, sure, maybe this won’t work, but if it is
something that can work on one panel, this might at least be fine to get
started.

btw, Chris Barker: thanks for posting Ed Leafe’s talk about Springboard.

Interesting idea, and kudos to Ed for making it.

Che

Thanks Che,

That was indeed the initial way I was thinking about it. Have all separate applications running in a wx.Panel and add the panel to a tabpage in the main application.

The question then would be how to get the panel from loading the plugin. Obviously, I could have a function GetPanel() which returns the panel containing the sub-application (or plugin), but then I guess that would mean the main application should already be aware of the class containing the new sub-application.

So e.g. say I have a plugin file called “newPlugin.py” which contains a class newPlugin. This class contains a derived panel where all functionality is provided. In addition the newPlugin class contains a method GetPlugin() which returns this panel. The question now is, how could I get the main application to know the “newPlugin” class without hardcoding it, such that I could load the plugin simply by loading the newPlugin.py file in the main app.