Skip to content

Tkdnd file drag to Gtk3 based app is ignored #66

@eric-gilbertson

Description

@eric-gilbertson

tkdnd file drag into Gtk3 apps does nothing, e.g. the drop is accepted but the file is not transferred. The issue is that Gtk3 based apps get the file list in their drop callback by calling data.get_uris() which returns an empty list when the drop originator is tkdnd. The root problem is that the drop handler receives the file drop as a UTF8_STRING rather than text/uri-list type even though the drag source type is DND_FILES.

The issue is demonstrated with the following app. If you drag the file from the drag.tcl demo program into the Gtk test app listed below you get messages to stdout indicating that the transfer was received as a string but not as a uri-list. However when a file is transferred from the Natilus finder tool in Ubuntu then the file name is returned from both of the get calls.

Gtk3 drop handler 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.COPY)
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