In most cases, it isn't necessary for a PyGTK application to deal with selections itself. The standard widgets, such as the Entry widget, already have the capability to claim the selection when appropriate (e.g., when the user drags over text), and to retrieve the contents of the selection owned by another widget or another application (e.g., when the user clicks the second mouse button). However, there may be cases in which you want to give other widgets the ability to supply the selection, or you wish to retrieve targets not supported by default.
A fundamental concept needed to understand
selection handling is that of the atom. An atom is an integer that
uniquely identifies a string (on a certain display). Certain atoms are
predefined by the X server, GTK and PyGTK (in GDK.py):
SELECTION_TYPE_ATOM SELECTION_TYPE_BITMAP SELECTION_TYPE_COLORMAP SELECTION_TYPE_DRAWABLE SELECTION_TYPE_INTEGER SELECTION_TYPE_PIXMAP SELECTION_TYPE_WINDOW SELECTION_TYPE_STRING
You should use the functions atom_intern(), to get the atom corresponding to a string, and atom_name(), to get the name of an atom. Both selections and targets are identified by atoms.