[pygtk] About buttons in a Treeview...

A.Ferrarin at tieffesistemi.com A.Ferrarin at tieffesistemi.com
Tue Jan 31 07:07:37 WST 2006


I'm not able to find a CellRenderButton to put it inside a
TreeView. Somebody says that it's not a good solution and that's why it
doesn't exist. Mmm, I really don't understand why... I need it!

My treeview looks like this:

 +--------------+-----+-----+------+
 | item name    |less |value| more |
 +--------------+-----+-----+------+
 | item 1       | [-] | val |  [+] |
 | item 2       | [-] | val |  [+] |
 | item 3       | [-] | val |  [+] |
 | item 4       | [-] | val |  [+] |
 +--------------+-----+-----+------+

where you can click over [-] and [+] buttons to increment or decrement the
value between.
I tried the following solution with two gtk.CellRendererPixbuf() for each
[-] and [+] columns in my treeview widget and then connecting the
'cursor-changed' signal.

  treeview.connect('cursor-changed', self.cursor_changed)

Then, inside the cursor_changed callback function I check for the column
the user clicked:

  def cursor_changed(self, treeview):
     path,column=treeview.get_cursor()
     if not column: return
     colname=column.get_title()
     model,iter=treeview.get_selection().get_selected()

     if colname=='less':
        val+=1
     elif colname=='more':
        val-=1
     ...

I suppose this would be a dirty but functional solution to catch user
clicks over my "button", doesn't it?

Thanks

    Ale

-- 
+-----------------------------------------------------------------------+
 Alessandro Ferrarin     www.tieffesistemi.com     Tieffe Sistemi S.r.l.
tel. +39 02 76.11.52.15                       V.le Piceno 21 (PF.Dateo)
fax. +39 02 70.10.11.55                           20129 Milano - Italia
+-----------------------------------------------------------------------+







More information about the pygtk mailing list