Re: Nautilus as a drop target



Problem solved.

On Wed, Feb 17, 2010 at 3:34 AM, Robin Stocker <robin nibor org> wrote:
> You can also just provide the URI of the file to Nautilus. This is what drag
> and drop of a video from Totem does.

This what I was trying to do all along :) Anyway, I finally got it
working. I've attached an obligatory minimal python gtk sample for
future google searchers below. The problem I was having is that
Nautilus causes the drag_data_get_cb to be called twice. I was
erroneously clearing some needed state from my app after the first
call and simply not processing any further calls. Does anyone know why
Nautilus asks for the uri-list SelectionData twice? This seems to be
idiosyncratic to Nautilus.

Here's the python code:

import gtk

TARGET_TYPE_URI_LIST=0

uri='file://'+__file__

def drag_data_get_cb(widget, drag_context, selection_data, info, timestamp):
    if info == TARGET_TYPE_URI_LIST:
        selection_data.set_uris([uri])
        print 'drag_data_get_cb',uri

window=gtk.Window()
window.connect("destroy",lambda window:gtk.main_quit())
window.set_default_size(200,200)
button=gtk.Button("Drag Me To Your File Manager")
window.add(button)
target_list=[]
target_list=gtk.target_list_add_uri_targets(target_list,TARGET_TYPE_URI_LIST)
button.drag_source_set(gtk.gdk.BUTTON1_MASK,
                  target_list,gtk.gdk.ACTION_COPY)
button.connect("drag-data-get",drag_data_get_cb)
window.show_all()
gtk.main()


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