Skip to content

tkinterdnd2 file drag into Gtk3 apps like Nautilus does nothing #14

Description

@eric-gilbertson

tkinterdnd2 file drag into Gtk3 apps like Nautilus does nothing. The issue is that Gtk3 based apps get the file list in the drop callback by calling data.get_uris() which returns an empty list when the drop source is tkinterdnd2 based. I know that the basic operation is correct because the file name in the Gtk app can be obtained by calling data.get_data(). The problem appears to be how to configure the tkinterdnd2 drag source so that the file list payload can be obtained from data.get_uris(). The issue is demonstrated with the following apps. If you drag the file from the trkinter source app into the Gtk drop app you will messages to stdout indicating that the transfer was received as a string but not as a uri-list.

Tkinter drag source app:

import os
import platform
from tkinterdnd2 import *
from tkinter import *

root = TkinterDnD.Tk()
root.withdraw()
root.title('TkinterDnD File DnD')
label = Label(root, text='Drag Me')
label.pack(padx=20, pady=20)

def drag_init(event):
return ((LINK), (DND_FILES), ("/tmp/test.txt"))

def drag_end(event):
print('Drag ended for widget:', event.widget)

label.drag_source_register(1, DND_FILES)
label.dnd_bind('<>', drag_init)
label.dnd_bind('<>', drag_end)

root.update_idletasks()
root.deiconify()
root.mainloop()

GTK3 drop receive app:

import gi
gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk

window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)

box = Gtk.HBox()
window.add(box)

def on_drag_data_received(widget, drag_context, x, y, data, info, time):
print("Received uris: {}".format(data.get_uris()))
print("Received data: {}".format(data.get_data()))

drop_button = Gtk.Button(label="Drop")
drop_button.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.LINK)
drop_button.drag_dest_add_uri_targets()
drop_button.connect("drag-data-received", on_drag_data_received)
box.add(drop_button)
window.show_all()
Gtk.main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions