After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756072 - TreeView Drag and Drop broken when using TreeDragSource/TreeDragDest: SelectionData not passed back up signal chain
TreeView Drag and Drop broken when using TreeDragSource/TreeDragDest: Selecti...
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: gobject
3.20.x
Other Linux
: Normal major
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-05 04:29 UTC by Dustin Spicuzza
Modified: 2018-01-10 20:51 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dustin Spicuzza 2015-10-05 04:29:03 UTC
I've been trying to get drag/drop with a TreeView working by only using the 'high-level' API, but after playing with this for awhile and stepping through it using GDB it appears that the SelectionData object that the TreeModel is receiving is different from the object that the TreeView is processing, so when I set a URI in the SelectionData it isn't passed on, and thus the drag_data_received function never gets called. 

I've created a sample program that demonstrates this behavior, and contains some (currently disabled) code that is useful in showing what's happening.

https://gist.github.com/virtuald/c03602dc7218ca0ecd3c
Comment 1 Dustin Spicuzza 2015-10-06 01:39:20 UTC
I've added a vala example (courtesy of @sjohannes) which is mostly the same as the python version, except that it actually works. Definitely seems to be a python-specific bindings problem.
Comment 2 Dustin Spicuzza 2015-10-06 01:43:29 UTC
Appears to be a duplicate of https://bugzilla.gnome.org/show_bug.cgi?id=737587 ?
Comment 3 Dustin Spicuzza 2016-08-15 06:37:33 UTC
After some contemplatation and a bit more work than I expected, I have a hacked up version of the original code that works: https://gist.github.com/virtuald/c03602dc7218ca0ecd3c#file-treetest_hack-py

Basically, this hacky solution uses ctypes + gobject introspection to find the correct drag_data_get vfunction in the class, and put our own ctypes callback function that can access the selection data directly instead of using the one that pygobject would install (that won't work correctly). When it gets called, it uses the private qdata to get a pointer to the python wrapper, and calls the python object's drag_data_get vfunc with a wrapper around the selection data that allows the python function to directly modify the selection data. This allows the python program to utilize the high level DnD API.

Yes, this workaround is probably a bad idea. However, rewriting hundreds of lines of tricky DnD code seems worse to me.

I would love feedback on this approach, or better ways to go about this that aren't quite as hacky. I'm also open to helping figure out how to integrate it into PyGObject, or to help find/test a proper fix. However, I suspect a proper fix will be quite problematic, because of the reasons listed in 737587.
Comment 4 Dustin Spicuzza 2016-08-16 05:14:50 UTC
Ok, I've pushed an improved version of the hacky version now that features different forms of hacking -- but I think it's more likely to be stable:

- Converts all callback arguments to wrapped python objects via GObject.GValue
- Copies all of the selection data back to the callback's caller
- Don't actually have to rename the virtual function

In particular, realizing that GValue can be used to convert raw pointers to arbitrary objects in python was a great find. :)
Comment 5 GNOME Infrastructure Team 2018-01-10 20:51:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/104.