Question

I'm using PyGObject but I think this is a question that could be adapted to all GTK, so if someone know how to do it using C or anything should work in python also.

I have two treeview, Active and Inactive, I load data from a Sqlite database and I can swap and drag & drop items from one to other. This is just an aestetic thing, if I click on one item on one treeview I want that a previous selected item on the other be deselected.

It appears that nobody had to do something similar because I didn't found anything about it on the net.

Was it helpful?

Solution

At the risk of being too basic (perhaps I misunderstand the problem), to manipulate treeview selections, you use the GtkTreeSelection object returned from GtkTreeView.get_selection. You can attach to signals on this object, change the current selection,etc.

OTHER TIPS

To turn off selection in the other view, you can get its selection mode property and set to GTK_SELECTION_NONE. To turn it back on upon clicking, my thought was that you could catch a grab-focus signal, set the selection mode to single in that view, and set the selection mode to none in the other view:

 (connect view-1 'grab-focus
       (lambda args
         (set-mode (gtk-tree-view-get-selection view-1) "GTK_SELECTION_SINGLE")
         (set-mode (gtk-tree-view-get-selection view-2) "GTK_SELECTION_NONE")))

(That code is using the guile-gnome wrapper but the concept should be the same in any language binding.) A problem with this approach is that now in order to make a selection you must click the tree view twice - once to grab the focus, and again to make the selection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top