logo       

using the same callback for a check menu and a toggle toolbutton: msg#00107

gnome.gtk+.python

Subject: using the same callback for a check menu and a toggle toolbutton

Hi,

I have a toggle button on my toolbar and a check menu in my menu. They do the same thing and must stay sincronized - when I check the menu, the toggle button get's activated, for example.

Both widgets show the state of an internal flag (for example __zoomBestFit).

What's the simplest way to handle this? What is the best way?

What I do now:

1. I have the internal flag: self.__zoomBestFit
2. I have my callback that calls doToggleZoomBestFit()
3. I have a flag that prevents nested calls of the doZoomBestFit()

class Window(...):
def __init__(...):
...
self.__flagZoomBestFit = False
self.__zoomBestFit = False
...

...

def doToggleZoomBestFit(self):
if self.__flagZoomBestFit:
return
self.__flagZoomBestFit = True
self.__zoomBestFit = not self.__zoomBestFit

... # do something usefull
... # set the new state of toolbutton
... # set the new state of the menu

self.__flagZoomBestFit = False

To keep the consistency between the check menu and the toggle button, the doToggleZoomBestFit sets explictly their new state, to both of them. Unfortunatelly, this generates events and the function is called again and again. To prevent this I have added the self.__zoomBestFit flag. But this is not nice at all and the code starts to be hard to maintain once you have a lot of togglebuttons and check menus.

How should this be done?

How can I prevent the emission of the messages when I explictly set the state of the check menu and of the toggle button?

TIA,

Ionutz
_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise