3

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.

gpoo
  • 8,408
  • 3
  • 38
  • 53
andyinno
  • 1,021
  • 2
  • 9
  • 24

2 Answers2

2

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.

ergosys
  • 47,835
  • 5
  • 49
  • 70
  • 1
    you was near the solution but made me a step ahead. The solution to my problem was: `self._treeview_enabled.connect('cursor-changed', self.treeview_row_selected)` and in the function called `selection = self._treeview_disabled.get_selection() selection.unselect_all()` thank you for pointing me on the right way with the GtkTreeSelection object that for what I saw is not straightforward. – andyinno May 22 '12 at 06:44
0

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.

gcbenison
  • 11,723
  • 4
  • 44
  • 82
  • I didn't tried your solution but focused on mine, I think mine, using get_selection and unselect_all is more cleaner than yours. in any case thank you for your reply, – andyinno May 22 '12 at 07:34