TypeError: GetDataHere(self, buf: sip.voidptr): argument 1 has unexpected type 'DataFormat'


While converting a python2 package to python3, I’ve got an error “TypeError: GetDataHere(self, buf: sip.voidptr): argument 1 has unexpected type ‘DataFormat’”

The code follows this message, and it is “drag and drop” related.

It is somewhat wierd that GetDataHere fails after IsSupported returns True. Another wierd thing is that type of mydrag is DataObject in python2 and bibDataObject in python3. These are in OnData method.

Currently, I think that this is related to “wx.DataObject and derived classes” in migration guide.

Questions are:

  1. Is GetDataHere needs to be overridden/implemented? If so, is there any better samples?

  2. Is it good to work with DataObject as a base class? Change to DataObjectSimple?

  3. Why is return type (mydrag) different in python2/3?

My system is Debian(amd64), with python2.7.18 and 3.9.1. wxpython version is and 4.0.7 respectively. IDE used is pycharm.

I hope I am on the right track and appreciate any suggestion. If more information is necessary, I am happy to provide them.

Many thanks in advance.


class keyDropTarget(wx.DropTarget):      (*)
    def __init__(self, window):
        wx.DropTarget.__init__(self, bibDataObject()) 
(many lines)
    def OnData(self, x, y, result):
        pos = wx.Point(x, y)
        item, flags = self.keytree.HitTest(pos)
        newparentID, user, id = self.keytree.GetItemData(item)
        if self.GetData():
            mydrag = self.GetDataObject()
            if not mydrag.IsSupported(BIB.DnD_FORMAT):
            refdragged = pickle.loads(mydrag.GetDataHere(BIB.DnD_FORMAT))  (+)
(many lines)
class bibDataObject(wx.DataObject):   (**)
    """DataObject for DnD"""

    def __init__(self):
        wx.CustomDataObject.__init__(self, BIB.DnD_FORMAT)  (**)
        self.data = ""  

    def setObject(self, data):
        return self.SetData(pickle.dumps(data, True))  (+)

    def getObject(self):
        return pickle.loads(self.GetDataHere())   (+)
(many lines)

(*) in python2 “pyDropTarget” instead of “DropTarget”

(**) in python2, CustomDataObject. in python3, “DataObject” and “CustomDataObject” are checked

(+) in python2, “cPickle” instead of “pickle”, GetDataHere is here.

Error message looks like:

TypeError: GetDataHere(self, buf: sip.voidptr): argument 1 has unexpected type 'DataFormat'

DnD_FORMAT is defined as follows:

DnD_FORMAT = wx.DataFormat('bibus/dnd')        python3

DnD_FORMAT = wx.CustomDataFormat('bibus/dnd')   python2

self reply.

I have managed to find workaround for GetDataHere(). For the time being, I decided to disregard BIB.DnD_FORMAT. Without it, mydrag.GetData() works.

I somewhat think that return type problem is the clue for this issue.

Thanks for reading.