[wxPython] wxPyDataObjectSimple

Could anybody offer example code for this class, please?

(I'm trying to make DnD of URLs work)

Gerhard

···

--
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')))

* 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')))

* Gerhard Häring <haering_linux@gmx.de> [2002-05-12 18:02 +0200]:

Could anybody offer example code for this class, please?

(I'm trying to make DnD of URLs work)

If I'd like to make a custom format that accepts these mime types (dunno
what they really are) how would I do that in wxPython?

[Trace] 21:23:14: (dnd) Drop target: drag has format: text/x-moz-url
[Trace] 21:23:14: (dnd) Drop target: drag has format: _NETSCAPE_URL

If it currently isn't possible, is there a way to do it in wxWindows? I
could then perhaps try to expose the functionality to wxPython.

Gerhard

···

--
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')))

* Gerhard H�ring <haering_linux@gmx.de> [2002-05-12 18:02 +0200]:
> Could anybody offer example code for this class, please?
>
> (I'm trying to make DnD of URLs work)

If I'd like to make a custom format that accepts these mime types (dunno
what they really are) how would I do that in wxPython?

[Trace] 21:23:14: (dnd) Drop target: drag has format: text/x-moz-url
[Trace] 21:23:14: (dnd) Drop target: drag has format: _NETSCAPE_URL

It may be possible with wxDataObjectComposite, adding a couple
wxCustomDataObjects to it. If there is something missing from the wxPython
wrappers that is needed to make it work please let me know.

If it currently isn't possible, is there a way to do it in wxWindows? I
could then perhaps try to expose the functionality to wxPython.

Look at how wxURLDataObject is implemented for wxMSW. It handles two data
types at once. It would be nice for the C++ guys to have the wxGTK version
of wxURLDataObject be able to handle the above types.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!