I am porting liblarch, a library for handling directed acyclic graphs, from PyGTK (GTK2) to PyGObject introspection (GTK3). I ran into the problem with GtkTreeView.
The
GTG is a great piece of software! But it's far too slow, at least on my computer. So I've been writing a C++ library which displays a directed acyclic graph using a Gtk::TreeView, and I looked at the LibLarch source code a lot.
As far as I know, Python and C++ bindings of GTK share the same limitation, coming from GTK itself (I once looked at GTK source code to find exactly why it works like that): If you turn of drag-and-drop and sorting, drag-and-drop won't work. I offer three things you can do about it:
Make a patch to GTK which limits dnd when sorting is enabled, instead of completely blocking it
Implement sorting by yourself. It easy: start by loading your data to a sorted treeview. Now, every time the user drags and drops, move the dragged row to the new position using your sorting function. But leave GTK sorting off.
This can be done in addition to 2, it's a GUI design issue: In GtkTreeView you can insert an item between to sibling items, which doesn't make much sense in sorted trees. In terms of UI it's better to allow dropping only ON rows, not BETWEEN them. Example: Nautilus list-view works like this. The solution is either override the TreeView drag_data_received() default handler, or better than that in terms of maintainability: send your model a hint from the view telling the model whether the drop position is ON or BEFORE. If the position is BEFORE, make your tree's drop_possible() virtual override return false, and then you don't see the treeview's "you can drop here" didplay", thus you get a cleaner GUI.
2 and 3 is what I do in C++, you should be able to do that in Python easily :)
Also, a note regarding option 1: GtktreeView (or was is GtkTreeStore? I forgot) simply blocks any drop if sorting is enabled. If someone just fixes that (you... or me...), or at least writes a derived view class, we'll have a default clean GUI for sorted trees with dnd support.