Treeview drag-and-drop



Hi,

I'm having problems with pygobject treeview drag-and-drop. The attached
minimal example program shows that the drag-data-received callback is
never called..

The also attached analogous pygtk version works as expected.

Am I doing something wrong, or shall I report a bug?

Thanks for any hint,
Holger
#!/usr/bin/python
from gi.repository import Gtk
from gi.repository import Gdk

class DndTester(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="CellRendererText Example")
        
        # dnd
        window_targets = [Gtk.TargetEntry.new("text/uri-list", Gtk.TargetFlags.OTHER_APP, 1)]
        self.drag_dest_set(0, window_targets, Gdk.DragAction.COPY)
        self.connect('drag-motion', self._drag_motion_cb)
        self.connect('drag-leave', self._drag_leave_cb)
        self.connect('drag-drop', self._drag_drop_cb)
        self.connect("drag-data-received", self._drag_data_received_cb)
        
        self.set_default_size(200, 200)

        self.add(Gtk.Label("Drop files from Nautilus here"))

    def _drag_data_received_cb(self, widget, context, x, y, data, info, time):
        print('drag data received')
        if selection_data.get_length() > 0:
            Gtk.drag_finish(context, True, False, time)
        else:
            Gtk.drag_finish(context, False, False, time)

    def _drag_motion_cb(self, widget, context, x, y, time):
        Gdk.drag_status(context, Gdk.DragAction.COPY, time)
        widget.drag_highlight()
        return True

    def _drag_leave_cb(self, widget, context, time):
        widget.drag_unhighlight()

    def _drag_drop_cb(self, widget, context, x, y, time):
        targets = {}
        for atom in context.list_targets():
            targets[atom.name()] = atom
        if "text/uri-list" in targets:
            print("Requesting data")
            widget.drag_get_data(context, targets["text/uri-list"], time)
        else:
            Gtk.drag_finish(context, False, False, time)
        return True


win = DndTester()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
#!/usr/bin/python
import pygtk
import gtk

class DndTester(gtk.Window):

    def __init__(self):
        gtk.Window.__init__(self)
        
        # dnd
        window_targets = [("text/uri-list", gtk.TARGET_OTHER_APP, 1)]
        self.drag_dest_set(0, window_targets, gtk.gdk.ACTION_COPY)
        self.connect('drag-motion', self._drag_motion_cb)
        self.connect('drag-leave', self._drag_leave_cb)
        self.connect('drag-drop', self._drag_drop_cb)
        self.connect("drag-data-received", self._drag_data_received_cb)
        
        self.set_default_size(200, 200)

        self.add(gtk.Label("Drop files from Nautilus here"))

    def _drag_data_received_cb(self, widget, context, x, y, selection_data, info, time):
        print('drag data received')

    def _drag_motion_cb(self, widget, context, x, y, time):
        gtk.gdk.DragContext.drag_status(context, gtk.gdk.ACTION_COPY, time)
        widget.drag_highlight()
        return True

    def _drag_leave_cb(self, widget, context, time):
        widget.drag_unhighlight()

    def _drag_drop_cb(self, widget, context, x, y, time):
        targets = {}
        for atom in context.targets:
            targets[atom] = atom
        if "text/uri-list" in targets:
            print("Requesting data")
            widget.drag_get_data(context, targets["text/uri-list"], time)
        else:
            gtk.drag_finish(context, False, False, time)
        return True


win = DndTester()
win.connect("delete-event", gtk.main_quit)
win.show_all()
gtk.main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]