Python plug-in framework

I appear to have still a small problem with using the plugins.

Loading the plugin which is defined on a wx.Panel seems to work.

Unfortunately, the buttons which are located on the plugin panel don’t seem to capture the button events.

I.e., clicking on them doesn’t do anything, while it is expected that the button clicks write something in the logWindow.

See below for a code excerpt example.

LoadPlugin function in main.py, MainFrame class:

···

====================================

def LoadPlugin(self, pluginFilename):
print “Selected plugin: “, pluginFilename
plugin = pluginFilename.replace(”.py”,"")
mod = import(“TomsPlugins.”+plugin, globals(), locals(), plugin)

newPanel = mod.PluginPanel2(self.frame)
self.panelSizer.Add(newPanel.GetPanel())
self.frame.Fit()

In the plugin2.py file:

===============

class PluginPanel:
def init(self, parent):
#Load the panel from XRC
panelResource = xrc.XmlResource(“C:/TomsPlugins/plugin2.xrc”)
#Attach the panel to the parent frame
self.pluginPanel = panelResource.LoadPanel(parent, ‘mainPanel’)

#Reference the widgets from the xrc resource
self.button1 = GetControl(self.pluginPanel, “button1”)
self.button2 = GetControl(self.pluginPanel, “button2”)
self.logWindow = GetControl(self.pluginPanel, “logWindow”)

#Bind the widgets on the panel
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1)
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2)

def OnButton1(self, evt):
self.logWindow.WriteText(“Button 1\n”)

def OnButton2(self, evt):
self.logWindow.WriteText(“Button 2\n”)

def GetPanel(self):
return self.pluginPanel

Best regards,

Tom.

Tom, are you getting any errors when you press a button in the
plugin panel?

Could it be that self.logWindow is defined in the MainFrame
class, but you are referencing it from within the PluginPanel
class? If you need plugin-to-mainframe communication, which
you will, there are about 3 options you can do, the simplest
of which is probably using .GetParent() from within PluginPanel
to get a reference to the main frame, but the pubsub module
allows for more proper independence of objects.

If this doesn't work, if you could post a small runnable app,
somebody can help you get it going.

Che

···

On Tue, Apr 28, 2009 at 10:11 AM, Tom Clerckx <tclerckx@gmail.com> wrote:

I appear to have still a small problem with using the plugins.
Loading the plugin which is defined on a wx.Panel seems to work.

Unfortunately, the buttons which are located on the plugin panel don't seem
to capture the button events.
I.e., clicking on them doesn't do anything, while it is expected that the
button clicks write something in the logWindow.

See below for a code excerpt example.

LoadPlugin function in main.py, MainFrame class:

def LoadPlugin(self, pluginFilename):
print "Selected plugin: ", pluginFilename
plugin = pluginFilename.replace(".py","")
mod = __import__("TomsPlugins."+plugin, globals(), locals(), plugin)
newPanel = mod.PluginPanel2(self.frame)
self.panelSizer.Add(newPanel.GetPanel())
self.frame.Fit()

In the plugin2.py file:

class PluginPanel:
def __init__(self, parent):
#Load the panel from XRC
panelResource = xrc.XmlResource("C:/TomsPlugins/plugin2.xrc")
#Attach the panel to the parent frame
self.pluginPanel = panelResource.LoadPanel(parent, 'mainPanel')

#Reference the widgets from the xrc resource
self.button1 = GetControl(self.pluginPanel, "button1")
self.button2 = GetControl(self.pluginPanel, "button2")
self.logWindow = GetControl(self.pluginPanel, "logWindow")

#Bind the widgets on the panel
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1)
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2)

def OnButton1(self, evt):
self.logWindow.WriteText("Button 1\n")

def OnButton2(self, evt):
self.logWindow.WriteText("Button 2\n")

def GetPanel(self):
return self.pluginPanel

Best regards,
Tom.