Paintable#
- class Paintable(*args, **kwargs)#
Implementations: DmabufTexture, GLTexture, MemoryTexture, Texture
GdkPaintable is a simple interface used by GTK to represent content that
can be painted.
The content of a GdkPaintable can be painted anywhere at any size
without requiring any sort of layout. The interface is inspired by
similar concepts elsewhere, such as
ClutterContent,
HTML/CSS Paint Sources,
or SVG Paint Servers.
A GdkPaintable can be snapshot at any time and size using
snapshot. How the paintable interprets that size and
if it scales or centers itself into the given rectangle is implementation
defined, though if you are implementing a GdkPaintable and don’t know what
to do, it is suggested that you scale your paintable ignoring any potential
aspect ratio.
The contents that a GdkPaintable produces may depend on the Snapshot
passed to it. For example, paintables may decide to use more detailed images
on higher resolution screens or when OpenGL is available. A GdkPaintable
will however always produce the same output for the same snapshot.
A GdkPaintable may change its contents, meaning that it will now produce
a different output with the same snapshot. Once that happens, it will call
invalidate_contents which will emit the
invalidate_contents signal. If a paintable is known
to never change its contents, it will set the CONTENTS
flag. If a consumer cannot deal with changing contents, it may call
get_current_image which will return a static
paintable and use that.
A paintable can report an intrinsic (or preferred) size or aspect ratio it
wishes to be rendered at, though it doesn’t have to. Consumers of the interface
can use this information to layout thepaintable appropriately. Just like the
contents, the size of a paintable can change. A paintable will indicate this
by calling invalidate_size which will emit the
invalidate_size signal. And just like for contents,
if a paintable is known to never change its size, it will set the
SIZE flag.
Besides API for applications, there are some functions that are only
useful for implementing subclasses and should not be used by applications:
invalidate_contents,
invalidate_size,
new_empty.
Methods#
- class Paintable
- compute_concrete_size(specified_width: float, specified_height: float, default_width: float, default_height: float) tuple[float, float]#
Compute a concrete size for the
GdkPaintable.Applies the sizing algorithm outlined in the CSS Image spec to the given
paintable. See that link for more details.It is not necessary to call this function when both
specified_widthandspecified_heightare known, but it is useful to call this function in GtkWidget:measure implementations to compute the other dimension when only one dimension is given.- Parameters:
specified_width – the width
paintablecould be drawn into or 0.0 if unknownspecified_height – the height
paintablecould be drawn into or 0.0 if unknowndefault_width – the width
paintablewould be drawn into if no other constraints were givendefault_height – the height
paintablewould be drawn into if no other constraints were given
- get_current_image() Paintable#
Gets an immutable paintable for the current contents displayed by
paintable.This is useful when you want to retain the current state of an animation, for example to take a screenshot of a running animation.
If the
paintableis already immutable, it will return itself.
- get_flags() PaintableFlags#
Get flags for the paintable.
This is oftentimes useful for optimizations.
See
PaintableFlagsfor the flags and what they mean.
- get_intrinsic_aspect_ratio() float#
Gets the preferred aspect ratio the
paintablewould like to be displayed at.The aspect ratio is the width divided by the height, so a value of 0.5 means that the
paintableprefers to be displayed twice as high as it is wide. Consumers of this interface can use this to preserve aspect ratio when displaying the paintable.This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.Usually when a
paintablereturns nonzero values fromget_intrinsic_widthandget_intrinsic_heightthe aspect ratio should conform to those values, though that is not required.If the
paintabledoes not have a preferred aspect ratio, it returns 0. Negative values are never returned.
- get_intrinsic_height() int#
Gets the preferred height the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.If the
paintabledoes not have a preferred height, it returns 0. Negative values are never returned.
- get_intrinsic_width() int#
Gets the preferred width the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.If the
paintabledoes not have a preferred width, it returns 0. Negative values are never returned.
- invalidate_contents() None#
Called by implementations of
GdkPaintableto invalidate their contents.Unless the contents are invalidated, implementations must guarantee that multiple calls of
snapshotproduce the same output.This function will emit the
invalidate_contentssignal.If a
paintablereports theCONTENTSflag, it must not call this function.
- invalidate_size() None#
Called by implementations of
GdkPaintableto invalidate their size.As long as the size is not invalidated,
paintablemust return the same values for its intrinsic width, height and aspect ratio.This function will emit the
invalidate_sizesignal.If a
paintablereports theSIZEflag, it must not call this function.
- classmethod new_empty(intrinsic_height: int) Paintable#
Returns a paintable that has the given intrinsic size and draws nothing.
This is often useful for implementing the
get_current_imagevirtual function when the paintable is in an incomplete state (like a GtkMediaStream before receiving the first frame).- Parameters:
intrinsic_height – The intrinsic height to report. Can be 0 for no height.
- snapshot(snapshot: Snapshot, width: float, height: float) None#
Snapshots the given paintable with the given
widthandheight.The paintable is drawn at the current (0,0) offset of the
snapshot. Ifwidthandheightare not larger than zero, this function will do nothing.- Parameters:
snapshot – a
GdkSnapshotto snapshot towidth – width to snapshot in
height – height to snapshot in
Signals#
Virtual Methods#
- class Paintable
- do_get_current_image() Paintable#
Gets an immutable paintable for the current contents displayed by
paintable.This is useful when you want to retain the current state of an animation, for example to take a screenshot of a running animation.
If the
paintableis already immutable, it will return itself.
- do_get_flags() PaintableFlags#
Get flags for the paintable.
This is oftentimes useful for optimizations.
See
PaintableFlagsfor the flags and what they mean.
- do_get_intrinsic_aspect_ratio() float#
Gets the preferred aspect ratio the
paintablewould like to be displayed at.The aspect ratio is the width divided by the height, so a value of 0.5 means that the
paintableprefers to be displayed twice as high as it is wide. Consumers of this interface can use this to preserve aspect ratio when displaying the paintable.This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.Usually when a
paintablereturns nonzero values fromget_intrinsic_widthandget_intrinsic_heightthe aspect ratio should conform to those values, though that is not required.If the
paintabledoes not have a preferred aspect ratio, it returns 0. Negative values are never returned.
- do_get_intrinsic_height() int#
Gets the preferred height the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.If the
paintabledoes not have a preferred height, it returns 0. Negative values are never returned.
- do_get_intrinsic_width() int#
Gets the preferred width the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to
snapshot.If the
paintabledoes not have a preferred width, it returns 0. Negative values are never returned.
- do_snapshot(snapshot: Snapshot, width: float, height: float) None#
Snapshots the given paintable with the given
widthandheight.The paintable is drawn at the current (0,0) offset of the
snapshot. Ifwidthandheightare not larger than zero, this function will do nothing.- Parameters:
snapshot – a
GdkSnapshotto snapshot towidth – width to snapshot in
height – height to snapshot in