[pygtk] Drag from GTK+ and drop on MS Windows problem

nseigne nicolas.seigneurin at cea.fr
Thu Sep 4 21:59:35 WST 2008


Hi all,

I’m writing a small application that builds a file and I want the user to be
able to drag it from the main application window into his file explorer or
any other location just like it was the real file (in my case, the idea
would be to drag it on an email client window to post an attachment).
I got the drop on linux to work fine, but the same code on MS Windows
doesn’t get the drag_data_get signal…

Here is a simpler example I’ve built to make the point with text/plain (my
original app uses text/uri-list) : it pops up 2 windows. 
-	You can drag from the “source” window onto the “destination” window : the
window will display the time the drag_data_get was called.
-	You can drag from the “source” window to the file explorer or desktop : it
should create a file with a default name containing the same string
-	You can drag from the “source” window to a text editor window : it should
insert the same string into the text at the cursor location

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import time

def data_received(wid, c, x, y, s, t, time):
	print 'data_received'
	l.set_text(s.get_text())

w = gtk.Window()
w.set_title('Destination')
w.set_size_request(200, 150)
w.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
		                  gtk.DEST_DEFAULT_HIGHLIGHT |
		                  gtk.DEST_DEFAULT_DROP,
		                  [( "text/plain", 0, 80 )], gtk.gdk.ACTION_COPY)
w.connect("drag_data_received", data_received)
w.connect('destroy', lambda w: gtk.main_quit())
l = gtk.Label()
w.add(l)
w.show_all()

def data_get(wid, c, s, t, te):
	print 'data_get'
	now = time.time()
	s.set_text('data_get at %s' % time.ctime(now))

w2 = gtk.Window()
w2.set_title('Source')
w2.set_size_request(200, 150)
w2.drag_source_set(gtk.gdk.BUTTON1_MASK, [( "text/plain", 0, 80
)],gtk.gdk.ACTION_COPY)
w2.connect("drag_data_get", data_get)	
w2.connect('destroy', lambda w: gtk.main_quit())	
w2.show_all()			

print 'go !'

gtk.main()

On linux, everything goes as described.
On windows, the data_get signal is never received if I try to drop outside
the “destination” window (file explorer or desktop, not even text editor)

I have got something wring with the targets (tex/plain, text/uri-list) or is
this a limitation of gtk drag and drop on windows?
Thanks for your help.

I’m running :
-	Linux Ubuntu Feisty 7.04
o	Gnome 2.14.3
o	Python 2.5.1
o	Gtk 2.12.0
o	Pygtk 2.12.0
-	Windows XP
o	Python 2.5.1
o	Gtk 2.12.9
o	Pygtk 2.12.9

-- 
View this message in context: http://www.nabble.com/Drag-from-GTK%2B-and-drop-on-MS-Windows-problem-tp19309025p19309025.html
Sent from the Gtk+ - Python mailing list archive at Nabble.com.



More information about the pygtk mailing list