:right-sidebar: True Clipboard =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: Clipboard(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` :Constructors: :: Clipboard(**properties) 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: ~typing.Sequence[str], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously requests an input stream to read the ``clipboard``'s contents from. When the operation is finished ``callback`` will be called. You must then call :obj:`~gi.repository.Gdk.Clipboard.read_finish` to get the result of the operation. 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) -> 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[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously request the ``clipboard`` contents converted to a string. When the operation is finished ``callback`` will be called. You must then call :obj:`~gi.repository.Gdk.Clipboard.read_text_finish` to get the result. 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[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously request the ``clipboard`` contents converted to a ``GdkPixbuf``. When the operation is finished ``callback`` will be called. You must then call :obj:`~gi.repository.Gdk.Clipboard.read_texture_finish` to get the result. 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: type, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously request the ``clipboard`` contents converted to the given ``type``. When the operation is finished ``callback`` will be called. You must then call :obj:`~gi.repository.Gdk.Clipboard.read_value_finish` to get the resulting ``GValue``. 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) -> ~typing.Any Finishes an asynchronous clipboard read. See :obj:`~gi.repository.Gdk.Clipboard.read_value_async`. :param result: a ``GAsyncResult`` .. method:: set(value: ~typing.Any) -> 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[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously instructs the ``clipboard`` to store its contents remotely. If the clipboard is not local, this function does nothing but report success. The ``callback`` must call :obj:`~gi.repository.Gdk.Clipboard.store_finish`. 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 ``GdkContentProvider`` or :const:`None` if the clipboard is empty or contents are provided otherwise. .. attribute:: props.display :type: ~gi.repository.Gdk.Display The ``GdkDisplay`` that the clipboard belongs to. .. attribute:: props.formats :type: ~gi.repository.Gdk.ContentFormats The possible formats that the clipboard can provide its data in. .. attribute:: props.local :type: bool :const:`True` if the contents of the clipboard are owned by this process. Signals ------- .. rst-class:: interim-class .. class:: Clipboard.signals :no-index: .. method:: changed() -> None Emitted when the clipboard changes ownership.