Functions

cairo_draw_from_gl (cr, surface, source, source_type, buffer_scale, x, y, width, height)

cairo_rectangle (cr, rectangle)

cairo_region (cr, region)

cairo_region_create_from_surface (surface)

cairo_set_source_pixbuf (cr, pixbuf, pixbuf_x, pixbuf_y)

cairo_set_source_rgba (cr, rgba)

content_deserialize_async (stream, mime_type, type, io_priority, cancellable, callback, *user_data)

content_deserialize_finish (result)

content_formats_parse (string)

content_register_deserializer (mime_type, type, deserialize, *data)

content_register_serializer (type, mime_type, serialize, *data)

content_serialize_async (stream, mime_type, value, io_priority, cancellable, callback, *user_data)

content_serialize_finish (result)

drag_action_is_unique (action)

drag_surface_size_get_type ()

events_get_angle (event1, event2)

events_get_center (event1, event2)

events_get_distance (event1, event2)

gl_error_quark ()

intern_mime_type (string)

keyval_convert_case (symbol)

keyval_from_name (keyval_name)

keyval_is_lower (keyval)

keyval_is_upper (keyval)

keyval_name (keyval)

keyval_to_lower (keyval)

keyval_to_unicode (keyval)

keyval_to_upper (keyval)

paintable_new_empty (intrinsic_width, intrinsic_height)

pixbuf_get_from_surface (surface, src_x, src_y, width, height)

pixbuf_get_from_texture (texture)

set_allowed_backends (backends)

texture_error_quark ()

toplevel_size_get_type ()

unicode_to_keyval (wc)

vulkan_error_quark ()

Details

Gdk.cairo_draw_from_gl(cr, surface, source, source_type, buffer_scale, x, y, width, height)[source]
Parameters:
  • cr (cairo.Context) – a cairo context

  • surface (Gdk.Surface) – The surface we’re rendering for (not necessarily into)

  • source (int) – The GL ID of the source buffer

  • source_type (int) – The type of the source

  • buffer_scale (int) – The scale-factor that the source buffer is allocated for

  • x (int) – The source x position in source to start copying from in GL coordinates

  • y (int) – The source y position in source to start copying from in GL coordinates

  • width (int) – The width of the region to draw

  • height (int) – The height of the region to draw

The main way to not draw GL content in GTK.

It takes a render buffer ID (source_type == GL_RENDERBUFFER) or a texture id (source_type == GL_TEXTURE) and draws it onto cr with an OVER operation, respecting the current clip. The top left corner of the rectangle specified by x, y, width and height will be drawn at the current (0,0) position of the cairo_t.

This will work for *all* cairo_t, as long as surface is realized, but the fallback implementation that reads back the pixels from the buffer may be used in the general case. In the case of direct drawing to a surface with no special effects applied to cr it will however use a more efficient approach.

For GL_RENDERBUFFER the code will always fall back to software for buffers with alpha components, so make sure you use GL_TEXTURE if using alpha.

Calling this may change the current GL context.

Deprecated since version 4.6: The function is overly complex and produces broken output in various combinations of arguments. If you want to draw with GL textures in GTK, use [ctor`Gdk`.GLTexture.new]; if you want to use that texture in Cairo, use [method`Gdk`.Texture.download] to download the data into a Cairo image surface.

Gdk.cairo_rectangle(cr, rectangle)[source]
Parameters:

Adds the given rectangle to the current path of cr.

Gdk.cairo_region(cr, region)[source]
Parameters:

Adds the given region to the current path of cr.

Gdk.cairo_region_create_from_surface(surface)[source]
Parameters:

surface (cairo.Surface) – a cairo surface

Returns:

A cairo_region_t

Return type:

cairo.Region

Creates region that covers the area where the given surface is more than 50% opaque.

This function takes into account device offsets that might be set with cairo.Surface.set_device_offset().

Gdk.cairo_set_source_pixbuf(cr, pixbuf, pixbuf_x, pixbuf_y)[source]
Parameters:
  • cr (cairo.Context) – a cairo context

  • pixbuf (GdkPixbuf.Pixbuf) – a GdkPixbuf

  • pixbuf_x (float) – X coordinate of location to place upper left corner of pixbuf

  • pixbuf_y (float) – Y coordinate of location to place upper left corner of pixbuf

Sets the given pixbuf as the source pattern for cr.

The pattern has an extend mode of cairo.Extend.NONE and is aligned so that the origin of pixbuf is pixbuf_x, pixbuf_y.

Gdk.cairo_set_source_rgba(cr, rgba)[source]
Parameters:

Sets the specified GdkRGBA as the source color of cr.

Gdk.content_deserialize_async(stream, mime_type, type, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Read content from the given input stream and deserialize it, asynchronously.

The default I/O priority is GLib.PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.

When the operation is finished, callback will be called. You must then call [func`Gdk`.content_deserialize_finish] to get the result of the operation.

Gdk.content_deserialize_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the GAsyncResult

Raises:

GLib.Error

Returns:

True if the operation was successful. In this case, value is set. False if an error occurred. In this case, error is set

value:

return location for the result of the operation

Return type:

(bool, value: GObject.Value)

Finishes a content deserialization operation.

Gdk.content_formats_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.

Gdk.content_register_deserializer(mime_type, type, deserialize, *data)[source]
Parameters:
  • mime_type (str) – the mime type which the function can deserialize from

  • type (GObject.GType) – the type of objects that the function creates

  • deserialize (Gdk.ContentDeserializeFunc) – the callback

  • data (object or None) – data that deserialize can access

Registers a function to deserialize object of a given type.

Gdk.content_register_serializer(type, mime_type, serialize, *data)[source]
Parameters:

Registers a function to serialize objects of a given type.

Gdk.content_serialize_async(stream, mime_type, value, io_priority, cancellable, callback, *user_data)[source]
Parameters:
  • stream (Gio.OutputStream) – a GOutputStream to write the serialized content to

  • mime_type (str) – the mime type to serialize to

  • value (GObject.Value) – the content to serialize

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

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

  • callback (Gio.AsyncReadyCallback or None) – callback to call when the operation is done

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

Serialize content and write it to the given output stream, asynchronously.

The default I/O priority is GLib.PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.

When the operation is finished, callback will be called. You must then call [func`Gdk`.content_serialize_finish] to get the result of the operation.

Gdk.content_serialize_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the GAsyncResult

Raises:

GLib.Error

Returns:

True if the operation was successful, False if an error occurred. In this case, error is set

Return type:

bool

Finishes a content serialization operation.

Gdk.drag_action_is_unique(action)[source]
Parameters:

action (Gdk.DragAction) – a GdkDragAction

Returns:

True if exactly one action was given

Return type:

bool

Checks if action represents a single action or includes multiple actions.

When action is 0 - ie no action was given, True is returned.

Gdk.drag_surface_size_get_type()[source]
Return type:

GObject.GType

Gdk.events_get_angle(event1, event2)[source]
Parameters:
Returns:

True if the angle could be calculated.

angle:

return location for the relative angle between both events

Return type:

(bool, angle: float)

Returns the relative angle from event1 to event2.

The relative angle is the angle between the X axis and the line through both events’ positions. The rotation direction for positive angles is from the positive X axis towards the positive Y axis.

This assumes that both events have X/Y information. If not, this function returns False.

Gdk.events_get_center(event1, event2)[source]
Parameters:
Returns:

True if the center could be calculated.

x:

return location for the X coordinate of the center

y:

return location for the Y coordinate of the center

Return type:

(bool, x: float, y: float)

Returns the point halfway between the events’ positions.

This assumes that both events have X/Y information. If not, this function returns False.

Gdk.events_get_distance(event1, event2)[source]
Parameters:
Returns:

True if the distance could be calculated.

distance:

return location for the distance

Return type:

(bool, distance: float)

Returns the distance between the event locations.

This assumes that both events have X/Y information. If not, this function returns False.

Gdk.gl_error_quark()[source]
Return type:

int

Gdk.intern_mime_type(string)[source]
Parameters:

string (str) – string of a potential mime type

Returns:

An interned string for the canonicalized mime type or None if the string wasn’t a valid mime type

Return type:

str or None

Canonicalizes the given mime type and interns the result.

If string is not a valid mime type, None is returned instead. See RFC 2048 for the syntax if mime types.

Gdk.keyval_convert_case(symbol)[source]
Parameters:

symbol (int) – a keyval

Returns:

lower:

return location for lowercase version of symbol

upper:

return location for uppercase version of symbol

Return type:

(lower: int, upper: int)

Obtains the upper- and lower-case versions of the keyval symbol.

Examples of keyvals are GDK_KEY_a, GDK_KEY_Enter, GDK_KEY_F1, etc.

Gdk.keyval_from_name(keyval_name)[source]
Parameters:

keyval_name (str) – a key name

Returns:

the corresponding key value, or Gdk.KEY_VoidSymbol if the key name is not a valid key

Return type:

int

Converts a key name to a key value.

The names are the same as those in the gdk/gdkkeysyms.h header file but without the leading “GDK_KEY_”.

Gdk.keyval_is_lower(keyval)[source]
Parameters:

keyval (int) – a key value.

Returns:

True if keyval is in lower case, or if keyval is not subject to case conversion.

Return type:

bool

Returns True if the given key value is in lower case.

Gdk.keyval_is_upper(keyval)[source]
Parameters:

keyval (int) – a key value.

Returns:

True if keyval is in upper case, or if keyval is not subject to case conversion.

Return type:

bool

Returns True if the given key value is in upper case.

Gdk.keyval_name(keyval)[source]
Parameters:

keyval (int) – a key value

Returns:

a string containing the name of the key

Return type:

str or None

Converts a key value into a symbolic name.

The names are the same as those in the gdk/gdkkeysyms.h header file but without the leading “GDK_KEY_”.

Gdk.keyval_to_lower(keyval)[source]
Parameters:

keyval (int) – a key value.

Returns:

the lower case form of keyval, or keyval itself if it is already in lower case or it is not subject to case conversion.

Return type:

int

Converts a key value to lower case, if applicable.

Gdk.keyval_to_unicode(keyval)[source]
Parameters:

keyval (int) – a GDK key symbol

Returns:

the corresponding unicode character, or 0 if there is no corresponding character.

Return type:

int

Convert from a GDK key symbol to the corresponding Unicode character.

Note that the conversion does not take the current locale into consideration, which might be expected for particular keyvals, such as Gdk.KEY_KP_Decimal.

Gdk.keyval_to_upper(keyval)[source]
Parameters:

keyval (int) – a key value.

Returns:

the upper case form of keyval, or keyval itself if it is already in upper case or it is not subject to case conversion.

Return type:

int

Converts a key value to upper case, if applicable.

Gdk.paintable_new_empty(intrinsic_width, intrinsic_height)[source]
Parameters:
  • intrinsic_width (int) – The intrinsic width to report. Can be 0 for no width.

  • intrinsic_height (int) – The intrinsic height to report. Can be 0 for no height.

Returns:

a GdkPaintable

Return type:

Gdk.Paintable

Returns a paintable that has the given intrinsic size and draws nothing.

This is often useful for implementing the [vfunc`Gdk`.Paintable.get_current_image] virtual function when the paintable is in an incomplete state (like a GtkMediaStream before receiving the first frame).

Gdk.pixbuf_get_from_surface(surface, src_x, src_y, width, height)[source]
Parameters:
  • surface (cairo.Surface) – surface to copy from

  • src_x (int) – Source X coordinate within surface

  • src_y (int) – Source Y coordinate within surface

  • width (int) – Width in pixels of region to get

  • height (int) – Height in pixels of region to get

Returns:

A newly-created pixbuf with a reference count of 1

Return type:

GdkPixbuf.Pixbuf or None

Transfers image data from a cairo_surface_t and converts it to a GdkPixbuf.

This allows you to efficiently read individual pixels from cairo surfaces.

This function will create an RGB pixbuf with 8 bits per channel. The pixbuf will contain an alpha channel if the surface contains one.

Deprecated since version 4.12: Use [class`Gdk`.Texture] and subclasses instead cairo surfaces and pixbufs

Gdk.pixbuf_get_from_texture(texture)[source]
Parameters:

texture (Gdk.Texture) – a GdkTexture

Returns:

a new GdkPixbuf

Return type:

GdkPixbuf.Pixbuf or None

Creates a new pixbuf from texture.

This should generally not be used in newly written code as later stages will almost certainly convert the pixbuf back into a texture to draw it on screen.

Deprecated since version 4.12: Use [class`Gdk`.Texture] and subclasses instead cairo surfaces and pixbufs

Gdk.set_allowed_backends(backends)[source]
Parameters:

backends (str) – a comma-separated list of backends

Sets a list of backends that GDK should try to use.

This can be useful if your application does not work with certain GDK backends.

By default, GDK tries all included backends.

For example:

``c gdk_set_allowed_backends (“wayland,macos,*”); ``

instructs GDK to try the Wayland backend first, followed by the MacOs backend, and then all others.

If the GDK_BACKEND environment variable is set, it determines what backends are tried in what order, while still respecting the set of allowed backends that are specified by this function.

The possible backend names are:

  • broadway

  • macos

  • wayland.

  • win32

  • x11

You can also include a * in the list to try all remaining backends.

This call must happen prior to functions that open a display, such as [func`Gdk`.Display.open], gtk_init(), or gtk_init_check() in order to take effect.

Gdk.texture_error_quark()[source]
Return type:

int

Gdk.toplevel_size_get_type()[source]
Return type:

GObject.GType

Gdk.unicode_to_keyval(wc)[source]
Parameters:

wc (int) – a Unicode character

Returns:

the corresponding GDK key symbol, if one exists. or, if there is no corresponding symbol, wc | 0x01000000

Return type:

int

Convert from a Unicode character to a key symbol.

Gdk.vulkan_error_quark()[source]
Return type:

int