#! /usr/bin/python

# This code works on linux (displays drag motion feedback when DNDing
# both source buttons over the destination button)

# This code works on win32 with gtk 2.16.6
# This code does not work on win32 with gtk 2.20: one cannot DND source2 button (with set_icon_widget)

import gtk

w = gtk.Window()
w.connect('destroy', gtk.main_quit)

v = gtk.VBox()
w.add(v)

feedback = gtk.Label("")

def drag_begin(widget, context):
    i = gtk.Window(gtk.WINDOW_POPUP)
    i.set_decorated(False)
    i.add(gtk.Label("My own DND icon"))
    i.show_all()
    context.set_icon_widget(i, 0, 0)
    return True
    
def debug(widget, event, *p):
    feedback.set_text("%s (%s): %s" % (event.__class__.__name__, widget.__class__.__name__, str(p)))
    return False

source1 = gtk.Button("Source1")
source1.drag_source_set(gtk.gdk.BUTTON1_MASK, [], gtk.gdk.ACTION_COPY)
source1.drag_source_add_text_targets()
v.add(source1)

source2 = gtk.Button("Source2")
source2.drag_source_set(gtk.gdk.BUTTON1_MASK, [], gtk.gdk.ACTION_COPY)
source2.drag_source_add_text_targets()
source2.connect("drag-begin", drag_begin)
v.add(source2)

dest = gtk.Button("Destination")
dest.drag_dest_set(gtk.DEST_DEFAULT_ALL, [], gtk.gdk.ACTION_COPY)
dest.drag_dest_add_text_targets()
# This does not work either:
# dest.drag_dest_set_track_motion()
dest.connect('drag-motion', debug)
v.add(dest)

v.add(feedback)

w.show_all()
gtk.main()
