Being the source of a drag and drop

Drag and drop is functionally similar to cut and paste. In both cases, you are transferring data between various parts of your own application or between two different applications. Since the problem of managing data and formats is nearly identical, wxPython uses the same wx.DataObject hierarchy to ensure that formats are handled properly.

The biggest difference between drag and drop and cut and paste is that cut and paste relies on the existence of the centralized clipboard. Since the clipboard manages the data, the source application is done with the operation as soon as it passes it along—the source doesn't care what happens after that. Not so with a drag and drop. Not only does the source application need to create a drag manager object to serve the purpose of the clipboard, but it must also wait for the target application to respond. Unlike a clipboard operation, in drag and drop it is the target application that gets to decide whether the operation is a cut or a copy, so the source must wait to find out what it is expected to do with the transferred data.

Typically, you will start your drag source operation from inside an event handler, often a mouse down event, since the drag generally happens with the mouse down. Creating a drag source requires four steps:

1 Create data object

2 Create wx.DropSource instance

3 Execute drag operation

4 Cancel or accept drop

Was this article helpful?

0 0

Post a comment