Chapter 21. Drag-and-drop (DND)

Table of Contents
21.1. Overview
21.2. Properties
21.3. Functions
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.

21.1. 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.

    Drag data request (when a drop occurs).

    Drop data received (may be on same or different application).

    Drag data delete (if the drag was a move).

    Drag-and-drop procedure done.

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