Skip to content

Gdk.ContentProvider

class — extends GObject.Object

Provides content for the clipboard or for drag-and-drop operations in a number of formats.

To create a GdkContentProvider, use ContentProvider.new_for_value or ContentProvider.new_for_bytes.

GDK knows how to handle common text and image formats out-of-the-box. See ContentSerializer and ContentDeserializer if you want to add support for application-specific data formats.

Constructors

new_for_bytes

@classmethod
def new_for_bytes(cls, mime_type: str, bytes: bytes) -> ContentProvider

Create a content provider that provides the given bytes as data for the given mime_type.

Parameters:

  • mime_type — the mime type
  • bytes — a GBytes with the data for mime_type

new_for_value

@classmethod
def new_for_value(cls, value: GObject.Value) -> ContentProvider

Create a content provider that provides the given value.

Parameters:

  • value — a GValue

new_union

@classmethod
def new_union(cls, providers: list[ContentProvider] | None = ...) -> 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

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);

Parameters:

  • providers — The GdkContentProviders to present the union of

Methods

content_changed

def content_changed(self) -> None

Emits the ::content-changed signal.

get_value

def get_value(self) -> tuple[bool, 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 ContentProvider.ref_formats. However, if the given GType is not supported, this operation can fail and G_IO_ERROR_NOT_SUPPORTED will be reported.

ref_formats

def ref_formats(self) -> ContentFormats

Gets the formats that the provider can provide its current contents in.

ref_storable_formats

def ref_storable_formats(self) -> 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 ContentProvider.ref_formats.

write_mime_type_async

def write_mime_type_async(self, mime_type: str, stream: Gio.OutputStream, io_priority: int, cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | 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 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.

Parameters:

  • mime_type — the mime type to provide the data in
  • stream — the GOutputStream to write to
  • io_priority — I/O priority of the request.
  • cancellable — optional GCancellable object, None to ignore.
  • callback — callback to call when the request is satisfied

write_mime_type_finish

def write_mime_type_finish(self, result: Gio.AsyncResult) -> bool

Finishes an asynchronous write operation.

See ContentProvider.write_mime_type_async.

Parameters:

  • result — a GAsyncResult

Virtual methods

do_attach_clipboard

def do_attach_clipboard(self, clipboard: Clipboard) -> None

do_content_changed

def do_content_changed(self) -> None

Emits the ::content-changed signal.

do_detach_clipboard

def do_detach_clipboard(self, clipboard: Clipboard) -> None

do_get_value

def do_get_value(self) -> tuple[bool, 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 ContentProvider.ref_formats. However, if the given GType is not supported, this operation can fail and G_IO_ERROR_NOT_SUPPORTED will be reported.

do_ref_formats

def do_ref_formats(self) -> ContentFormats

Gets the formats that the provider can provide its current contents in.

do_ref_storable_formats

def do_ref_storable_formats(self) -> 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 ContentProvider.ref_formats.

do_write_mime_type_async

def do_write_mime_type_async(self, mime_type: str, stream: Gio.OutputStream, io_priority: int, cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | 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 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.

Parameters:

  • mime_type — the mime type to provide the data in
  • stream — the GOutputStream to write to
  • io_priority — I/O priority of the request.
  • cancellable — optional GCancellable object, None to ignore.
  • callback — callback to call when the request is satisfied

do_write_mime_type_finish

def do_write_mime_type_finish(self, result: Gio.AsyncResult) -> bool

Finishes an asynchronous write operation.

See ContentProvider.write_mime_type_async.

Parameters:

  • result — a GAsyncResult

Properties

formats

formats: ContentFormats  # read-only

The possible formats that the provider can provide its data in.

storable_formats

storable_formats: ContentFormats  # read-only

The subset of formats that clipboard managers should store this provider's data in.

Signals

content-changed

def on_content_changed(self) -> None: ...

Emitted whenever the content provided by this provider has changed.