[wxPython] wxPyDropTarget

I am trying to get drag and drop to work. The demo program shows

how to use crtl-drag to do a copy operation, and that works for me.

I want to drag and drop without the control key, but I can’t get any

response (the target shows a (/) symbol, when dragged over).

Here’s my code running on wxPython 2.3.1, Python 2.1.1, Windows:

class NiMapDropTarget(wx.wxPyDropTarget):
def init(self, w):
wx.wxPyDropTarget.init(self)
self.w = w
self.data = wx.wxCustomDataObject(wx.wxCustomDataFormat(“NiObject”))
self.SetDataObject(self.data)

def OnEnter(self, x,y, d):
    print 'OnEnter'    # . . . (gets called, but disallows drop unless Ctrl is pressed)
    return wx.wxDragMove   # Also tried wx.wxDragCopy with same result

def OnData(self, x, y, d):

    print 'OnData'    # . . . (doesn't get not called unless Ctrl is pressed)

I’d like to show “copy” semantics (i.e. show the + symbol), but not require the

Ctrl key, since copy (and not move) is the only reasonable operation in this case.

However, I have not been able to get a drop to happen at all without Ctrl being

pressed.

  • Ken
···

I am trying to get drag and drop to work. The demo program shows

how to use crtl-drag to do a copy operation, and that works for me.

I want to drag and drop without the control key, but I can’t get any

response (the target shows a (/) symbol, when dragged over).

I can’t seem to get “move” semantics (i.e. drag without control)

to work at all.

Here’s my code running on wxPython 2.3.1, Python 2.1.1, Windows:

class NiMapDropTarget(wx.wxPyDropTarget):
def init(self, w):
wx.wxPyDropTarget.init(self)
self.w = w
self.data = wx.wxCustomDataObject(wx.wxCustomDataFormat(“NiObject”))
self.SetDataObject(self.data)

def OnEnter(self, x,y, d):
    print 'OnEnter'    # . . . (gets called, but disallows drop unless Ctrl is pressed)
    return wx.wxDragMove   # Also tried wx.wxDragCopy with same result

def OnData(self, x, y, d):

    print 'OnData'    # . . . (doesn't get not called unless Ctrl is pressed)

I’d like to show “copy” semantics (i.e. show the + symbol), but not require the

Ctrl key, since copy (and not move) is the only reasonable operation in my case.

However, I have not been able to get a drop to happen at all without Ctrl being

pressed.

  • Ken
···

[No html mail please...]

In the demo the Control is just used as a flag to start the drag since a
bare mouse drag is already used for the drawing. Once the drag opeation has
started then the control key is used to signal the type of drag operation it
is. I suppose I should change the demo so this isn't so confusing.

The reason you only copy-drags are allowed is that is what the droup source
specifies. See the docs for wxDropSource::DoDragDrop. If you pass a true
instead of letting it default to false tells the drop target that the drop
source will respond to a move by deleting the dragged object when it is done
being copied. I'll change the demo to show this too.

···

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

The reason you only copy-drags are allowed is that is what the droup

source

specifies. See the docs for wxDropSource::DoDragDrop. If you pass a true
instead of letting it default to false tells the drop target that the drop
source will respond to a move by deleting the dragged object when it is

done

being copied. I'll change the demo to show this too.

You can see it at:

http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/demo/CustomDragAndDrop
.py?rev=1.4&content-type=text/vnd.viewcvs-markup

···

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