[pygtk] Drag row from a TreeView onto an EventBox

Stephen English steve at secomputing.co.uk
Tue Nov 28 01:31:44 WST 2006


I am struggling to fire suitable events when dragging a row from a treeview
onto an eventbox. The code at http://phpfi.com/179070 and below doesn't run
the sig_dropped or drag_data_get functions. What am I missing?

Cheers,

Stephen English

import pygtk, gtk, gobject

def sig_dropped(widget, drag_context, x, y, selection, targettype, timestam=
p):
    print widget
    print drag_context
    print x
    print y
    print timestamp

def drag_data_get(widget, drag_context, selection_data, info, time):
    print widget, drag_context, selection_data, info, time, data
    selection_data.set(selection_data.target, 8, "moo")

image =3D gtk.Image()
image.set_from_file("schem.png")
image.show()
evbox =3D gtk.EventBox()
evbox.add(image)
evbox.connect("drag-data-received", sig_dropped)
evbox.drag_dest_set(gtk.DEST_DEFAULT_DROP, [('text/plain',
    gtk.TARGET_SAME_APP, 0)], gtk.gdk.ACTION_COPY)
evbox.show()

model =3D gtk.TreeStore(gobject.TYPE_STRING)
iter =3D model.insert_before(None, None)
model.set_value(iter, 0, "Test1")
iter =3D model.insert_before(None, None)
model.set_value(iter, 0, "Test2")
iter =3D model.insert_before(None, None)
model.set_value(iter, 0, "Test3")

tv =3D gtk.TreeView(model)
renderer =3D gtk.CellRendererText()
col =3D gtk.TreeViewColumn("Test", renderer, text=3D0)
tv.append_column(col)

tv.connect("drag-data-get", drag_data_get)
tv.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, [('text/plain',
        gtk.TARGET_SAME_APP, 0),], gtk.gdk.ACTION_COPY)

tv.set_property("width-request", 200)
tv.show()

hbox =3D gtk.HBox(False, 10)
hbox.pack_start(evbox, expand=3DTrue, fill=3DTrue, padding=3D0)
hbox.pack_start(tv, expand=3DFalse, fill=3DFalse, padding=3D0)
hbox.show()
win =3D gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect("delete-event", lambda w, x: gtk.main_quit())
win.add(hbox)
win.show()
gtk.main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20061127/4dc3e846/at=
tachment.htm


More information about the pygtk mailing list