I'm not sure I'm properly phrasing this question, code will probably be more clear.
I'm adding a pretty simple plugin system to a WxPython application, where the plugin options are simply added to a submenu, and once they are clicked, the plugin's action is performed. I'm pretty new to wx, so there could be something simple I'm doing wrong, so I'd be happy to be informed.
The following code works as expected , with the clicked menu option's plugin 'performAction' method being called.
for plugin in self.pluginManager.plugins:
wxId = wx.NewId()
plugin_submenu.Append(wxID,plugin.displayName)
canvas.Bind(wx.EVT_MENU, plugin.performAction)
I'd like to add arguments to the plugin action as well, which led me to using lambdas, as the second argument to the 'bind' method should be callable. It seems like a pretty inconspicuous change to:
for plugin in self.pluginManager.plugins:
wxId = wx.NewId()
plugin_submenu.Append(wxID,plugin.displayName)
canvas.Bind(wx.EVT_MENU, lambda evt, temp=objArgs: plugin.performAction(evt,temp)
as described by this link. However, when I do this, whichever plugin object gets bound last gets called, regardless of which menu option is actually clicked. I'm really not sure why the behavior changes from the first code sample to the second, but it does, and I'm stumped.
So, does anyone have any clue why this is occuring, and what can I do to get the behavior that I expect?