wx.TreeCtrl拖放,复制和移动 [英] wx.TreeCtrl drag and drop, copy and move

查看:371
本文介绍了wx.TreeCtrl拖放,复制和移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在wx.TreeCtrl上实现拖放,我需要处理
复制和移动操作(如果用户按住CTRL按钮)。

首先,我搜索了维基一个例子,我被困惑为
要使用的方法..我应该使用DropSource / DropTarget还是只需
句柄EVT_TREE_BEGIN_DRAG和EVT_TREE_END_DRAG?

如果是后者,我该如何判断用户是否要求移动
操作?

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在Ubuntu Jaunty上)

(wxPython 2.8.9.1 on Ubuntu Jaunty)

推荐答案

使用wxWidgets进行跨平台GUI编程阅读相关段落,为我提供了解决问题的必要洞察力问题:)

最后我去了第一个解决方案(DropSource / DropTarget),所以:

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)

(第二个绑定避免了一个神秘的捕获鼠标的窗口拖动时没有处理wxEVT_MOUSE_CAPTURE_LOST)

(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)

这篇关于wx.TreeCtrl拖放,复制和移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆