Kevin Mehall

Multiple Selection + Drag and Drop in PyGTK

2010-01-14

There's no easy way to make PyGTK's TreeView drag and drop operations work together with multiple selection. When clicking to drag, it deselects all items except for the one under the cursor.

The solution is to trap the mouse click event. If the user does not drag, the click is synthesized when the mouse is released so that clicking one item to deselect others behaves normally.

I implemented this in GTG, but here it is in isolated form, under the MIT license, so you are free to re-use it.

The MultiDragDropTreeView class, DragDropTreeView class (that enables DnD operations) and a demo that compares them side-by-side can be downloaded below.

multi_select_drag_drop.py