Is it possible to set two DropTargets for one window

Maybe the following helps...

Cristina.

···

Date: Wed, 24 Nov 2004 19:19:03 -0600
From: Daniel Pozmanter <drpython@xxxxxxxxx>
Subject: Re: [wxPython-users] Newbie Drag and Drop :slight_smile:

Huge Thanks!

May I humbly suggest adding this to the demo? (Or I can write a
panel, if you'd like). This strikes me as a very useful thing to be
able to show new users how to do (Also, how to completely shut off
drag and drop).

It works perfectly with stc (Only you also need to use SetText for
self.text to ensure the file drag and drop works properly after
having performed a text drag and drop operation).

Best,
Dan

*************************************************

Daniel Pozmanter wrote:
> This sounds good, but I have never been able to get it working with a
> styled text control. I don't suppose you could provide a working
> example? (File and Text)?
>
> Whenever I try, (I set the drop target as DataObjectComposite,
> "Adding" the Text, File types. When going about dragging, the window
> is always "receptive", yet when I drop, whether or not it is a file
> or text, it always is picked up as text, and the data is always empty.

I havn't tried it with a STC but you would need to make a new drop
target something like this:

class MyCompositeDropTarget(wx.DropTarget):
     def __init__(self):
         wx.DropTarget.__init__(self)
         self.data = wx.DataObjectComposite()
         self.text = wx.TextDataObject()
         self.file = wx.FileDataObject()
         self.data.Add(self.text, True)
         self.data.Add(self.file)
         self.SetDataObject(self.data)

     def OnDrop(self, x, y):
         return True

     def OnData(self, x, y, d):
         self.GetData()
         # NOTE: empty text d.o. has length 1 for terminator character...
         if self.text.GetTextLength() > 1:
             text = self.text.GetText()
             self.text.SetText('')
             # Do something with text
         else:
             files = self.file.GetFilenames()
             # Do something with files
         return d

And then set an instance of this as the STC's drop target.

--
Robin Dunn