#!/usr/bin/env python

import gtk

class MyTextView(gtk.TextView):
    __gsignals__ = {
        'drag-motion': 'override',
        'drag-leave': 'override',
        'drag-drop': 'override',
        'drag-data-received': 'override',
    }
    
    def __init__(self):
        self.have_drag = False
        gtk.TextView.__init__(self)
    
    def do_drag_motion(self, context, x, y, timestamp):
        if not self.have_drag:
            self.have_drag = True
            # Highlight here

        if 'text/uri-list' in context.targets:
            context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
        else:
            context.drag_status(0, timestamp)
            
        return True

    def do_drag_leave(self, context, timestamp):
        if self.have_drag:
            self.have_drag = False
            # Unhilight here
            
        return True

    def do_drag_drop(self, context, x, y, timestamp):
        if 'text/uri-list' in context.targets:
            self.drag_get_data(context, 'text/uri-list', timestamp)
        else:
            context.finish(False, False, timestamp)
            
        return True

    def do_drag_data_received(self, context, x, y, selection, target_type, timestamp):
        context.finish(True, False, timestamp)
        return True

w = gtk.Window()
w.connect("destroy", lambda w: gtk.main_quit())
tv = MyTextView()
tv.set_editable(False)
w.add(tv)
w.resize(125, 125)

TARGET_TYPE_URI_LIST = 80
dnd_list = [ ( 'text/uri-list', 0, TARGET_TYPE_URI_LIST ) ]
tv.drag_dest_set(0, dnd_list, gtk.gdk.ACTION_COPY)

w.show_all()

gtk.main()
