[pygtk] Let's split it up...

Tim Evans t.evans at aranz.com
Wed Jul 2 06:13:01 WST 2008


Alessandro Dentella wrote:
> Ok, I try to split it into very little bits...
> 
> I want a CheckButton that doesn't react to "click".
> 
> I thought to connect a handler to the signal "clicked" that just "return
> True" but it does not work. What's wrong?
> 
> sandro
> 
> 
> 
> w = gtk.Window()
> c1 = gtk.CheckButton('toggle and clicked -> True')
> w.add(c1)
> 
> c1.connect('toggled', lambda  b: True)
> c1.connect('clicked', lambda  b: True)
> w.show_all()
> gtk.main()

The clicked signal cannot be blocked by returning True, that sort of 
behaviour is mostly on event signals like 'button-press-event'.  I would 
say your best option is to subclass the checkbutton widget like this:

     class MyCheckButton(gtk.CheckButton):
         __gtype_name__ = 'MyCheckButton'

         do_clicked(self):
             pass

With just "pass" the nothing will happen when you click the button.  Put 
whatever code you want into that method.  The normal clicked behaviour 
of gtk.CheckButton can be triggered by calling the superclass method 
"gtk.CheckButton.do_clicked(self)" from within your method.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list