Clientdata with button command event

I’m have a wxTransientPopupWindow on which I create buttons dynamically and Binding the buttons to a handler of the wxTransientPopupWindow. I then re-post the wxCommand event to the parent window of the wxTransientPopupWindow.

To let the parent window identify what button was pressed I wanted to add some extra data to the button event, with SetClientData(). I read somewhere this isn’t possible because it’s used by wxPython itself.

def CreateButtons( self ):
   
    for image in self.images:
        self.CreateButton( image )
   
def CreateButton( self, image ):
   
    button = wx.BitmapButton( self.panel, wx.ID_ANY, image.bitmap )
    button.Bind( wx.EVT_BUTTON, self.OnButtonSelected )
   
    self.panel.GetSizer().Add( button, 0, wx.ALL, 1 )

Is there a way to add extra data to the button event which is sent to the handler?

Standard commont: A formal sample app would be nice.

If the event handlers in the wx.TransientPopupWindow call the events Skip method, they should propagate up the parentage chain. The parents should be able to get the object through the event.GetEventObject() method.

Or am I missing something?

Josh

···

On Saturday, May 17, 2014 12:22:25 PM UTC-7, BigPilot wrote:

I’m have a wxTransientPopupWindow on which I create buttons dynamically and Binding the buttons to a handler of the wxTransientPopupWindow. I then re-post the wxCommand event to the parent window of the wxTransientPopupWindow.

To let the parent window identify what button was pressed I wanted to add some extra data to the button event, with SetClientData(). I read somewhere this isn’t possible because it’s used by wxPython itself.

def CreateButtons( self ):
   
    for image in self.images:
        self.CreateButton( image )
   
def CreateButton( self, image ):
   
    button = wx.BitmapButton( self.panel, wx.ID_ANY, image.bitmap )
    button.Bind( wx.EVT_BUTTON, self.OnButtonSelected )
   
    self.panel.GetSizer().Add( button, 0, wx.ALL, 1 )

Is there a way to add extra data to the button event which is sent to the handler?

Standard commont: A formal sample app would be nice.

If the event handlers in the wx.TransientPopupWindow call the events Skip method, they should propagate up the parentage chain. The parents should be able to get the object through the event.GetEventObject() method.

Or am I missing something?

Josh

The OnButtonSelected method does call skip and yes it does end up in the parent frame but I want to add extra info to the wx.EVT_BUTTON event though clientdata or some other mechanism. The C++ equivalent Connect() of Bind() does give one the ability to add clientData, but the Bind() does not.

···

Op zondag 18 mei 2014 03:26:26 UTC+2 schreef Josh English:

Actually you can add client data: See

http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks

in the wxPython-wiki.

I however find a mapping of button IDs and a specification more intuitive.

···

On Sunday, May 18, 2014 10:46:43 AM UTC+2, BigPilot wrote:

The OnButtonSelected method does call skip and yes it does end up in the parent frame but I want to add extra info to the wx.EVT_BUTTON event though clientdata or some other mechanism. The C++ equivalent Connect() of Bind() does give one the ability to add clientData, but the Bind() does not.

Optionally create custom event types.

Sometimes my thinking falls into:
{if a ListBox has ListBox events and TextCtrls and Frames each have their
own event types then why shouldn't my "DynamicButtonImagerPanel" widget
have its own type of events}.

It also allows the custom widget to be easily portable into other code. You
won't have to worry as much about callback function/method signatures or
wrapped callables and the like. Plugging the custom widget in other apps
seems simpler somehow: where event handlers follow the generic signature.

http://wiki.wxpython.org/CustomEventClasses