ContentProvider#
Superclasses: 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 new_for_value
or 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#
- class ContentProvider
- classmethod new_for_bytes(mime_type: str, bytes: Bytes) ContentProvider#
Create a content provider that provides the given
bytesas data for the givenmime_type.- Parameters:
mime_type – the mime type
bytes – a
GByteswith the data formime_type
- classmethod new_for_value(value: Value) ContentProvider#
Create a content provider that provides the given
value.- Parameters:
value – a
GValue
- classmethod new_union(providers: list[ContentProvider] | None = 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
providersin 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#
- class ContentProvider
-
- do_write_mime_type_async(self, mime_type: str, stream: OutputStream, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
mime_type
stream
io_priority
cancellable
callback
user_data
- do_write_mime_type_finish(self, result: AsyncResult) bool#
- Parameters:
result
- get_value() tuple[bool, Value]#
Gets the contents of
providerstored invalue.The
valuewill have been initialized to theGTypethe value should be provided in. This givenGTypedoes not need to be listed in the formats returned byref_formats. However, if the givenGTypeis not supported, this operation can fail andG_IO_ERROR_NOT_SUPPORTEDwill be reported.
- async write_mime_type_async(self, mime_type: str, stream: OutputStream, io_priority: int) bool#
This is the awaitable version of
write_mime_type_async().- Parameters:
mime_type – the mime type to provide the data in
stream – the
GOutputStreamto write toio_priority – I/O priority of the request.
- write_mime_type_async(mime_type: str, stream: OutputStream, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously writes the contents of
providertostreamin the givenmime_type.The given mime type does not need to be listed in the formats returned by
ref_formats. However, if the givenGTypeis not supported,G_IO_ERROR_NOT_SUPPORTEDwill be reported.The given
streamwill not be closed.- Parameters:
mime_type – the mime type to provide the data in
stream – the
GOutputStreamto write toio_priority – I/O priority of the request.
cancellable – optional
GCancellableobject,Noneto ignore.callback – callback to call when the request is satisfied
user_data – the data to pass to callback function
- write_mime_type_finish(result: AsyncResult) bool#
Finishes an asynchronous write operation.
- Parameters:
result – a
GAsyncResult
Properties#
- class ContentProvider
- props.formats: ContentFormats#
The type of the None singleton.
- props.storable_formats: ContentFormats#
The type of the None singleton.
Signals#
Virtual Methods#
- class ContentProvider
- do_attach_clipboard(clipboard: Clipboard) None#
The type of the None singleton.
- Parameters:
clipboard
- do_detach_clipboard(clipboard: Clipboard) None#
The type of the None singleton.
- Parameters:
clipboard
- do_get_value() tuple[bool, Value]#
Gets the contents of
providerstored invalue.The
valuewill have been initialized to theGTypethe value should be provided in. This givenGTypedoes not need to be listed in the formats returned byref_formats. However, if the givenGTypeis not supported, this operation can fail andG_IO_ERROR_NOT_SUPPORTEDwill be reported.
- do_ref_formats() ContentFormats#
Gets the formats that the provider can provide its current contents in.
- do_ref_storable_formats() 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
ref_formats.
- do_write_mime_type_async(mime_type: str, stream: OutputStream, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously writes the contents of
providertostreamin the givenmime_type.The given mime type does not need to be listed in the formats returned by
ref_formats. However, if the givenGTypeis not supported,G_IO_ERROR_NOT_SUPPORTEDwill be reported.The given
streamwill not be closed.- Parameters:
mime_type – the mime type to provide the data in
stream – the
GOutputStreamto write toio_priority – I/O priority of the request.
cancellable – optional
GCancellableobject,Noneto ignore.callback – callback to call when the request is satisfied
user_data – the data to pass to callback function
- do_write_mime_type_finish(result: AsyncResult) bool#
Finishes an asynchronous write operation.
- Parameters:
result – a
GAsyncResult
Fields#
- class ContentProvider
- parent#