How to use wxpython's DataViewCtrl Drag and Drop?

58 views
Skip to first unread message

Jan H.

unread,
Feb 24, 2015, 9:51:19 AM2/24/15
to wxpytho...@googlegroups.com

I want to use drag&drop in combination with wx.dataview.DataViewCtrl, so I started with trying to reorder rows using Drag&Drop. I was unable to find any examples how to do this correctly in wxpython, but anyhow, I managed to get it partially working (see attached samplecode).

Unfortunately, event.GetDataObject() always returns None in my on_drop function. Any pointers how to get the DataObject I assigned in on_begin_drag? What am I doing wrong?

Thanks in advance!

Setup:

  • ArchLinux (64-Bit)
  • python2 2.7.9-1
  • wxpython 3.0.2.0-1
  • gtk3 3.14.8-1
  • gnome-shell 3.14.3-2
samplecode.py

Jan H.

unread,
Feb 25, 2015, 7:41:00 AM2/25/15
to wxpytho...@googlegroups.com
The only example of the DataViewCtrl-Drag&Drop-mechanism I found is this:

In Lines 892-893, they get the data like this:
> wxTextDataObject obj;
> obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() );

This is not possible in Python (at least I think so).

Thus, I'm coming to the conclusion that this is a bug which renders Drag&Drop with DataViewCtrl unusable. If I call event.GetDataBuffer() in the handler function of an EVT_DATAVIEW_ITEM_DROP, I get <Swig Object of type 'void *' at 0x1a59b30>. Since that C pointer is basically useless in python (I think so at least), that function should return a proper Python buffer object. And, if I look at the docs for wx.Image, which also has a GetDataBuffer()-method, it states: "Returns a writable Python buffer object that is pointing at the RGB image data buffer inside the wx.Image."
I my assumption correct? Should I open a trac ticket?

Robin Dunn

unread,
Mar 6, 2015, 8:32:44 PM3/6/15
to wxpytho...@googlegroups.com
Jan H. wrote:
> The only example of the DataViewCtrl-Drag&Drop-mechanism I found is this:
> http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/samples/dataview/dataview.cpp?revision=78273&view=markup
> (Line 875)
>
> In Lines 892-893, they get the data like this:
> > wxTextDataObject obj;
> > obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(),
> event.GetDataBuffer() );
>
> This is not possible in Python (at least I think so).
>
> Thus, I'm coming to the conclusion that this is a bug which renders
> Drag&Drop with DataViewCtrl unusable. If I call event.GetDataBuffer() in
> the handler function of an EVT_DATAVIEW_ITEM_DROP, I get <Swig Object of
> type 'void *' at 0x1a59b30>. Since that C pointer is basically useless
> in python (I think so at least), that function should return a proper
> Python buffer object. And, if I look at the docs for wx.Image, which
> also has a GetDataBuffer()-method, it states: "Returns a writable Python
> buffer object that is pointing at the RGB image data buffer inside the
> wx.Image."
> I my assumption correct? Should I open a trac ticket?
>

I think I need to do a little more tweaking in Phoenix to get those DnD
related methods in the DataViewEvent working properly. I'll try to get
to it soon, and will update one of the samples to show how to do it.




--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages