:right-sidebar: True Clipboard =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: Clipboard(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` The ``GdkClipboard`` object represents data shared between applications or inside an application. To get a ``GdkClipboard`` object, use :obj:`~gi.repository.Gdk.Display.get_clipboard` or :obj:`~gi.repository.Gdk.Display.get_primary_clipboard`\. You can find out about the data that is currently available in a clipboard using :obj:`~gi.repository.Gdk.Clipboard.get_formats`\. To make text or image data available in a clipboard, use :obj:`~gi.repository.Gdk.Clipboard.set_text` or :obj:`~gi.repository.Gdk.Clipboard.set_texture`\. For other data, you can use :obj:`~gi.repository.Gdk.Clipboard.set_content`\, which takes a :obj:`~gi.repository.Gdk.ContentProvider` object. To read textual or image data from a clipboard, use :obj:`~gi.repository.Gdk.Clipboard.read_text_async` or :obj:`~gi.repository.Gdk.Clipboard.read_texture_async`\. For other data, use :obj:`~gi.repository.Gdk.Clipboard.read_async`\, which provides a ``GInputStream`` object. Methods ------- .. rst-class:: interim-class .. class:: Clipboard :no-index: .. method:: get_content() -> ~gi.repository.Gdk.ContentProvider | None Returns the ``GdkContentProvider`` currently set on ``clipboard``\. If the ``clipboard`` is empty or its contents are not owned by the current process, :const:`None` will be returned. .. method:: get_display() -> ~gi.repository.Gdk.Display Gets the ``GdkDisplay`` that the clipboard was created for. .. method:: get_formats() -> ~gi.repository.Gdk.ContentFormats Gets the formats that the clipboard can provide its current contents in. .. method:: is_local() -> bool Returns if the clipboard is local. A clipboard is considered local if it was last claimed by the running application. Note that :obj:`~gi.repository.Gdk.Clipboard.get_content` may return :const:`None` even on a local clipboard. In this case the clipboard is empty. .. method:: read_async(mime_types: list[str], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously requests an input stream to read the ``clipboard``\'s contents from. The clipboard will choose the most suitable mime type from the given list to fulfill the request, preferring the ones listed first. :param mime_types: a :const:`None`-terminated array of mime types to choose from :param io_priority: the I/O priority of the request :param cancellable: optional ``GCancellable`` object :param callback: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[~gi.repository.Gio.InputStream | None, str] Finishes an asynchronous clipboard read. See :obj:`~gi.repository.Gdk.Clipboard.read_async`\. :param result: a ``GAsyncResult`` .. method:: read_text_async(cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously request the ``clipboard`` contents converted to a string. This is a simple wrapper around :obj:`~gi.repository.Gdk.Clipboard.read_value_async`\. Use that function or :obj:`~gi.repository.Gdk.Clipboard.read_async` directly if you need more control over the operation. :param cancellable: optional ``GCancellable`` object :param callback: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_text_finish(result: ~gi.repository.Gio.AsyncResult) -> str | None Finishes an asynchronous clipboard read. See :obj:`~gi.repository.Gdk.Clipboard.read_text_async`\. :param result: a ``GAsyncResult`` .. method:: read_texture_async(cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously request the ``clipboard`` contents converted to a ``GdkPixbuf``\. This is a simple wrapper around :obj:`~gi.repository.Gdk.Clipboard.read_value_async`\. Use that function or :obj:`~gi.repository.Gdk.Clipboard.read_async` directly if you need more control over the operation. :param cancellable: optional ``GCancellable`` object, :const:`None` to ignore. :param callback: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_texture_finish(result: ~gi.repository.Gio.AsyncResult) -> ~gi.repository.Gdk.Texture | None Finishes an asynchronous clipboard read. See :obj:`~gi.repository.Gdk.Clipboard.read_texture_async`\. :param result: a ``GAsyncResult`` .. method:: read_value_async(type: ~gobject.GType, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously request the ``clipboard`` contents converted to the given ``type``\. For local clipboard contents that are available in the given ``GType``\, the value will be copied directly. Otherwise, GDK will try to use :obj:`~gi.repository.Gdk.content_deserialize_async` to convert the clipboard's data. :param type: a ``GType`` to read :param io_priority: the I/O priority of the request :param cancellable: optional ``GCancellable`` object :param callback: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: read_value_finish(result: ~gi.repository.Gio.AsyncResult) -> ~gi.repository.GObject.Value Finishes an asynchronous clipboard read. See :obj:`~gi.repository.Gdk.Clipboard.read_value_async`\. :param result: a ``GAsyncResult`` .. method:: set(value: ~gi.repository.GObject.Value) -> None Sets the clipboard to contain the value collected from the given varargs. Values should be passed the same way they are passed to other value collecting APIs, such as :obj:`~gi.repository.GObject.Object.set` or :obj:`~gi.repository.GObject.signal_emit`\. .. code-block:: c :dedent: gdk_clipboard_set (clipboard, GTK_TYPE_STRING, "Hello World"); gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture); :param value: .. method:: set_content(provider: ~gi.repository.Gdk.ContentProvider | None = None) -> bool Sets a new content provider on ``clipboard``\. The clipboard will claim the ``GdkDisplay``\'s resources and advertise these new contents to other applications. In the rare case of a failure, this function will return :const:`False`. The clipboard will then continue reporting its old contents and ignore ``provider``\. If the contents are read by either an external application or the ``clipboard``\'s read functions, ``clipboard`` will select the best format to transfer the contents and then request that format from ``provider``\. :param provider: the new contents of ``clipboard`` or :const:`None` to clear the clipboard .. method:: store_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously instructs the ``clipboard`` to store its contents remotely. If the clipboard is not local, this function does nothing but report success. The purpose of this call is to preserve clipboard contents beyond the lifetime of an application, so this function is typically called on exit. Depending on the platform, the functionality may not be available unless a "clipboard manager" is running. This function is called automatically when a `GtkApplication <../gtk4/class.Application.html>`__ is shut down, so you likely don't need to call it. :param io_priority: the I/O priority of the request :param cancellable: optional ``GCancellable`` object :param callback: callback to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: store_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes an asynchronous clipboard store. See :obj:`~gi.repository.Gdk.Clipboard.store_async`\. :param result: a ``GAsyncResult`` Properties ---------- .. rst-class:: interim-class .. class:: Clipboard :no-index: .. attribute:: props.content :type: ~gi.repository.Gdk.ContentProvider The type of the None singleton. .. attribute:: props.display :type: ~gi.repository.Gdk.Display The type of the None singleton. .. attribute:: props.formats :type: ~gi.repository.Gdk.ContentFormats The type of the None singleton. .. attribute:: props.local :type: bool The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: Clipboard.signals :no-index: .. method:: changed() -> None The type of the None singleton.