我正在创建一个小应用程序必须能够接收网址。如果应用程序窗口是打开的,我应该能够从浏览器中拖动一个链接并将其放到应用程序中-应用程序会将URL保存到数据库中。在
我用Python/GTk创建这个。但是我对它的拖放功能有点困惑。那么,怎么做呢?在
一些实现拖放的示例代码(我的应用程序使用了一些这样的代码)。。。在import pygtk
pygtk.require('2.0')
import gtk
# function to print out the mime type of the drop item
def drop_cb(wid, context, x, y, time):
l.set_text('\n'.join([str(t) for t in context.targets]))
# What should I put here to get the URL of the link?
context.finish(True, False, time)
return True
# Create a GTK window and Label, and hook up
# drag n drop signal handlers to the window
w = gtk.Window()
w.set_size_request(200, 150)
w.drag_dest_set(0, [], 0)
w.connect('drag_drop', drop_cb)
w.connect('destroy', lambda w: gtk.main_quit())
l = gtk.Label()
w.add(l)
w.show_all()
# Start the program
gtk.main()