drag-and-droppygtkgtktreeview

Prevent Treeview selection loss on drag and drop


I have a gtk.Treeview setup as a drag source:

self.drag_source_set(gtk.gdk.BUTTON1_MASK, targets, gtk.gdk.ACTION_COPY)

and it's TreeSelection is set to SELECT_MULTIPLE.

But everytime I try to drag a multi row selection, the cursor jumps to the current mouse position, resetting the selection to the current row. Even though the mouse is above one of the selected rows. It only works when I hold down the Shift or Ctrl button down.

What is going on?

Edit 1:

I have set up a bare-bones treeview to rule out any bugs in my code and it does the same thing.

Edit 2:

I found a code snippet that does what I want. It's from the quod libet sources, called MultiDragTreeView.


Solution

  • I found a code snippet that does what I want. It's from the quod libet sources, called 'MultiDragTreeView'. Quoting the docstring:

    """TreeView with multirow drag support:
    * Selections don't change until button-release-event...
    * Unless they're a Shift/Ctrl modification, then they happen immediately
    * Drag icons include 3 rows/2 plus a "and more" count"""