Difference between TextDropTarget and DropTarget (Solved)

Hello,
I try to build a custom droptarget.
When it inherits from TextDropTarget, all work correctly
when it inherits from DropTarget, nothing happends. None of the inherited methods (OnEnter, OnDragOver, OnData,…) is called during the drag.
I’ve try super().SetDefaultAction(wx.DragCopy) in the constructor but that doesn’t change anything.

I doesn’t understand the fundamental difference between these two parent classes.

(for this tests I always use a TextDataObject as DataObject)

Thank you for any help or any idea…

Guillaume

PS: sorry for my bad english, it’s not my language

Platform and versions? How does your custom drop target differ from the one in the CustomDragAndDrop module in the demo?

The TextDropTarget is simply a subclass of DropTarget that is set up to work with text objects, and only text objects. If you application is already working the way you want with the TextDropTarget then there probably isn’t any need to change it.

Hello,
Thank you for your answer.
I use wxpython 3.0.2.0 and python 3.6.10 on linux (Gentoo)

I didn’t know the CustomDragAndDrop module in the demo.
By comparing, the lines

self.data = wx.TextDataObject()
self.SetDataObject(self.data)

was missing in the constructor. That surprises me that without these lines, not at all occur. But now it’s working… for TextDataObject.

For the second part of your answer, I doesn’t only use to drag text. But this was for testing one thing at a time.

Thank you

The wx.DropTarget base class has a much better implementation in 4.0 for the lower-level raw data functionality. If you need to use it like that then you’ll want to update. Another way to support more than one type of dropped data is to use wx.DataObjectComposite, which does work well in 3.0. There is also an example of that in the CustomDragAndDrop.py demo module.

I notice the difference between 3.0 and 4.0 for the wx.DropTarget.

If I understand well the doc, wx.DataObjectComposite is for supporting multiple formats.
In my situation, I just want to share multiple objects (more precisely, one object and informations on the drag source). wx.DataObjectComposite doesn’t seem to do that.

I can do that by passing a dictionnary with all the informations/objects to a wx.CustomDataObject but I don’t find that very clean.

My idea is to subclass wx.DataObjectSimple or wx.DataObject and add aditionnal fields in it. But perhaps it is not a good idea. All remarks will be appreciate :wink:

As a subsidiary question, in my CustomDropTarget, OnDrop is called and returns True, but OnData isn’t called and I doesn’t understand why (but perhaps it will be better in a new Topic ?)

At the bottom layers a data object used for DnD or the Clipboard is just a set of bytes. The different kinds of DataObject classes are really just different ways to convert to or from those bytes. There are some standard data format types that are well-known and other applications will know how to deal with too. Adding extra fields to the data object will not work, as that is not what is passed to the receiver of the data object. It’s just that bunch of bytes that is transferred.

For wxPython applications that need to transfer a more complex custom object it’s very easy to use a pickled or a jsonified representation of that object, since support for those kinds of things are built-in or easily available in 3rd-party libs. And example of that is shown in the demo with the “DoodleLines” custom data format.

Ok.
Thank you for the explanations.
I will look the example and try to follow this way.