Chapter 22. Drag-and-drop (DND)
Prev |  | Next

## Chapter 22. Drag-and-drop (DND)

PyGTK has a high level set of functions for doing inter-process communication via the drag-and-drop system. PyGTK can perform drag-and-drop on top of the low level Xdnd and Motif drag-and-drop protocols.

## 22.1. DND Overview

An application capable of drag-and-drop first defines and sets up the widget(s) for drag-and-drop. Each widget can be a source and/or destination for drag-and-drop. Note that these widgets must have an associated X Window.

Source widgets can send out drag data, thus allowing the user to drag things off of them, while destination widgets can receive drag data. Drag-and-drop destinations can limit who they accept drag data from, e.g. the same application or any application (including itself).

Sending and receiving drop data makes use of signals. Dropping an item to a destination widget requires both a data request (for the source widget) and data received signal handler (for the target widget). Additional signal handers can be connected if you want to know when a drag begins (at the very instant it starts), to when a drop is made, and when the entire drag-and-drop procedure has ended (successfully or not).

Your application will need to provide data for source widgets when requested, that involves having a drag data request signal handler. For destination widgets they will need a drop data received signal handler.

So a typical drag-and-drop cycle would look as follows:

- Drag begins. Source can get "drag-begin" signal. Can set up drag icon, etc.

- Drag moves over a drop area. Destination can get "drag-motion" signal.

- Drop occurs. Destination can get "drag-drop" signal. Destination should ask for source data.

- Drag data request (when a drop occurs). Source can get "drag-data-get" signal.

- Drop data received (may be on same or different application). Destination can get "drag-data-received" signal.

- Drag data delete (if the drag was a move). Source can get "drag-data-delete" signal

- Drag-and-drop procedure done. Source can receive "drag-end" signal.

There are a few minor steps that go in between here and there, but we will get into detail about that later.

Prev | Up | Next
21.3. Supplying the Selection | Home | 22.2. DND Properties