[wxpython-users] Re: code structure - suggestions? (classes
for gui, data, calculations...)
Robin Dunn
robin at alldunn.com
Mon May 19 09:39:01 PDT 2008
Don Dwiggins wrote:
> Peter Damoc wrote:
> The problem I've run into with this is the need to check all the button
> states after each "significant" change to the form. The solution I came
> up with was to incorporate the buttons into the MVC structure. In
> effect, a button is a view on a Boolean method of a model; when the
> method returns true, the button is enabled. To do this requires some
> setup, registering each button as an observer of the model, and
> arranging for the model to notify its observers when any change to the
> form occurs. Once set up, though, it becomes easy to manage the states
> of any number of buttons. If anyone's interested, I'll write up a short
> description of my implementation of this.
>
You can use EVT_UPDATE_UI events to help with this. The events are sent
when a menu is about to be shown for the menu items on that menu, and
periodically for other gui elements. Using your example of buttons
being enabled only when the app is in some particular state, you can
take care of it with a one-line event handler, like this:
def OnFooCheckState(self, evt):
evt.Enable(self.whatever.isActiveState())
Calling evt.Enable sets a flag for you want to use for this particular
widget, and when the event handler returns wx will know that evt.Enable
was called and will then propagate that setting on to the actual widget
it was making the inquiry for.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list