Hey all,
I was wondering, what is an easy way to check if a variable returns True or False, and if true, enable the copy menu item, but if it’s false, disable it?
I know that this menu.Enable(menuitem, False) will disable a menu item, but how would I get the program to loop through this, constantly checking if that variable was true, and not just checking it when I create the menu?
or would it be easier to just enable/disable that item whenever I initiate an event that changes the variable?
Thanks
Hey all,
I was wondering, what is an easy way to check if a variable returns True or False, and if true, enable the copy menu item, but if it's false, disable it?
I know that this menu.Enable(menuitem, False) will disable a menu item, but how would I get the program to loop through this, constantly checking if that variable was true, and not just checking it when I create the menu?
or would it be easier to just enable/disable that item whenever I initiate an event that changes the variable?
Take a look at EVT_UPDATE_UI events. There is an example in the doodle sample and in a few places in the lib. Basically the system calls your event handlers before the menu us shown and you just need to call a method of the event object giving it your boolean value, and then it will take care of enabling or disabling the menu item for you.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
There's actually a different idiom that you can use with wxPython.
Check out Menu.py in the wxPython demo, but the basics are that an
event called EVT_UPDATE_UI will fire your callback function just
before the menu is shown. So, rather than continually polling your
application to change the state of your menu items, you can let
wxPython tell you when it's time to update the state.
HTH,
Rob
···
On 10/12/07, Trey K <trey.wxpython@gmail.com> wrote:
I know that this menu.Enable(menuitem, False) will disable a menu item, but
how would I get the program to loop through this, constantly checking if
that variable was true, and not just checking it when I create the menu?
or would it be easier to just enable/disable that item whenever I initiate
an event that changes the variable?