Phoenix Logo

phoenix_title wx.DropTarget

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, OnDragOver possibly many times, OnDrop and finally OnData.


class_hierarchy Class Hierarchy

Inheritance diagram for class DropTarget:

method_summary Methods Summary

__init__ Constructor.
GetData This method may only be called from within OnData .
GetDataObject Returns the data wx.DataObject associated with the drop target.
GetDefaultAction Returns default action for drag and drop or DragNone if this not specified.
OnData Called after OnDrop returns True.
OnDragOver Called when the mouse is being dragged over the drop target.
OnDrop Called when the user drops a data object on the target.
OnEnter Called when the mouse enters the drop target.
OnLeave Called when the mouse leaves the drop target.
SetDataObject Sets the data wx.DataObject associated with the drop target and deletes any previously associated data object.
SetDefaultAction Sets the default action for drag and drop.

api Class API



class wx.DropTarget(object)

Possible constructors:

DropTarget(data=None)

This class represents a target for a drag and drop operation.


Methods



__init__(self, data=None)

Constructor.

data is the data to be associated with the drop target.

Parameters:data (wx.DataObject) –


GetData(self)

This method may only be called from within OnData .

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

Return type:bool


GetDataObject(self)

Returns the data wx.DataObject associated with the drop target.

Return type: wx.DataObject


GetDefaultAction(self)

Returns default action for drag and drop or DragNone if this not specified.

Return type: wx.DragResult


OnData(self, x, y, defResult)

Called after OnDrop returns True.

By default this will usually GetData and will return the suggested default value defResult.

Parameters:
  • x (int) –
  • y (int) –
  • defResult (DragResult) –
Return type:

wx.DragResult



OnDragOver(self, x, y, defResult)

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

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

Parameters:
  • x (int) – The x coordinate of the mouse.
  • y (int) – The y coordinate of the mouse.
  • defResult (DragResult) – Suggested value for return value. Determined by SHIFT or CONTROL key states.
Return type:

wx.DragResult

Returns:

The desired operation or DragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon.



OnDrop(self, 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.
Return type:

bool

Returns:

True to accept the data, or False to veto the operation.



OnEnter(self, x, y, defResult)

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.
  • defResult (DragResult) – Suggested default for return value. Determined by SHIFT or CONTROL key states.
Return type:

wx.DragResult

Returns:

The desired operation or DragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon.



OnLeave(self)

Called when the mouse leaves the drop target.



SetDataObject(self, data)

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

Parameters:data (wx.DataObject) –


SetDefaultAction(self, action)

Sets the default action for drag and drop.

Use DragMove or DragCopy to set default action to move or copy and use DragNone (default) to set default action specified by initialization of draging (see wx.DropSource.DoDragDrop )

Parameters:action (DragResult) –

Properties



Data

See GetData



DataObject

See GetDataObject and SetDataObject



DefaultAction

See GetDefaultAction and SetDefaultAction