[wxPython-users] what's reasonable to do in a idle handler
Phil Mayes
phil at philmayes.com
Sat Jul 22 12:28:37 PDT 2006
At 08:50 AM 7/22/2006, you wrote:
>Hi,
>I just thought I found an elegant way to maintain consistency in the gui of an
>app, i.e. enable/disable buttons in dependence on the state of other controls,
>by putting the relevant code in an idle handler, in contrast to checking
>consistency every time when something has been clicked. Is that a reasonable
>method in terms of e.g. cpu load? In the current implementation I'll call
>.Disable()/Enable() over and over again if nothing happens. It looks like it's
>working, but what happens if similar code runs parallel in many panels?
>Thanks for any comments, Christian
MFC uses a method like this to maintain the state of toolbar buttons etc.,
Google for ON_UPDATE_COMMAND_UI for more details.
Another way you might do this is to have a state table that maps the state
of the app to the controls that should be active. Any time something
happens that changes the state (timer expires, socket closes, mouse moves
over button, ... can be anything at all), call a function that
(de)activates all the controls corresponding to the new state. If you want
to be obsessive about it, note the old state also and only adjust controls
whose state has changed.
The nice thing about this approach is that it is easy to tweak the
interface, add new controls, etc. Changes only have to be made in one place.
Phil Mayes
More information about the wxpython-users
mailing list