[wxPython-users] Question on code in Chapter 8 of "wxPython In
Action"
Robin Dunn
robin at alldunn.com
Wed May 2 13:59:35 PDT 2007
John Clark wrote:
> Okay, I'm _still_ going through the wxPython In Action book and have
> questions now on the code in Chapter 8. In Listing 8.12 the code reads
> something like:
>
> def OnCheckCanSplit(self, evt):
> evt.Enable(not self.sp.IsSplit())
>
> What I don't understand here is calling Enable on an event - it would
> seem to me that the code should use the ID that is provided by the event
> to track down the menu item that is raising the event and then call
> Enable on that menu item.
The sender of the update ui event does all that for you, although it is
a bit simpler because it already has a reference to the menu item (or
whatever) it is sending the event about. It's like me taking an apple
out of a box and asking you if you would like this apple whole or
sliced. You don't have to go and look around the whole room for the
apple and slice it yourself, it's already in my hand so you just have to
say "slice it please" and I'll do it for you.
> So it seems that there UpdateUIEvents can pass messages (such as
> "enable") back to the controls that raised the event. My questions are:
> are UpdateUIEvents the only type of event that can do this?
No. Some events can be vetoed by calling the Veto method of the event
object. The tree drag start event requires that event.Allow be called
to enable the tree to start a drag and drop, etc. There are probably
some others that I'm not thinking about at the moment.
> And what
> types of widgets will actually generate this type of event? Is it only
> menu item widgets that will do this?
Menus, toolbars and I think it can also be used for the simpler widgets,
like static text, buttons, etc.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list