* Gerhard Häring <haering_linux@gmx.de> [2002-05-12 18:02 +0200]:
Could anybody offer example code for this class, please?
Here's what I've come up with in the meantime. Not that it would help
for my problem, though (see below for why):
class MyDataObject(wxPyDataObjectSimple):
def __init__(self, *args):
wxPyDataObjectSimple.__init__(self)
self.df = wxDataFormat(wxDF_TEXT)
self.SetFormat(self.df)
self.s = None
def GetDataHere(self):
return self.s
def SetData(self, s):
self.s = s
class MyURLDropTarget(wxPyDropTarget):
def __init__(self, window):
wxPyDropTarget.__init__(self)
self.window = window
self.data = MyDataObject()
#self.data = wxURLDataObject()
self.SetDataObject(self.data)
def OnDragOver(self, x, y, d):
return wxDragLink
def OnData(self, x, y, d):
if not self.GetData():
return wxDragNone
url = self.data.GetDataHere()
#url = self.data.GetURL()
self.window.Clear()
self.window.WriteText(url)
return d
(I'm trying to make DnD of URLs work)
The whole drag-and-drop stuff is highly confusing IMO. Can I only write
a data object for _one_ format in Python (like wxDF_TEXT)?
I've almost no idea what I'm doing here, but what I do know is that the
wxGTK implementation of Drag and Drop doesn't work _at all_ for text, if
you use GTK or KDE applications.
I've patched wxGTK with this:
*** /home/gerhard/src/wxGTK-2.3.2/src/gtk/dataobj.cpp Mon Dec 10 20:07:06 2001
--- dataobj.cpp Sun May 12 19:11:03 2002
···
***************
*** 134,140 ****
// text/uri-list for file dnd because compatibility is not important
// here (with whom?)
if (!g_textAtom)
! g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
if (!g_pngAtom)
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
if (!g_fileAtom)
--- 134,140 ----
// text/uri-list for file dnd because compatibility is not important
// here (with whom?)
if (!g_textAtom)
! g_textAtom = gdk_atom_intern( /*"STRING"*/ "text/plain", FALSE );
if (!g_pngAtom)
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
if (!g_fileAtom)
and now the URL example in wxPython works, as does my custom
MyDataObject class. Without this patch, neither work, nor can I drag and
drop pure simple text to wxPython or wxGTK apps. This is no surprise, as
the URL and Text DnD is one and the same thing in wxGTK. From the
comment in dataobj.cpp, it looks like the wxGTK author knows about this
problem, but has simply ignored it!?
Gerhard
PS: I've now submitted the above patch - unfortunately I've no experience with X
or GTK to be able to really fix DnD.
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))