Functions#
- cairo_draw_from_gl(cr: Context, surface: Surface, source: int, source_type: int, buffer_scale: int, x: int, y: int, width: int, height: int) None#
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 ontocrwith an OVER operation, respecting the current clip. The top left corner of the rectangle specified byx,y,widthandheightwill be drawn at the current (0,0) position of thecairo_t.This will work for all
cairo_t, as long assurfaceis 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 tocrit 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
new; if you want to use that texture in Cairo, usedownloadto download the data into a Cairo image surface.- Parameters:
cr – a cairo context
surface – The surface we’re rendering for (not necessarily into)
source – The GL ID of the source buffer
source_type – The type of the
sourcebuffer_scale – The scale-factor that the
sourcebuffer is allocated forx – The source x position in
sourceto start copying from in GL coordinatesy – The source y position in
sourceto start copying from in GL coordinateswidth – The width of the region to draw
height – The height of the region to draw
- cairo_rectangle(cr: Context, rectangle: Rectangle) None#
Adds the given rectangle to the current path of
cr.- Parameters:
cr – a cairo context
rectangle – a
GdkRectangle
- cairo_region(cr: Context, region: Region) None#
Adds the given region to the current path of
cr.- Parameters:
cr – a cairo context
region – a
cairo_region_t
- cairo_region_create_from_surface(surface: Surface) Region#
Creates region that covers the area where the given
surfaceis more than 50% opaque.This function takes into account device offsets that might be set with cairo_surface_set_device_offset().
- Parameters:
surface – a cairo surface
- Returns:
A
cairo_region_t
- cairo_set_source_pixbuf(cr: Context, pixbuf: Pixbuf, pixbuf_x: float, pixbuf_y: float) None#
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
pixbufispixbuf_x,pixbuf_y.- Parameters:
cr – a cairo context
pixbuf – a
GdkPixbufpixbuf_x – X coordinate of location to place upper left corner of
pixbufpixbuf_y – Y coordinate of location to place upper left corner of
pixbuf
- cairo_set_source_rgba(cr: Context, rgba: RGBA) None#
Sets the specified
GdkRGBAas the source color ofcr.- Parameters:
cr – a cairo context
rgba – a
GdkRGBA
- color_state_get_rec2100_linear() ColorState#
- color_state_get_rec2100_pq() ColorState#
- color_state_get_srgb() ColorState#
- color_state_get_srgb_linear() ColorState#
- content_deserialize_async(stream: InputStream, mime_type: str, type: GType, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Read content from the given input stream and deserialize it, asynchronously.
The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.
- Parameters:
stream – a
GInputStreamto read the serialized content frommime_type – the mime type to deserialize from
type – the GType to deserialize from
io_priority – the I/O priority of the operation
cancellable – optional
GCancellableobjectcallback – callback to call when the operation is done
user_data – data to pass to the callback function
- content_deserialize_finish(result: AsyncResult) tuple[bool, Value]#
Finishes a content deserialization operation.
- Parameters:
result – the
GAsyncResult- Returns:
Trueif the operation was successful. In this case,valueis set.Falseif an error occurred. In this case,erroris set
- content_formats_parse(string: str) ContentFormats | None#
- Parameters:
string
- content_register_deserializer(mime_type: str, type: GType, deserialize: Callable[[ContentDeserializer], None], data: Any = None) None#
Registers a function to deserialize object of a given type.
- Parameters:
mime_type – the mime type which the function can deserialize from
type – the type of objects that the function creates
deserialize – the callback
data – data that
deserializecan access
- content_register_serializer(type: GType, mime_type: str, serialize: Callable[[ContentSerializer], None], data: Any = None) None#
Registers a function to serialize objects of a given type.
- Parameters:
type – the type of objects that the function can serialize
mime_type – the mime type to serialize to
serialize – the callback
data – data that
serializecan access
- content_serialize_async(stream: OutputStream, mime_type: str, value: Value, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Serialize content and write it to the given output stream, asynchronously.
The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.
- Parameters:
stream – a
GOutputStreamto write the serialized content tomime_type – the mime type to serialize to
value – the content to serialize
io_priority – the I/O priority of the operation
cancellable – optional
GCancellableobjectcallback – callback to call when the operation is done
user_data – data to pass to the callback function
- content_serialize_finish(result: AsyncResult) bool#
Finishes a content serialization operation.
- Parameters:
result – the
GAsyncResult- Returns:
Trueif the operation was successful,Falseif an error occurred. In this case,erroris set
- drag_action_is_unique(action: DragAction) bool#
- Parameters:
action
- events_get_angle(event1: Event, event2: Event) tuple[bool, float]#
Returns the relative angle from
event1toevent2.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.- Parameters:
event1 – first
GdkEventevent2 – second
GdkEvent
- Returns:
Trueif the angle could be calculated.
- events_get_center(event1: Event, event2: Event) tuple[bool, float, float]#
Returns the point halfway between the events’ positions.
This assumes that both events have X/Y information. If not, this function returns
False.- Parameters:
event1 – first
GdkEventevent2 – second
GdkEvent
- Returns:
Trueif the center could be calculated.
- events_get_distance(event1: Event, event2: Event) tuple[bool, float]#
Returns the distance between the event locations.
This assumes that both events have X/Y information. If not, this function returns
False.- Parameters:
event1 – first
GdkEventevent2 – second
GdkEvent
- Returns:
Trueif the distance could be calculated.
- intern_mime_type(string: str) str | None#
Canonicalizes the given mime type and interns the result.
If
stringis not a valid mime type,Noneis returned instead. See RFC 2048 for the syntax if mime types.- Parameters:
string – string of a potential mime type
- Returns:
An interned string for the canonicalized mime type or
Noneif the string wasn’t a valid mime type
- keyval_convert_case(symbol: int) tuple[int, 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.- Parameters:
symbol – a keyval
- keyval_from_name(keyval_name: str) int#
Converts a key name to a key value.
The names are the same as those in the
gdk/gdkkeysyms.hheader file but without the leading “GDK_KEY_”.- Parameters:
keyval_name – a key name
- Returns:
the corresponding key value, or
KEY_VOIDSYMBOLif the key name is not a valid key
- keyval_is_lower(keyval: int) bool#
Returns
Trueif the given key value is in lower case.- Parameters:
keyval – a key value.
- Returns:
Trueifkeyvalis in lower case, or ifkeyvalis not subject to case conversion.
- keyval_is_upper(keyval: int) bool#
Returns
Trueif the given key value is in upper case.- Parameters:
keyval – a key value.
- Returns:
Trueifkeyvalis in upper case, or ifkeyvalis not subject to case conversion.
- keyval_name(keyval: int) str | None#
Converts a key value into a symbolic name.
The names are the same as those in the
gdk/gdkkeysyms.hheader file but without the leading “GDK_KEY_”.- Parameters:
keyval – a key value
- Returns:
a string containing the name of the key
- keyval_to_lower(keyval: int) int#
Converts a key value to lower case, if applicable.
- Parameters:
keyval – a key value.
- Returns:
the lower case form of
keyval, orkeyvalitself if it is already in lower case or it is not subject to case conversion.
- keyval_to_unicode(keyval: int) 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
KEY_KP_DECIMAL.- Parameters:
keyval – a GDK key symbol
- Returns:
the corresponding unicode character, or 0 if there is no corresponding character.
- keyval_to_upper(keyval: int) int#
Converts a key value to upper case, if applicable.
- Parameters:
keyval – a key value.
- Returns:
the upper case form of
keyval, orkeyvalitself if it is already in upper case or it is not subject to case conversion.
- paintable_new_empty(intrinsic_width: int, intrinsic_height: int) Paintable#
- Parameters:
intrinsic_width
intrinsic_height
- pixbuf_get_from_surface(surface: Surface, src_x: int, src_y: int, width: int, height: int) Pixbuf | None#
Transfers image data from a
cairo_surface_tand converts it to aGdkPixbuf.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
surfacecontains one.Deprecated since version 4.12: Use
Textureand subclasses instead cairo surfaces and pixbufs- Parameters:
surface – surface to copy from
src_x – Source X coordinate within
surfacesrc_y – Source Y coordinate within
surfacewidth – Width in pixels of region to get
height – Height in pixels of region to get
- Returns:
A newly-created pixbuf with a reference count of 1
- pixbuf_get_from_texture(texture: Texture) Pixbuf | 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
Textureand subclasses instead cairo surfaces and pixbufs- Parameters:
texture – a
GdkTexture- Returns:
a new
GdkPixbuf
- set_allowed_backends(backends: str) None#
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:
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_BACKENDenvironment 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:
broadwaymacoswayland.win32x11
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
open,gtk_init(), orgtk_init_check()in order to take effect.- Parameters:
backends – a comma-separated list of backends