Thomas Mills Hinkle wrote:
Hello -- I'm working with drag and drop and finding some frustrations.
I've noticed that text buffers and entry boxes have drag-n-drop enabled by default. If I open gedit, type some text and drag it across into my pygtk app, the text shows up in the widget without me having to do any coding.
However, if I open Mozilla Firefox and drag text, I'm out of luck -- the Entry and Textview widgets don't accept it.
Now here's the kicker: I have set up a treeView to accept drag-and-drop text on my own, basing my code on the TreeView tutorial (thanks!). My TreeView will accept text dragged from firefox, but not text dragged from gedit.
So, I imagine this means that firefox and gedit are offering up different types of selections. Of course, I would like to handle any kind of selection that I can turn into plain text. Perhaps the vital lines are...
self.ingTree.enable_model_drag_dest([('text/plain',0,0)], gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
Now I would think that gedit and other programs would be
offering up some variant of text/plain. So my question is: what are they
offering up? Can some point me to documentation of dnd types, etc. Is
there a simple way to create a pygtk test program that will tell
me what formats a selection I drag onto it is offering up?
Here's a small program that prints out the drag targets:
########################## #!/usr/local/env python
import pygtk
pygtk.require('2.0')
import gtkdef gettargets(wid, context, x, y, time):
for t in context.targets:
print t
return Truew = gtk.Window()
w.set_size_request(100, 100)
w.drag_dest_set(0, [], 0)
w.connect('drag_motion', gettargets)
w.show_all()gtk.main() ##########################
Running this and dragging from gedit I get:
GTK_TEXT_BUFFER_CONTENTS UTF8_STRING COMPOUND_TEXT TEXT STRING
As you can see gedit doesn't support text mime types so you would need to add the text targets to your drag destination - something like:
self.ingTree.enable_model_drag_dest([('text/plain',0,0),
('TEXT', 0, 1),
('STRING', 0, 2),
('COMPOUND_TEXT', 0, 3),
('UTF8_STRING', 0, 4)], gtk.gdk.ACTION_DEFAULT |
gtk.gdk.ACTION_COPY |
gtk.gdk.ACTION_MOVE)
Dragging from Netscape I get:
text/html text/unicode text/plain
gedit uses the TextView widget and doesn't support any of these targets. I suspect that Firefox is similar to Netscape and so you can't drag from Firefox to gedit and vice versa. You can cut and paste between the two. You can use the tutorial program:
http://www.moeraki.com/pygtktutorial/pygtk2tutorial/examples/getselection.py
to print out the selection targets.
John
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
