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
.
See also
Drag and Drop Overview, DataObject Overview, wx.DropSource, wx.TextDropTarget, wx.FileDropTarget, wx.DataFormat, wx.DataObject
wx.FileDropTarget, wx.TextDropTarget
Constructor. |
|
This method may only be called from within |
|
Returns the data wx.DataObject associated with the drop target. |
|
Returns default action for drag and drop or DragNone if this not specified. |
|
Called after |
|
Called when the mouse is being dragged over the drop target. |
|
Called when the user drops a data object on the target. |
|
Called when the mouse enters the drop target. |
|
Called when the mouse leaves the drop target. |
|
Sets the data wx.DataObject associated with the drop target and deletes any previously associated data object. |
|
Sets the default action for drag and drop. |
See |
|
See |
|
See |
wx.
DropTarget
(object)¶Possible constructors:
DropTarget(data=None)
This class represents a target for a drag and drop operation.
__init__
(self, data=None)¶Constructor.
data is the data to be associated with the drop target.
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.
bool
GetDataObject
(self)¶Returns the data wx.DataObject associated with the drop target.
GetDefaultAction
(self)¶Returns default action for drag and drop or DragNone if this not specified.
OnData
(self, x, y, defResult)¶Called after OnDrop
returns True
.
By default this will usually GetData
and will return the suggested default value defResult.
x (int) –
y (int) –
defResult (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.
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.
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.
x (int) – The x coordinate of the mouse.
y (int) – The y coordinate of the mouse.
bool
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
.
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.
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.
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 dragging (see wx.DropSource.DoDragDrop
)
action (DragResult) –
DataObject
¶See GetDataObject
and SetDataObject
DefaultAction
¶See GetDefaultAction
and SetDefaultAction