ContentFormats#
- class ContentFormats(**kwargs)#
The GdkContentFormats structure is used to advertise and negotiate the
format of content.
You will encounter GdkContentFormats when interacting with objects
controlling operations that pass data between different widgets, window
or application, like Drag, Drop,
Clipboard or ContentProvider.
GDK supports content in 2 forms: GType and mime type.
Using GTypes is meant only for in-process content transfers. Mime types
are meant to be used for data passing both in-process and out-of-process.
The details of how data is passed is described in the documentation of
the actual implementations. To transform between the two forms,
ContentSerializer and ContentDeserializer are used.
A GdkContentFormats describes a set of possible formats content can be
exchanged in. It is assumed that this set is ordered. GTypes are more
important than mime types. Order between different GTypes or mime types
is the order they were added in, most important first. Functions that
care about order, such as union, will describe
in their documentation how they interpret that order, though in general the
order of the first argument is considered the primary order of the result,
followed by the order of further arguments.
For debugging purposes, the function to_string
exists. It will print a comma-separated list of formats from most important
to least important.
GdkContentFormats is an immutable struct. After creation, you cannot change
the types it represents. Instead, new GdkContentFormats have to be created.
The ContentFormatsBuilder structure is meant to help in this
endeavor.
Constructors#
- class ContentFormats
- classmethod new(mime_types: list[str] | None = None) ContentFormats#
Creates a new
GdkContentFormatsfrom an array of mime types.The mime types must be valid and different from each other or the behavior of the return value is undefined. If you cannot guarantee this, use
ContentFormatsBuilderinstead.- Parameters:
mime_types – Pointer to an array of mime types
- classmethod new_for_gtype(type: GType) ContentFormats#
Creates a new
GdkContentFormatsfor a givenGType.- Parameters:
type – a
GType
Methods#
- class ContentFormats
- contain_gtype(type: GType) bool#
Checks if a given
GTypeis part of the givenformats.- Parameters:
type – the
GTypeto search for
- contain_mime_type(mime_type: str) bool#
Checks if a given mime type is part of the given
formats.- Parameters:
mime_type – the mime type to search for
- get_gtypes() list[GType] | None#
Gets the
GTypes included informats.Note that
formatsmay not contain anyGTypes, in particular when they are empty. In that caseNonewill be returned.
- get_mime_types() list[str] | None#
Gets the mime types included in
formats.Note that
formatsmay not contain any mime types, in particular when they are empty. In that caseNonewill be returned.
- match(second: ContentFormats) bool#
Checks if
firstandsecondhave any matching formats.- Parameters:
second – the
GdkContentFormatsto intersect with
- match_gtype(second: ContentFormats) GType#
Finds the first
GTypefromfirstthat is also contained insecond.If no matching
GTypeis found,Invalidis returned.- Parameters:
second – the
GdkContentFormatsto intersect with
- match_mime_type(second: ContentFormats) str | None#
Finds the first mime type from
firstthat is also contained insecond.If no matching mime type is found,
Noneis returned.- Parameters:
second – the
GdkContentFormatsto intersect with
- classmethod parse() ContentFormats | None#
Parses the given
stringintoGdkContentFormatsand returns the formats.Strings printed via
to_stringcan be read in again successfully using this function.If
stringdoes not describe valid content formats,Noneis returned.Added in version 4.4.
- to_string() str#
Prints the given
formatsinto a human-readable string.The resulting string can be parsed with
parse.This is a small wrapper around
printto help when debugging.
- union(second: ContentFormats) ContentFormats#
Append all missing types from
secondtofirst, in the order they had insecond.- Parameters:
second – the
GdkContentFormatsto merge from
- union_deserialize_gtypes() ContentFormats#
Add GTypes for mime types in
formatsfor which deserializers are registered.
- union_deserialize_mime_types() ContentFormats#
Add mime types for GTypes in
formatsfor which deserializers are registered.
- union_serialize_gtypes() ContentFormats#
Add GTypes for the mime types in
formatsfor which serializers are registered.
- union_serialize_mime_types() ContentFormats#
Add mime types for GTypes in
formatsfor which serializers are registered.