[pygtk] Problem with CellRendererToggle

Pipen pipene at gmail.com
Sat Nov 18 01:28:33 WST 2006


Hi.

Each row in my TreeView contains a column with: toggle, pixbuf and
text renderer respectively. If need to maintain the following
situations:
- user clicks on the toggle - toggle receives 'toggled' event;
treeview row cursor should not change.
- user clicks on the rest of the row (pixbuf, text) - treeview row
cursor should change, toggle should not receive 'toggled' event.

The program does not work as I expected. I receive 'toggled' and
'cursor-changed' events no matter what part the user clicks. If the user
clicks on the toggle, the treeview row cursor changes to the row clicked
toggle is in.

The following code sets up the TreeView (SETS_COL_TOGGLE is 0,
SETS_COL_ICON is 1, SETS_COL_NAME is 2).

        store = gtk.TreeStore( bool, gtk.gdk.Pixbuf, str, int )
        col = gtk.TreeViewColumn( 'Sets' )
        # Toggle.
        cell = gtk.CellRendererToggle()
        cell.set_property( 'activatable', True )
        cell.connect_object( 'toggled', self.on_set_toggled, store )
        col.pack_start( cell, False )
        col.add_attribute( cell, 'active', SETS_COL_TOGGLE )
        # Pixbuf.
        cell = gtk.CellRendererPixbuf()
        col.pack_start( cell, False )
        col.add_attribute( cell, 'pixbuf', SETS_COL_ICON )
        # Text.
        cell = gtk.CellRendererText()
        col.pack_start( cell, True )
        col.add_attribute( cell, 'text', SETS_COL_NAME )
        self.treesets.append_column( col )
        self.treesets.set_model( store )

I successfuly set up this kind of tree behavior using Qt, I'm fighting
Gtk right now.
Any kind of suggestion would be appreciated.

-- 
Artur M. Piwko
AMP29-RIPE


More information about the pygtk mailing list