[wxPython-users] Re: how to use wx.DragTreeItem?
Robin Dunn
robin at alldunn.com
Mon Feb 18 15:34:04 PST 2008
Danny Shevitz wrote:
>>> In fact I am trying to hack TraitsUI using the wx backend so that the c
> ursor 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.
>
>
> The actual architecture is the tree has a DropTarget. In EVT_TREE_BEGIN_DRAG
> Traits creates a DropSource with a custom data format. The arguments to
> DropSource can take wx.Cursor's, but I don't know how to create a cursor from
> the tree item (including the icon).
Create a bitmap, select it into a wx.MemoryDC, draw the text and
whatever else you want into this dc, convert the bitmap to a wx.Image,
use wx.CursorFromImage to get a cursor.
> You are suggesting a second method which
> is to override the DropSource's GiveFeedback method probably using a DragImage.
>
> What do you recommend as the best way to proceed?
The GiveFeedback method would probably be better since it won't have the
same platform limitations as the cursor. Basically you just override
GiveFeedback in your derived wx.DropSource class, and when it is called
you can use wx.GetMousePosition to get the current screen location of
the mouse cursor, and then if you are using a wx.DragImage just Move()
it to that spot.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list