Thanks!!! It's confusing all right, but with your help I was indeed able
> to get my wxPyDropTarget accepting multiple data types using
> wxCustomDataObjects as the underlying data types.
Hi - I'm running across this same issue. I've got the underlying data objects thing going, but I'm currently stuck on determining which type it was that came in. I've tried querying each of the data objects, but I find that I get garbage returned from the custom data object when it isn't the one triggered - is this to be expected?
The code I'm using is at the end of the message.
thanks for any help,
--bob
class MultipleDropTarget(wxPyDropTarget):
def __init__(self, tool, cvi):
wxPyDropTarget.__init__(self)
self.tool = tool
self.cvi = cvi
self.create_data_objects()
def create_data_objects(self):
ulist_dobj = self.ulist_dobj = wxCustomDataObject(wxCustomDataFormat("VVUserList"))
file_dobj = self.file_dobj = wxFileDataObject()
both_dobj = wxDataObjectComposite()
both_dobj.Add(ulist_dobj)
both_dobj.Add(file_dobj)
self.data = both_dobj
self.SetDataObject(self.data)
# Called when OnDrop returns true. We need to get the data and
# do something with it.
def OnData(self, x, y, d):
print "OnData: %d, %d, %d\n" % (x, y, d)
# copy the data from the drag source to our data object
data = self.GetData()
if data:
user_data = self.ulist_dobj.GetData()
if user_data:
print "Have user data ", type(user_data)
#user_list = cPickle.loads(user_data)
#print "Got user list ", user_list
file_data = self.file_dobj.GetFilenames()
if file_data != :
print "have file data ", file_data
···
#
# Recreate the data objects so they're empty next time
# This is because I've not yet figured out how to determine
# the actual type of the incoming dropped data.
#
self.create_data_objects()
return d # what is returned signals the source what to do
# with the original data (move, copy, etc.) In this
# case we just return the suggested value given to us.