Hi everyone!
I am using the reorderable and detachable properties of gtk.Notebook tabs
(pygtk 2.10).
Now I wanted to implement dragging a notebook tab to an event box, but somehow
my event box will not respond to the dnd event from the notebook tab. I am not
sure if I set up the target properly and I could not find any example on the
net.
The attached example illustrates my problem.
Best regards,
Niklas.
_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
import gtk
nb = gtk.Notebook()
# fill first notebook with tabs containing a label
for text in ("One", "Two", "Three"):
label = gtk.Label("\n%s\n"%text)
nb.append_page(label)
nb.set_tab_reorderable(label, True)
nb.set_tab_detachable(label, True)
# add event box
label = gtk.Label("Drop here")
event_box = gtk.EventBox()
event_box.set_size_request(-1, 40)
event_box.add(label)
# From the PyGTK documentation:
# "If you want a widget to interact with a notebook through DnD (i.e.:
# accept dragged tabs from it) it must be set as a drop destination
# and accept the target "gtk.NOTEBOOK_TAB". The notebook will fill the
# selection with a reference to the child widget that corresponds to
# the dropped tab."
event_box.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[("gtk.NOTEBOOK_TAB",gtk.TARGET_SAME_APP,42)],
gtk.gdk.ACTION_MOVE)
# set up dnd
def on_dnd_drag_leave(sender, context, time):
print "on_dnd_drag_leave"
sender.modify_bg(gtk.STATE_NORMAL, None)
def on_dnd_drag_motion(sender, context, x, y, time):
print "on_dnd_drag_motion"
color = gtk.gdk.Color(65535,0,0)
sender.modify_bg(gtk.STATE_NORMAL, color)
def on_dnd_drag_drop(sender, context, x, y, time):
print "on_dnd_drag_drop"
event_box.connect("drag-leave", on_dnd_drag_leave)
event_box.connect("drag-motion", on_dnd_drag_motion)
event_box.connect("drag-drop", on_dnd_drag_drop)
# put everything in a window
win = gtk.Window()
win.connect("destroy", gtk.main_quit)
vbox = gtk.VBox()
vbox.add(nb)
vbox.add(event_box)
win.add(vbox)
win.show_all()
gtk.main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/