:right-sidebar: True ContentProvider =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: ContentProvider(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` A ``GdkContentProvider`` is used to provide content for the clipboard or for drag-and-drop operations in a number of formats. To create a ``GdkContentProvider``\, use :obj:`~gi.repository.Gdk.ContentProvider.new_for_value` or :obj:`~gi.repository.Gdk.ContentProvider.new_for_bytes`\. GDK knows how to handle common text and image formats out-of-the-box. See :obj:`~gi.repository.Gdk.ContentSerializer` and :obj:`~gi.repository.Gdk.ContentDeserializer` if you want to add support for application-specific data formats. Constructors ------------ .. rst-class:: interim-class .. class:: ContentProvider :no-index: .. classmethod:: new_for_bytes(mime_type: str, bytes: ~gi.repository.GLib.Bytes) -> ~gi.repository.Gdk.ContentProvider Create a content provider that provides the given ``bytes`` as data for the given ``mime_type``\. :param mime_type: the mime type :param bytes: a ``GBytes`` with the data for ``mime_type`` .. classmethod:: new_for_value(value: ~gi.repository.GObject.Value) -> ~gi.repository.Gdk.ContentProvider Create a content provider that provides the given ``value``\. :param value: a ``GValue`` .. classmethod:: new_union(providers: list[~gi.repository.Gdk.ContentProvider] | None = None) -> ~gi.repository.Gdk.ContentProvider Creates a content provider that represents all the given ``providers``\. Whenever data needs to be written, the union provider will try the given ``providers`` in the given order and the first one supporting a format will be chosen to provide it. This allows an easy way to support providing data in different formats. For example, an image may be provided by its file and by the image contents with a call such as .. code-block:: c :dedent: gdk_content_provider_new_union ((GdkContentProvider *[2]) { gdk_content_provider_new_typed (G_TYPE_FILE, file), gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, texture) }, 2); :param providers: The ``GdkContentProvider``\s to present the union of Methods ------- .. rst-class:: interim-class .. class:: ContentProvider :no-index: .. method:: content_changed() -> None Emits the ::content-changed signal. .. method:: do_attach_clipboard(self, clipboard: ~gi.repository.Gdk.Clipboard) -> None :param clipboard: .. method:: do_content_changed(self) -> None .. method:: do_detach_clipboard(self, clipboard: ~gi.repository.Gdk.Clipboard) -> None :param clipboard: .. method:: do_get_value(self) -> ~typing.Tuple[bool, ~gi.repository.GObject.Value] .. method:: do_write_mime_type_async(self, mime_type: str, stream: ~gi.repository.Gio.OutputStream, 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 :param mime_type: :param stream: :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_write_mime_type_finish(self, result: ~gi.repository.Gio.AsyncResult) -> bool :param result: .. method:: get_value() -> ~typing.Tuple[bool, ~gi.repository.GObject.Value] Gets the contents of ``provider`` stored in ``value``\. The ``value`` will have been initialized to the ``GType`` the value should be provided in. This given ``GType`` does not need to be listed in the formats returned by :obj:`~gi.repository.Gdk.ContentProvider.ref_formats`\. However, if the given ``GType`` is not supported, this operation can fail and ``G_IO_ERROR_NOT_SUPPORTED`` will be reported. .. method:: write_mime_type_async(mime_type: str, stream: ~gi.repository.Gio.OutputStream, 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 writes the contents of ``provider`` to ``stream`` in the given ``mime_type``\. The given mime type does not need to be listed in the formats returned by :obj:`~gi.repository.Gdk.ContentProvider.ref_formats`\. However, if the given ``GType`` is not supported, ``G_IO_ERROR_NOT_SUPPORTED`` will be reported. The given ``stream`` will not be closed. :param mime_type: the mime type to provide the data in :param stream: the ``GOutputStream`` to write to :param io_priority: I/O priority of the request. :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:: write_mime_type_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes an asynchronous write operation. See :obj:`~gi.repository.Gdk.ContentProvider.write_mime_type_async`\. :param result: a ``GAsyncResult`` Properties ---------- .. rst-class:: interim-class .. class:: ContentProvider :no-index: .. attribute:: props.formats :type: ~gi.repository.Gdk.ContentFormats The type of the None singleton. .. attribute:: props.storable_formats :type: ~gi.repository.Gdk.ContentFormats The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: ContentProvider.signals :no-index: .. method:: content_changed() -> None The type of the None singleton. Virtual Methods --------------- .. rst-class:: interim-class .. class:: ContentProvider :no-index: .. method:: do_attach_clipboard(clipboard: ~gi.repository.Gdk.Clipboard) -> None The type of the None singleton. :param clipboard: .. method:: do_content_changed() -> None Emits the ::content-changed signal. .. method:: do_detach_clipboard(clipboard: ~gi.repository.Gdk.Clipboard) -> None The type of the None singleton. :param clipboard: .. method:: do_get_value() -> ~typing.Tuple[bool, ~gi.repository.GObject.Value] Gets the contents of ``provider`` stored in ``value``\. The ``value`` will have been initialized to the ``GType`` the value should be provided in. This given ``GType`` does not need to be listed in the formats returned by :obj:`~gi.repository.Gdk.ContentProvider.ref_formats`\. However, if the given ``GType`` is not supported, this operation can fail and ``G_IO_ERROR_NOT_SUPPORTED`` will be reported. .. method:: do_ref_formats() -> ~gi.repository.Gdk.ContentFormats Gets the formats that the provider can provide its current contents in. .. method:: do_ref_storable_formats() -> ~gi.repository.Gdk.ContentFormats Gets the formats that the provider suggests other applications to store the data in. An example of such an application would be a clipboard manager. This can be assumed to be a subset of :obj:`~gi.repository.Gdk.ContentProvider.ref_formats`\. .. method:: do_write_mime_type_async(mime_type: str, stream: ~gi.repository.Gio.OutputStream, 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 writes the contents of ``provider`` to ``stream`` in the given ``mime_type``\. The given mime type does not need to be listed in the formats returned by :obj:`~gi.repository.Gdk.ContentProvider.ref_formats`\. However, if the given ``GType`` is not supported, ``G_IO_ERROR_NOT_SUPPORTED`` will be reported. The given ``stream`` will not be closed. :param mime_type: the mime type to provide the data in :param stream: the ``GOutputStream`` to write to :param io_priority: I/O priority of the request. :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:: do_write_mime_type_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes an asynchronous write operation. See :obj:`~gi.repository.Gdk.ContentProvider.write_mime_type_async`\. :param result: a ``GAsyncResult`` Fields ------ .. rst-class:: interim-class .. class:: ContentProvider :no-index: .. attribute:: parent