views:

54

answers:

1

I'm trying to implement drag and drop on a wx.TreeCtrl and I need to handle both "copy" and "move" operations (if the user keeps CTRL pressed).
First of all, I searched the wiki for an example and I'm confused as to which method to use.. Should I use DropSource/DropTarget or just handle EVT_TREE_BEGIN_DRAG and EVT_TREE_END_DRAG?
If the latter, how can I tell if the user is requesting a "move" operation?

(wxPython 2.8.9.1 on Ubuntu Jaunty)

A: 

Reading the relevant paragraph from Cross-Platform GUI Programming with wxWidgets gave me the necessary insight to solve the issue :)
In the end I went for the first solution (DropSource/DropTarget), so:

tree.SetDropTarget(MyDropTarget())
tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag)
tree.GetMainWindow().Bind(wx.EVT_MOUSE_CAPTURE_LOST, lambda x: None)

(The second bind avoids a mysterious "window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST" on dragging)

def on_drag(self, evt):
   # No evt.Allow() here, I won't use TreeCtrl's internal DND support
   item = evt.GetItem()
   if item == self.tree.GetRootItem():
      return
   dropsrc = wx.DropSource(self)
   # Populate dropsource
   # ...
   dropsrc.DoDragDrop(wx.Drag_AllowMove)
Joril