Hi,
I'd like to have a DropTarget for text which is dragged from e.g. a console
window (linux/wxGTK KDE). In the following script I subclassed PyDropTarget and
used a CustomDataObject just in case the text is not transfered as pure text (is
it?). As expected the OnXXX methods of the drop target are being called when
dragging/dropping anything on the target but OnData is never called. So I can
say that and where something has been dropped but I can't access the data. What
am I doing wrong?
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1)
self.panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.btn = wx.Button(self.panel, -1, "drop here")
sizer.Add(self.btn, 1, wx.EXPAND)
self.panel.SetAutoLayout(True)
self.panel.SetSizer(sizer)
dt = DropTarget(self.btn)
self.btn.SetDropTarget(dt)
class DropTarget(wx.PyDropTarget):
def __init__(self, window):
wx.PyDropTarget.__init__(self)
#self.do = wx.TextDataObject()
self.do = wx.CustomDataObject('custom')
self.SetDataObject(self.do)
def OnEnter(self, x, y, d):
print 'on enter'
return d
def OnDragOver(self, x, y, d):
print 'on drag over'
return d
def OnLeave(self):
pass
def OnDrop(self, x, y):
print 'on drop'
return True
def OnData(self, x, y, d):
print 'on data'
self.GetData()
print self.do.GetData()
return d
class App(wx.App):
def OnInit(self):
self.frame = Frame(None)
self.frame.Show(True)
return True
app = App()
app.MainLoop()
Regards, Christian