Table Of Contents

Previous topic

DropSource

Next topic

DuplexMode

This Page

phoenix_title DropTarget

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

A 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 Inheritance Diagram

Inheritance diagram for class DropTarget

Inheritance diagram of DropTarget


method_summary Methods Summary

__init__ Constructor.
GetData This method may only be called from within OnData .
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 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 DropTarget(object)

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

Possible constructors:

DropTarget(data=None)

Methods



__init__(self, data=None)

Constructor.

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

Parameters:data (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 DataObject associated with this drop target, calling its DataObject.SetData method.

Return type:bool


GetDefaultAction(self)

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

Return type: 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:

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:

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:

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 DataObject associated with the drop target and deletes any previously associated data object.

Parameters:data (DataObject) –


SetDefaultAction(self, action)

Sets the default action for drag and drop.

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

Parameters:action (DragResult) –

Properties



Data

See GetData



DefaultAction

See GetDefaultAction and SetDefaultAction