I wanted to build an app which accepts drags. I looked up the drag and drop tutorial but it wasn't clear to me how I would make my app accept drags from other applications. Also, I needed to produce the necessary TargetEntries which I didn't know how to do.
The following example is ported from the pygtk tutorial but uses pygi. Maybe it's possible to include that somehow in the current tutorial.
#!/usr/bin/env python
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
def motion_cb(wid, context, x, y, time):
Gdk.drag_status(context, Gdk.DragAction.COPY, time)
return True
def drop_cb(wid, context, x, y, time):
l.set_text('\n'.join([str(t) for t in context.list_targets()]))
context.finish(True, False, time)
return True
w = Gtk.Window()
w.set_size_request(200, 150)
w.drag_dest_set(0, [], 0)
w.connect('drag-motion', motion_cb)
w.connect('drag-drop', drop_cb)
w.connect('destroy', lambda w: Gtk.main_quit())
l = Gtk.Label()
w.add(l)
w.show_all()
Gtk.main()
I wanted to build an app which accepts drags. I looked up the drag and drop tutorial but it wasn't clear to me how I would make my app accept drags from other applications. Also, I needed to produce the necessary TargetEntries which I didn't know how to do.
The following example is ported from the pygtk tutorial but uses pygi. Maybe it's possible to include that somehow in the current tutorial.