[wxPython-users] widget suggestion / question

Robin Dunn robin at alldunn.com
Mon Dec 3 12:08:45 PST 2007


Mark Erbaugh wrote:
> Steve,
> 
> Thanks for the reply.
> 
> On Sun, 2007-12-02 at 10:08 -0800, Stephen Hansen wrote: 
>>         In Borland Delphi, the individual widgets (components) had a
>>         spare field
>>         that could be used to store an integer for whatever purpose
>>         the 
>>         developer wanted.  I would like to see something like this in
>>         wx. Here's
>>         where I could use something like this. I designed a form with
>>         a series
>>         of buttons. Several of the buttons could share the same event
>>         handler if 
>>         the event handler could figure out which button invoked it.  I
>>         supposed
>>         I could use reflection to figure out which button, but it
>>         would be nice
>>         if the event handler could check this spare field in the
>>         button. 
>>
>>
>> Since every button has it's own ID, isn't .GetID() enough to find
>> which is which? 
> 
> That certainly is an approach. But, would that mean that I would have to
> assign a known ID to the button rather than using -1?  

Or continue to use -1 and then use one of these approaches:

* save the auto-generated ID using something like "self.btn1id = 
btn1.GetId()" and then test if the event id is equal to self.btn1id.

* just test it in the handler, like "if evt.GetId() == 
self.btn1.GetId():..."

* or you can get the object that sent the event with 
evt.GetEventObject() and test if it is the button object in question.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list