[wxPython] wxDropTarget which accepts multiple data types

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.

Robert Olson wrote:

> 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?

I've already answered this privately, but just for completeness I'll copy it here too.

You should be able to call GetDataSize(format) on the composite data object in your OnData method for each data format you support. The one(s) with a size greater than whatever size it uses for "empty" are the one for which data is available.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

oh, I meant to respond to this here as well. Worked like a champ,
especially after I initialized my custom data with "" instead of None -
otherwise GetDataSize returrned a very large and incorrect number. I also
reinitialized the data objects after each drop, otherwise they held the
last value received.

--bob

···

On Thu, 14 Nov 2002, Robin Dunn wrote:

Robert Olson wrote:
> > 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?
>

I've already answered this privately, but just for completeness I'll
copy it here too.

You should be able to call GetDataSize(format) on the composite data
object in your OnData method for each data format you support. The
one(s) with a size greater than whatever size it uses for "empty" are
the one for which data is available.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org