| 1 |
.. currentmodule:: gi.repository |
| 2 |
|
| 3 |
Clipboard |
| 4 |
========= |
| 5 |
|
| 6 |
:class:`Gdk.Clipboard` provides a storage area for a variety of data, including |
| 7 |
text and images. Using a clipboard allows this data to be shared between |
| 8 |
applications through actions such as copying, cutting, and pasting. |
| 9 |
|
| 10 |
There are multiple clipboard selections for different purposes. |
| 11 |
In most circumstances, the selection named ``CLIPBOARD`` is used for everyday |
| 12 |
copying and pasting. ``PRIMARY`` is another common selection which stores text |
| 13 |
selected by the user with the cursor. |
| 14 |
|
| 15 |
:class:`Gdk.Display` will allow us to access these different clipboards. |
| 16 |
You can get the default display with :meth:`Gdk.Display.get_default`, then get |
| 17 |
the clipboard that you want; :meth:`Gdk.Display.get_clipboard` for ``CLIPBOARD`` |
| 18 |
and :meth:`Gdk.Display.get_primary_clipboard` for ``PRIMARY``. |
| 19 |
|
| 20 |
You can set any simple value like text with :meth:`Gdk.Clipboard.set`. |
| 21 |
For more complex data you must use the :meth:`Gdk.Clipboard.set_content` method |
| 22 |
were you have to pass a :class:`Gdk.ContentProvider`. |
| 23 |
A content provider is usually created using |
| 24 |
:meth:`Gdk.ContentProvider.new_for_value` where you only pass the value. |
| 25 |
|
| 26 |
To read the clipboard values :class:`Gdk.Clipboard` provides three async methods. |
| 27 |
For textual or image data use :meth:`Gdk.Clipboard.read_text_async` or |
| 28 |
:meth:`Gdk.Clipboard.read_texture_async`. |
| 29 |
For other data use :meth:`Gdk.Clipboard.read_value_async`. |
| 30 |
|
| 31 |
|
| 32 |
Example |
| 33 |
------- |
| 34 |
|
| 35 |
.. image:: images/clipboard.png |
| 36 |
|
| 37 |
.. literalinclude:: examples/clipboard.py |
| 38 |
:linenos: |