On Sat, 2005-19-02 at 14:15 +0200, Nikos Kouremenos wrote:
> I have a treeview with:
>
> COL1 COL2 COL3
> toggle | string | string
>
>
> I want if the user clicks on the text on a row of *col2* or *col3* to
> toggle the bool in the *col1*.
> I cannot find a way to do that in GTK.
>
Here are some code snipits from our app that do the same as you want.
In this case the first time a row is clicked it only selects that row,
the toggle is only changed on every other click in that same row. I
hope it is clear enough for you.
class PackageView(CommonTreeView):
""" Self contained treeview of packages """
def __init__(self):
""" Initialize """
# initialize the treeview
CommonTreeView.__init__(self)
# setup the treecolumn
self._column = gtk.TreeViewColumn(_("Packages"))
self._column.set_resizable(True)
self.append_column(self._column)
# connect to clicked event
self.connect("cursor_changed", self._clicked)
def _init_view(self):
""" Set the treeview column """
# add the toggle renderer
check = gtk.CellRendererToggle()
self._column.pack_start(check, expand = False)
self._column.add_attribute(check, "active", 1)
# set the last selected to nothing
self._last_selected = None
def _clicked(self, treeview, *args):
""" Handles treeview clicks """
# get the selection
package = get_treeview_selection(treeview, 1)
if not package:
if self._package_changed:
self._package_changed(None)
return
if package.full_name == self._last_selected:
model, iter = self.get_selection().get_selected()
check = model.get_value(iter, 1)
model.set_value(iter, 1, not check)
self._last_selected = package.full_name
--
Brian <[EMAIL PROTECTED]>
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/