PyGtk 3 - Treeview Drag and drop (DnD) - Avoid deselection when dragging multiple rows
After selecting multiple rows in a Gtk.Treeview (with Gtk.SelectionMode.MULTIPLE option set), if you click on one of the selected rows to drag the entire selection... all the rows get deselected except the one being clicked on. So you end up actually dragging only one row. Here are some lines of code (I skipped the DnD part since that works fine).
...
def __init__(self):
# Create a new window
Gtk.Window.__init__(self, title="Hello World")
self.set_default_size(500, 500)
...
# create a liststore with one string column to use as the model
self.store = Gtk.TreeStore(str)
...
# create the TreeView using liststore
self.treeview = Gtk.TreeView(self.store)
# allow multiple selection
sel = self.treeview.get_selection()
sel.set_mode(Gtk.SelectionMode.MULTIPLE)
sel.set_select_function(self.my_sel_func, None)
...
def my_sel_func(self, selection, model, path, is_selected, data):
new_sel_iter = model.get_iter(path)
model, pathlist = selection.get_selected_rows()
is_allowed = True
for path_i in pathlist:
iter = model.get_iter(path_i)
# Check if iter in pathlist is_ancestor of the new_sel_iter
if model.is_ancestor(iter, new_sel_iter):
is_allowed = False
break
return is_allowed
...