[wxPython-users] widget suggestion / question

Mark Erbaugh mark at microenh.com
Sun Dec 2 10:29:43 PST 2007


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?  One problem I see
with this is that I would have to modify my handler if I modified the
GUI. Perhaps I added a new button that I wanted to be handled
identically to an existing button.  That button would have to have a
different ID so I would have to modify the handler to look for the new
ID.

> 
> 
>         I'm using wxGlade for the design. The latest version allows
>         you to
>         attach properties to the widgets which it implements by
>         calling a SetXXX
>         method. To get this to work, I had to derive a button from
>         wxButton that 
>         had a SetXXX method. 
> 
> As I find it more efficient to do all my GUI design by hand, I don't
> know what wxGlade's capabilities are. Does it let you enter arbitrary
> code? As all the wxPython objects are regular python objects, you can
> set any arbitrary attribute on them if you want. I personally find
> that "poor practice", but that's me.

Sometimes I do my own hand-coding and I have set arbitrary attributes.
Like you, I somehow feel that this is not right, but it's perfectly good
Python. That's why I'd kind of like an 'official' wxPython attribute.
Since Python is dynamically typed this attribute could hold whatever tne
programmer needed.

> 
> 
> You could do 'button.whichButton = 5' if you wanted. Even though
> 'whichButton' doesn't exist before. 

The new version of wxGlade does support arbitrary code. I haven't tried
that feature, but it might work for what I need. Thanks for the
suggestion.

Mark






More information about the wxpython-users mailing list