Gdk.ContentProvider

g GObject.Object GObject.Object Gdk.ContentProvider Gdk.ContentProvider GObject.Object->Gdk.ContentProvider

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new_for_bytes (mime_type, bytes)

class

new_for_value (value)

class

new_union (providers)

content_changed ()

get_value ()

ref_formats ()

ref_storable_formats ()

write_mime_type_async (mime_type, stream, io_priority, cancellable, callback, *user_data)

write_mime_type_finish (result)

Virtual Methods

Inherited:

GObject.Object (7)

do_attach_clipboard (clipboard)

do_content_changed ()

do_detach_clipboard (clipboard)

do_get_value ()

do_ref_formats ()

do_ref_storable_formats ()

do_write_mime_type_async (mime_type, stream, io_priority, cancellable, callback, *user_data)

do_write_mime_type_finish (result)

Properties

Name

Type

Flags

Short Description

formats

Gdk.ContentFormats

r/en

storable-formats

Gdk.ContentFormats

r/en

Signals

Inherited:

GObject.Object (1)

Name

Short Description

content-changed

Emitted whenever the content provided by this provider has changed.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent

GObject.Object

r

Class Details

class Gdk.ContentProvider(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gdk.ContentProviderClass

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 [ctor`Gdk`.ContentProvider.new_for_value] or [ctor`Gdk`.ContentProvider.new_for_bytes].

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

classmethod new_for_bytes(mime_type, bytes)[source]
Parameters:
  • mime_type (str) – the mime type

  • bytes (GLib.Bytes) – a GBytes with the data for mime_type

Returns:

a new GdkContentProvider

Return type:

Gdk.ContentProvider

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

classmethod new_for_value(value)[source]
Parameters:

value (GObject.Value) – a GValue

Returns:

a new GdkContentProvider

Return type:

Gdk.ContentProvider

Create a content provider that provides the given value.

classmethod new_union(providers)[source]
Parameters:

providers ([Gdk.ContentProvider] or None) – The ``GdkContentProvider``s to present the union of

Returns:

a new GdkContentProvider

Return type:

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 ``c gdk_content_provider_new_union ((GdkContentProvider *[2]) {

gdk_content_provider_new_typed (G_TYPE_FILE, file), gdk_content_provider_new_typed (G_TYPE_TEXTURE, texture)

}, 2);

``

content_changed()[source]

Emits the ::content-changed signal.

get_value()[source]
Raises:

GLib.Error

Returns:

True if the value was set successfully. Otherwise error will be set to describe the failure.

value:

the GValue to fill

Return type:

(bool, value: GObject.Value)

Gets the contents of self 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 [method`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.

ref_formats()[source]
Returns:

The formats of the provider

Return type:

Gdk.ContentFormats

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

ref_storable_formats()[source]
Returns:

The storable formats of the provider

Return type:

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 [method`Gdk`.ContentProvider.ref_formats].

write_mime_type_async(mime_type, stream, io_priority, cancellable, callback, *user_data)[source]
Parameters:
  • mime_type (str) – the mime type to provide the data in

  • stream (Gio.OutputStream) – the GOutputStream to write to

  • io_priority (int) – I/O priority of the request.

  • cancellable (Gio.Cancellable or None) – optional GCancellable object, None to ignore.

  • callback (Gio.AsyncReadyCallback or None) – callback to call when the request is satisfied

  • user_data (object or None) – the data to pass to callback function

Asynchronously writes the contents of self to stream in the given mime_type.

When the operation is finished callback will be called. You must then call [method`Gdk`.ContentProvider.write_mime_type_finish] to get the result of the operation.

The given mime type does not need to be listed in the formats returned by [method`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.

write_mime_type_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

True if the operation was completed successfully. Otherwise error will be set to describe the failure.

Return type:

bool

Finishes an asynchronous write operation.

See [method`Gdk`.ContentProvider.write_mime_type_async].

do_attach_clipboard(clipboard) virtual
Parameters:

clipboard (Gdk.Clipboard) –

do_content_changed() virtual

Emits the ::content-changed signal.

do_detach_clipboard(clipboard) virtual
Parameters:

clipboard (Gdk.Clipboard) –

do_get_value() virtual
Returns:

True if the value was set successfully. Otherwise error will be set to describe the failure.

value:

the GValue to fill

Return type:

(bool, value: 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 [method`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.

do_ref_formats() virtual
Returns:

The formats of the provider

Return type:

Gdk.ContentFormats

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

do_ref_storable_formats() virtual
Returns:

The storable formats of the provider

Return type:

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 [method`Gdk`.ContentProvider.ref_formats].

do_write_mime_type_async(mime_type, stream, io_priority, cancellable, callback, *user_data) virtual
Parameters:
  • mime_type (str) – the mime type to provide the data in

  • stream (Gio.OutputStream) – the GOutputStream to write to

  • io_priority (int) – I/O priority of the request.

  • cancellable (Gio.Cancellable or None) – optional GCancellable object, None to ignore.

  • callback (Gio.AsyncReadyCallback or None) – callback to call when the request is satisfied

  • user_data (object or None) – the data to pass to callback function

Asynchronously writes the contents of provider to stream in the given mime_type.

When the operation is finished callback will be called. You must then call [method`Gdk`.ContentProvider.write_mime_type_finish] to get the result of the operation.

The given mime type does not need to be listed in the formats returned by [method`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.

do_write_mime_type_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Returns:

True if the operation was completed successfully. Otherwise error will be set to describe the failure.

Return type:

bool

Finishes an asynchronous write operation.

See [method`Gdk`.ContentProvider.write_mime_type_async].

Signal Details

Gdk.ContentProvider.signals.content_changed(content_provider)
Signal Name:

content-changed

Flags:

RUN_LAST

Parameters:

content_provider (Gdk.ContentProvider) – The object which received the signal

Emitted whenever the content provided by this provider has changed.

Property Details

Gdk.ContentProvider.props.formats
Name:

formats

Type:

Gdk.ContentFormats

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

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

Gdk.ContentProvider.props.storable_formats
Name:

storable-formats

Type:

Gdk.ContentFormats

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

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