wx.DropTarget

Inheritance diagram for wx.DropTarget:



Description

This class represents a target for a drag and drop operation. A wx.DataObject can be associated with it and by default, this object will be filled with the data from the drag source, if the data formats supported by the data object match the drag source data format.

There are various virtual handler functions defined in this class which may be overridden to give visual feedback or react in a more fine-tuned way, e.g. by not accepting data on the whole window area, but only a small portion of it. The normal sequence of calls is OnEnter, possibly many times OnDragOver, OnDrop.

The return values of most of the DnD operations, termed wx.DragResult, can be sketched as follows:

Flag Description
wx.DragError Error prevented the d&d operation from completing
wx.DragNone Drag target didn’t accept the data
wx.DragCopy The data was successfully copied
wx.DragMove The data was successfully moved (MSW only)
wx.DragLink Operation is a drag-link
wx.DragCancel The operation was cancelled by user (not an error)

Class API

Methods

__init__(dataObject=None)

Constructor.

Parameters:

  • dataObject (wx.DataObject): the data to associate with the wx.DropTarget.

Returns:

wx.DropTarget


GetData()

By default, this method copies the data from the drop source to the wx.DataObject associated with this drop target, calling its SetDataObject method.


Returns:

bool


OnDrop(x, y)

Called when the user drops a data object on the target.

Return False to veto the operation.

Parameters:

  • x (int): The x coordinate of the mouse.
  • y (int): The y coordinate of the mouse.

Returns:

bool


OnEnter(x, y, default)

Called when the mouse enters the drop target.

By default, this calls OnDragOver.

Parameters:

  • x (int): The x coordinate of the mouse.
  • y (int): The y coordinate of the mouse.
  • default (int): Suggested default for return value. Determined by SHIFT or CONTROL key states.

Returns:

int


OnDragOver(x, y, default)

Called when the mouse is being dragged over the drop target.

By default, this calls functions return the suggested return value default.

Parameters:

  • x (int): The x coordinate of the mouse.
  • y (int): The y coordinate of the mouse.
  • default (int): Suggested default for return value. Determined by SHIFT or CONTROL key states.

Returns:

bool


OnLeave()
Called when the mouse leaves the drop target.

SetDataObject(data)

Sets the data wx.DataObject associated with the drop target and deletes any previously associated data object.

Parameters: