Hi Giovanni,
you may consider these snippets of code as a starting point:
import wx
import cPickle
class DragInfo:
def __init__(self, data):
""" Default class constructor. """
self._data = data
def GetPlotData(self):
""" Returns the data to plot in the MatPlotLib canvas. """
return self._data
<snip> subclassing of CustomTreeCtrl and initialization (self is a
CustomTreeCtrl):
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag)
def OnBeginDrag(self, event):
item = event.GetItem()
if not item:
event.Skip()
return
data = self.GetDataFromItem(item)
if not data:
event.Skip()
return
event.Allow()
draginfo = cPickle.dumps(DragInfo(data))
dataobject = wx.CustomDataObject(wx.CustomDataFormat("SymphonyPlot"))
dataobject.SetData(draginfo)
dragSource = wx.DropSource(self)
dragSource.SetData(dataobject)
dragSource.DoDragDrop(wx.Drag_DefaultMove)
event.Skip()
In your other class, your droptarget, you could do something like:
class DropTarget(wx.DropTarget):
def __init__(self, parent):
""" Default class constructor. """
wx.DropTarget.__init__(self)
self._parent = parent
self._dataobject =
wx.CustomDataObject(wx.CustomDataFormat("SymphonyPlot"))
self.SetDataObject(self._dataobject)
def OnData(self, x, y, dragres):
""" Handles the OnData() method to call the real DnD routine. """
if not self.GetData():
return wx.DragNone
draginfo = self._dataobject.GetData()
drginfo = cPickle.loads(draginfo)
if not drginfo.GetPlotData():
return wx.DragNone
return self._parent.OnDropTarget(x, y, drginfo.GetPlotData())
Above, "_parent" is your drop target (that may be a panel, a button,
whatever you want). At last, you have in your "_parent" class a method
like:
def OnDropTarget(self, x, y, data):
""" Handles the drop action from a DND operation. """
if not data:
return wx.DragCancel
# do whatever you want with your data
return wx.DragMove
Hope this helps. Sorry if I could not put a complete example here, but
it's bed-time for me
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/