[pygtk] CheckButton & signals
Alessandro Dentella
sandro at e-den.it
Mon Jun 30 19:30:13 WST 2008
Hi, rereading myself I see I can improve the explanation.
While trying to implement the tri-state checkbutton I stumbled across some
problems that I think should be trivial.
I added to a check butto a callback to get into inconsistent state (and it
works) but a subsequent click triggers the function that toggles it
again. So I only loop trhought True/inconsistent
So I wanted to stop the native togggling and was not able. And this is poit
1 below:
---- previuous essage ----------
i think my problem is very simple but I didn't get it right...
All I want to do is substitute normal toggling of CheckButton to step into
inconsisten mode. I have the working situation in a CellRenderer but now I
need it also for normal Widgets.
1. I thought I'd connect to 'toggled' signal and 'return True'. But that
seems to not be enought. Isn't that a general rule? After a handler
returns True, no more processing is done on that signal?
In the FAQ I see widget.emit_stop_by_name but I was not able to use it
(and I don't remember I have ever used it)
2. I thought I got the wrong signal: how should I verify which is the
correct one (the one that trigges the change of "active" status)?
c.connect('toggled', lambda b: True)
c.connect('clicked', lambda b: True)
still toggles Between active on/off
3. tere is a difference if I use set_active(is_active) or if I set
directly the value: button.active = is_active.
In the first case the example below loops into inconsistent/consistent
In the second it loops throught active/inactive
thaks in advance for any help
sandro
*:-)
here is the test I used:
import gtk
class MyCheck(object):
def __init__(self):
w = gtk.Window()
h = gtk.VBox()
w.add(h)
b = gtk.Button('reset')
c1 = gtk.CheckButton('toggle and clecked -> True')
c2 = gtk.CheckButton('toggle with null')
h.add(b)
h.add(c1)
h.add(c2)
b.connect('clicked', self.butt_cb)
c1.connect('toggled', lambda b: True)
c1.connect('clicked', lambda b: True)
c2.connect('clicked', self.toggle_with_null_cb)
self.c2 = c2
w.show_all()
def toggle_with_null_cb(self, button):
"""a toggle function that loops through inconsinstent state also
"""
value = button.get_active()
null = button.get_inconsistent()
## - -> True -> False
if null: # - next is True
print "turn to True"
button.set_active(True)
button.set_inconsistent(False)
else:
if value == True:
print "turn to False"
button.set_inconsistent(False)
button.set_active(False)
else:
print "turn to Null"
button.set_inconsistent(True)
return True
def butt_cb(self, *args):
self.c2.set_inconsistent(False)
self.c2.set_active(False)
if __name__ == '__main__':
m = MyCheck()
try:
gtk.main()
except KeyboardInterrupt:
import sys
sys.exit()
More information about the pygtk
mailing list