[wxPython-users] Re: xrc: programmatic access to menu items
Robin Dunn
robin at alldunn.com
Thu Nov 2 20:40:07 PST 2006
John Salerno wrote:
> Robin Dunn wrote:
>
>>> def UpdateUI(self, event):
>>> #what goes here? a bunch of if tests using each control?
>>
>> No, just one. You'll have one of these handlers for every item, and
>> in each you can do something like:
>>
>> event.Enable(not someCondition)
>
> Oh, interesting. So when I write the Bind calls, I have to create a new
> handler for each one that is tied to the specified control, and in that
> handler I do the testing to enable/disable it?
Almost. The update events are designed to be bound per ID, so if you
have a menu item and a toolbar item that have the same ID, their update
can be controlled by a single update handler.
>
> That much makes sense, I think. I'll give it a try. But as far as
> actually calling Enable and Disable, I do this through the event
> parameter, not through a reference to the controls?
Because of the above, you may not know in the handler if you are being
called for the menu item, a toolbar item, or a control, etc. so you set
the enabled, checked, shown, or label state in the event, and then when
control returns to the sender of the event it sorts out what to do based
on what kind of item it was sending the event for.
>
> That seems a little odd, I guess because I don't have a good
> understanding of what 'event' really represents. I figured it had
> information about the event, but I didn't know you could use it to
> affect the object itself.
It depends on the type of event. For example, some kinds of events are
able to be vetoed, or need to be explicitly allowed by the handler, and
these are done by calling methods on the event object too.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list