[pygtk] About buttons in a Treeview...
Danny Milosavljevic
danny.milo at gmx.net
Sat Feb 4 11:05:07 WST 2006
Hi,
Am Dienstag, den 31.01.2006, 00:07 +0100 schrieb
A.Ferrarin at tieffesistemi.com:
> 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 | [+] |
> +--------------+-----+-----+------+
I can see that at the beginning, this looks like a good idea (especially
since it's would be easy to implement the actual "+" and "-" because
they only need to apply to one value, and the one in the current row to
boot).
But it gets old very quickly. Too. many. buttons.
The less button-in-the-face way to do that is:
+--------------+-----+
| item name |value|
+--------------+-----+ [Increment Value]
| item 1 | val | [Decrement Value]
| item 2 | val |
| item 3 | val |
| item 4 | val |
+--------------+-----+
>
> where you can click over [-] and [+] buttons to increment or decrement the
> value between.
I presume that your application has specific requirements that
neccessite these kind of buttons (like for example the user has to
change about 23 values in 20 seconds - which he only can if the buttons
are 1) close to the value - and 2) large enough)
The latter being probably why buttons aren't possible in a treeview.
They would be HUGE and ruin the row spacing of the tree (the button
would make every row very tall, although there is just a little bit of
actual information shown)
If you make them small like for example those checkbuttons that _do_
work in a treeview (cellrenderertoggle), users will hate them because
they are too hard to "hit".
> 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?
yes.
cheers,
Danny
More information about the pygtk
mailing list