[wxPython-users] how to use wx.DragTreeItem?

Robin Dunn robin at alldunn.com
Fri Feb 15 15:52:51 PST 2008


Danny Shevitz wrote:
> howdy,
> 
> I have found wx.DragTreeItem to be almost completely undocumented. 

DragTreeItem is simply a convenience factory that fetches the text of 
the item from the tree and makes a bitmap out of it to pass to the main 
wx.DragImage constructor.


> 
> I'm trying to implement DnD on a wx.TreeCtrl and I want the drag icon to be a
> visual representation of the tree item.  I believe this is what wx.DragTreeItem
> is for. I have found the following snippet of code on this list a few years back:
> 
> class FolderTree(wx.TreeCtrl):
> [snip]
> 	wx.EVT_TREE_BEGIN_DRAG(self, ID_TREE, self.OnBeginDrag)
> [snip]
> 	def OnBeginDrag(self, event):
>         	self.dragging_item = event.GetItem()
> 		self.drag_image = wx.DragTreeItem(self, self.dragging_item)
> 
> In fact I am trying to hack TraitsUI using the wx backend so that the cursor is
> more useful than the standard block cursor.
> 
> I tried implementing this in their TreeEditor and it didn't seem to work. 
> Can someone be kind enough to write a few sentences and explain how this
> drag image hook is supposed to work?


Take a look at the DragImage sample in the demo.  Basically a 
wx.DragImage object just makes it a little easier to draw a transient 
image somewhere either within the bounds of some window, or on the whole 
screen, and update (move) it in response to some other events, like 
mouse motion.  So the key point for using it for something like drag and 
drop is to create the obj like above, and then call its methods from 
some appropriate event handler or callback to move it to follow the 
mouse cursor.  For the wx.TreeCtrl's internal DnD you can do it from the 
tree's EVT_MOTION event.  For normal DnD then you can do it from the 
DropSource's GiveFeedback method.



-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list