Having trouble with wx.DataObjectComposite on OSX

I starting having weird troubles in my code when using wx.DataObjectComposite, but just on OSX (my code works under Windows and Linux). I’m not sure how to describe the problem except the run the test code below, on OSX. Make sure to use the right mouse button when dragging from the left window to the right. I get garble when I drag the text from the left window to the right (again, make sure to use the right button to drag…that’s what activates the “DropSource” on the wxPython side).

I think there is a unicode problem in either wxpython or wxwidgets, but have not been able to locate it. I thought that I would first post this to make sure that other people could see the same behavior.

Code attached. It’s just a slightly modified version of the wx.DataObjectComposite sample that can be found on the wxWiki. Can someone with a mac run this and see if you see garble?

Thanks,

Daniel Hyams

dndbug.py (4.65 KB)

Yes, I see it. It seems to be something to do with both the source and the destination being in wx, as I can drag text to other applications and it works (although there is an assertion about unknown drag result code) and if I drag text from another application to the sample then it works. And it does seem to be only related to using DataObjectComposite, after switching to a wx.TextDropTarget I was able to drag text successfully each time.

While trying to duplicate the problem in the C++ DnD sample I noticed that your sample program was now mostly working (sometimes there would be one or two garbage characters at the end) so it seems it is a transient problem probably dependent on what may already be in certain memory locations...

I'll try to poke at this a little more later.

···

On 2/29/12 3:49 PM, dhyams wrote:

I starting having weird troubles in my code when using
wx.DataObjectComposite, but just on OSX (my code works under Windows and
Linux). I'm not sure how to describe the problem except the run the test
code below, on OSX. Make sure to use the right mouse button when
dragging from the left window to the right. I get garble when I drag the
text from the left window to the right (again, make sure to use the
right button to drag...that's what activates the "DropSource" on the
wxPython side).

I think there is a unicode problem in either wxpython or wxwidgets, but
have not been able to locate it. I thought that I would first post this
to make sure that other people could see the same behavior.

Code attached. It's just a slightly modified version of the
wx.DataObjectComposite sample that can be found on the wxWiki. Can
someone with a mac run this and see if you see garble?

--
Robin Dunn
Software Craftsman

Thanks Robin;

Yes, I see it. It seems to be something to do with both the source and
the destination being in wx, as I can drag text to other applications
and it works (although there is an assertion about unknown drag result
code) and if I drag text from another application to the sample then it
works. And it does seem to be only related to using
DataObjectComposite, after switching to a wx.TextDropTarget I was able
to drag text successfully each time.

Right, I meant to mention that about wx.TextDropTarget; I get the same
result, in that it works if I use wx.TextDropTarget instead of
wx.DataObjectComposite.

While trying to duplicate the problem in the C++ DnD sample I noticed
that your sample program was now mostly working (sometimes there would
be one or two garbage characters at the end) so it seems it is a
transient problem probably dependent on what may already be in certain
memory locations...

Right, I guess it is using a pointer that is not pointing at anything
in particular, inside of wxWidgets.

I don't know if it helps (I don't have the version numbers right in
front of me at the moment), but I tried switching out the wxPython
installations that I had available. It did not seem to matter if I
used cocoa, or if I switched between the 2.8 and 2.9 series wxpythons,
the problem occurred every time.

Slight correction to the below; it works for me if I comment out the few lines in YourDropTarget such that it never used wx.DataObjectComposite, but wx.TextDataObject instead. In other words, call self.SetDataObject with self.textdo as the argument, instead of self.do, and then make the appropriate mod to the OnData() function to call self.textdo.GetText() directly without the checking for the appropriate data format (which is not valid for wx.TextDataObject).

···

On Wednesday, February 29, 2012 6:49:10 PM UTC-5, dhyams wrote:

I starting having weird troubles in my code when using wx.DataObjectComposite, but just on OSX (my code works under Windows and Linux). I’m not sure how to describe the problem except the run the test code below, on OSX. Make sure to use the right mouse button when dragging from the left window to the right. I get garble when I drag the text from the left window to the right (again, make sure to use the right button to drag…that’s what activates the “DropSource” on the wxPython side).

I think there is a unicode problem in either wxpython or wxwidgets, but have not been able to locate it. I thought that I would first post this to make sure that other people could see the same behavior.

Code attached. It’s just a slightly modified version of the wx.DataObjectComposite sample that can be found on the wxWiki. Can someone with a mac run this and see if you see garble?

Thanks,

Daniel Hyams

I think this one is solved, but I sure would like more experienced eyes to take a glance over it.

In src/common/dobjcmn.cpp, wxDataObjectComposite::SetData calls SetData for the data object that it deems appropriate, but fails to pass “format” as the first argument. After putting that argument in, everything seems to work. The TextDataObject was getting ascii characters as the string, but was converting it as if the data were unicode.

There is a lot of schizophrenia present in the SetData() calls in that class hierarchy, and I don’t claim to understand it all.

The patch, against the wxwidgets shipped with wxpython 2.9.1.1, is below. I have recompiled and verified that things work for the sample code and my application under OSX. I have no way of checking Windows, but I’ll try Linux later and make sure that things still work there even with the change.

— dobjcmn.cpp.orig 2012-03-02 00:19:20.000000000 -0500

+++ dobjcmn.cpp 2012-03-02 00:20:02.000000000 -0500

@@ -234,7 +234,7 @@

wxT(“unsupported format in wxDataObjectComposite”));

m_receivedFormat = format;

  • return dataObj->SetData( len, buf );
  • return dataObj->SetData(format, len, buf );

}

// ----------------------------------------------------------------------------

···

On Wednesday, February 29, 2012 6:49:10 PM UTC-5, dhyams wrote:

I starting having weird troubles in my code when using wx.DataObjectComposite, but just on OSX (my code works under Windows and Linux). I’m not sure how to describe the problem except the run the test code below, on OSX. Make sure to use the right mouse button when dragging from the left window to the right. I get garble when I drag the text from the left window to the right (again, make sure to use the right button to drag…that’s what activates the “DropSource” on the wxPython side).

I think there is a unicode problem in either wxpython or wxwidgets, but have not been able to locate it. I thought that I would first post this to make sure that other people could see the same behavior.

Code attached. It’s just a slightly modified version of the wx.DataObjectComposite sample that can be found on the wxWiki. Can someone with a mac run this and see if you see garble?

Thanks,

Daniel Hyams

For reference, ticket created.

http://trac.wxwidgets.org/ticket/14101

···