Gdk.ContentFormats

Fields

None

Methods

class

new (mime_types)

class

new_for_gtype (type)

class

parse (string)

contain_gtype (type)

contain_mime_type (mime_type)

get_gtypes ()

get_mime_types ()

match (second)

match_gtype (second)

match_mime_type (second)

print_ (string)

ref ()

to_string ()

union (second)

union_deserialize_gtypes ()

union_deserialize_mime_types ()

union_serialize_gtypes ()

union_serialize_mime_types ()

unref ()

Details

class Gdk.ContentFormats

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 [class`Gdk`.Drag], [class`Gdk`.Drop], [class`Gdk`.Clipboard] or [class`Gdk`.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, [class`Gdk`.ContentSerializer] and [class`Gdk`.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 [method`Gdk`.ContentFormats.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 [method`Gdk`.ContentFormats.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 [struct`Gdk`.ContentFormatsBuilder] structure is meant to help in this endeavor.

classmethod new(mime_types)[source]
Parameters:

mime_types ([str] or None) – Pointer to an array of mime types

Returns:

the new GdkContentFormats.

Return type:

Gdk.ContentFormats

Creates a new GdkContentFormats from 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 [struct`Gdk`.ContentFormatsBuilder] instead.

classmethod new_for_gtype(type)[source]
Parameters:

type (GObject.GType) – a GType

Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Creates a new GdkContentFormats for a given GType.

classmethod parse(string)[source]
Parameters:

string (str) – the string to parse

Returns:

the content formats if string is valid

Return type:

Gdk.ContentFormats or None

Parses the given string into GdkContentFormats and returns the formats.

Strings printed via [method`Gdk`.ContentFormats.to_string] can be read in again successfully using this function.

If string does not describe valid content formats, None is returned.

New in version 4.4.

contain_gtype(type)[source]
Parameters:

type (GObject.GType) – the GType to search for

Returns:

True if the GType was found

Return type:

bool

Checks if a given GType is part of the given self.

contain_mime_type(mime_type)[source]
Parameters:

mime_type (str) – the mime type to search for

Returns:

True if the mime_type was found

Return type:

bool

Checks if a given mime type is part of the given self.

get_gtypes()[source]
Returns:

GObject.TYPE_INVALID-terminated array of types included in self

Return type:

[GObject.GType] or None

Gets the ``GType``s included in self.

Note that self may not contain any ``GType``s, in particular when they are empty. In that case None will be returned.

get_mime_types()[source]
Returns:

None-terminated array of interned strings of mime types included in self

Return type:

[str] or None

Gets the mime types included in self.

Note that self may not contain any mime types, in particular when they are empty. In that case None will be returned.

match(second)[source]
Parameters:

second (Gdk.ContentFormats) – the GdkContentFormats to intersect with

Returns:

True if a matching format was found.

Return type:

bool

Checks if self and second have any matching formats.

match_gtype(second)[source]
Parameters:

second (Gdk.ContentFormats) – the GdkContentFormats to intersect with

Returns:

The first common GType or GObject.TYPE_INVALID if none.

Return type:

GObject.GType

Finds the first GType from self that is also contained in second.

If no matching GType is found, GObject.TYPE_INVALID is returned.

match_mime_type(second)[source]
Parameters:

second (Gdk.ContentFormats) – the GdkContentFormats to intersect with

Returns:

The first common mime type or None if none

Return type:

str or None

Finds the first mime type from self that is also contained in second.

If no matching mime type is found, None is returned.

print_(string)[source]
Parameters:

string (GLib.String) – a GString to print into

Prints the given self into a string for human consumption.

The result of this function can later be parsed with [func`Gdk`.ContentFormats.parse].

ref()[source]
Returns:

the passed in GdkContentFormats.

Return type:

Gdk.ContentFormats

Increases the reference count of a GdkContentFormats by one.

to_string()[source]
Returns:

a new string

Return type:

str

Prints the given self into a human-readable string.

The resulting string can be parsed with [func`Gdk`.ContentFormats.parse].

This is a small wrapper around [method`Gdk`.ContentFormats.print] to help when debugging.

union(second)[source]
Parameters:

second (Gdk.ContentFormats) – the GdkContentFormats to merge from

Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Append all missing types from second to self, in the order they had in second.

union_deserialize_gtypes()[source]
Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Add GTypes for mime types in self for which deserializers are registered.

union_deserialize_mime_types()[source]
Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Add mime types for GTypes in self for which deserializers are registered.

union_serialize_gtypes()[source]
Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Add GTypes for the mime types in self for which serializers are registered.

union_serialize_mime_types()[source]
Returns:

a new GdkContentFormats

Return type:

Gdk.ContentFormats

Add mime types for GTypes in self for which serializers are registered.

unref()[source]

Decreases the reference count of a GdkContentFormats by one.

If the resulting reference count is zero, frees the formats.