[pygtk] About buttons in a Treeview...

John Finlay finlay at moeraki.com
Tue Jan 31 08:01:04 WST 2006


Did you think about using Labels and SpinButtons in a Table as an 
alternative to using a TreeView?

John

A.Ferrarin at tieffesistemi.com wrote:
> 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
>
>   



More information about the pygtk mailing list