閱讀從Cross-Platform GUI Programming with wxWidgets相關段落給了我必要的洞察力,以解決這一問題:)
在我去的第一個解決方案結束(DropSource/DropTarget的) ,所以:
tree.SetDropTarget(MyDropTarget())
tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag)
tree.GetMainWindow().Bind(wx.EVT_MOUSE_CAPTURE_LOST, lambda x: None)
(第二綁定避免了拖動神祕「捕獲該鼠標沒有處理wxEVT_MOUSE_CAPTURE_LOST窗口」)
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)