작은 응용 프로그램을 만들고있어 URL을 수신 할 수 있어야합니다. 앱 창이 열리면 브라우저에서 링크를 드래그하여 앱에 드롭 할 수 있어야합니다. 그러면 앱이 URL을 데이터베이스에 저장합니다.Python GTK 끌어서 놓기 - 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()
당신이해야 할 수도 있다는 점에서주의 데이터가 URI리스트의 형식이면, data.get_uris()를 호출합니다. 예를 들어, konqueror/nautilus에서 창까지의 파일 목록을 DnD하면 'text/uri-list'라고 말하면 GtkSelectionData의 get_data()는 None을 반환합니다. –
윈도우를 드래그하여 텍스트를 유지하는 라벨의 마우스를 놓지 않고 윈도우 창 밖으로 드래그하면 바람직하지 않은 동작이 발생할 수 있습니다. 라벨을 지우는 것이 더 합리적인 것 같습니다. – demongolem