I am trying to configure my text file viewer to open files by dragging them onto it. I’ve looked at several tutorials and tried to imitate them, but my widget never seems to be receiving the “drag_data_received” signal. Here, self.topLevel is a gtk.Window widget, the root of my application, and this is the last bit of the code for setting it up. I’ve confirmed that dragging text files onto it doesn’t call OnDrop at all.
def OnDrop(widget, context, x, y, sel, targetType, timestamp):
print context.actions
print context.targets
return True
self.topLevel.connect("drag_data_received", OnDrop)
self.topLevel.drag_dest_set(gtk.DEST_DEFAULT_DROP |
gtk.DEST_DEFAULT_MOTION |
gtk.DEST_DEFAULT_HIGHLIGHT, [("text/*", 0, 0)], gtk.gdk.ACTION_COPY)
self.topLevel.show_all()
I realized that my application was getting the signal, but the TextView widget that I was dropping everything onto (because it occupied most of its window) was absorbing these signals and not calling my callback function; dropping the file onto any other part of the application fixed it. I got it to work by calling the TextView’s drop_dest_unset function.