Adw.Animation

g Adw.Animation Adw.Animation GObject.Object GObject.Object GObject.Object->Adw.Animation

Subclasses:

Adw.SpringAnimation, Adw.TimedAnimation

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

get_follow_enable_animations_setting ()

get_state ()

get_target ()

get_value ()

get_widget ()

pause ()

play ()

reset ()

resume ()

set_follow_enable_animations_setting (setting)

set_target (target)

skip ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

follow-enable-animations-setting

bool

r/w/en

state

Adw.AnimationState

r

target

Adw.AnimationTarget

r/w/c/en

value

float

r

widget

Gtk.Widget

r/w/co

Signals

Inherited:

GObject.Object (1)

Name

Short Description

done

This signal is emitted when the animation has been completed, either on its own or via calling [method`Animation`.skip].

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Adw.Animation(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Adw.AnimationClass

A base class for animations.

AdwAnimation represents an animation on a widget. It has a target that provides a value to animate, and a state indicating whether the animation hasn’t been started yet, is playing, paused or finished.

Currently there are two concrete animation types: [class`TimedAnimation`] and [class`SpringAnimation`].

AdwAnimation will automatically skip the animation if [property`Animation`:py:data::widget<Adw.Animation.props.widget>] is unmapped, or if [property`Gtk`.Settings:gtk-enable-animations] is FALSE.

The [signal`Animation`:py:func:::done<Adw.Animation.signals.done>] signal can be used to perform an action after the animation ends, for example hiding a widget after animating its [property`Gtk`.Widget:opacity] to 0.

AdwAnimation will be kept alive while the animation is playing. As such, it’s safe to create an animation, start it and immediately unref it: A fire-and-forget animation:

```c static void animation_cb (double value, MyObject *self) { // Do something with value }

static void my_object_animate (MyObject *self) { Adw.AnimationTarget *target = Adw.CallbackAnimationTarget.new ((Adw.AnimationTargetFunc) animation_cb, self, None); g_autoptr (Adw.Animation) animation = Adw.TimedAnimation.new (widget, 0, 1, 250, target);

Adw.Animation.play (animation); } ```

If there’s a chance the previous animation for the same target hasn’t yet finished, the previous animation should be stopped first, or the existing AdwAnimation object can be reused.

get_follow_enable_animations_setting()
Returns:

whether to follow the global setting

Return type:

bool

Gets whether self should be skipped when animations are globally disabled.

New in version 1.3.

get_state()
Returns:

the animation value

Return type:

Adw.AnimationState

Gets the current value of self.

The state indicates whether self is currently playing, paused, finished or hasn’t been started yet.

get_target()
Returns:

the animation target

Return type:

Adw.AnimationTarget

Gets the target self animates.

get_value()
Returns:

the current value

Return type:

float

Gets the current value of self.

get_widget()
Returns:

the animation widget

Return type:

Gtk.Widget

Gets the widget self was created for.

It provides the frame clock for the animation. It’s not strictly necessary for this widget to be same as the one being animated.

The widget must be mapped in order for the animation to work. If it’s not mapped, or if it gets unmapped during an ongoing animation, the animation will be automatically skipped.

pause()

Pauses a playing animation for self.

Does nothing if the current state of self isn’t ADW_ANIMATION_PLAYING.

Sets [property`Animation`:py:data::state<Adw.Animation.props.state>] to ADW_ANIMATION_PAUSED.

play()

Starts the animation for self.

If the animation is playing, paused or has been completed, restarts it from the beginning. This allows to easily play an animation regardless of whether it’s already playing or not.

Sets [property`Animation`:py:data::state<Adw.Animation.props.state>] to ADW_ANIMATION_PLAYING.

The animation will be automatically skipped if [property`Animation`:py:data::widget<Adw.Animation.props.widget>] is unmapped, or if [property`Gtk`.Settings:gtk-enable-animations] is FALSE.

As such, it’s not guaranteed that the animation will actually run. For example, when using [func`GLib`.idle_add] and starting an animation immediately afterwards, it’s entirely possible that the idle callback will run after the animation has already finished, and not while it’s playing.

reset()

Resets the animation for self.

Sets [property`Animation`:py:data::state<Adw.Animation.props.state>] to ADW_ANIMATION_IDLE.

resume()

Resumes a paused animation for self.

This function must only be used if the animation has been paused with [method`Animation`.pause].

Sets [property`Animation`:py:data::state<Adw.Animation.props.state>] to ADW_ANIMATION_PLAYING.

set_follow_enable_animations_setting(setting)
Parameters:

setting (bool) – whether to follow the global setting

Sets whether to skip self when animations are globally disabled.

The default behavior is to skip the animation. Set to FALSE to disable this behavior.

This can be useful for cases where animation is essential, like spinners, or in demo applications. Most other animations should keep it enabled.

See [property`Gtk`.Settings:gtk-enable-animations].

New in version 1.3.

set_target(target)
Parameters:

target (Adw.AnimationTarget) – an animation target

Sets the target self animates to target.

skip()

Skips the animation for self.

If the animation hasn’t been started yet, is playing, or is paused, instantly skips the animation to the end and causes [signal`Animation`:py:func:::done<Adw.Animation.signals.done>] to be emitted.

Sets [property`Animation`:py:data::state<Adw.Animation.props.state>] to ADW_ANIMATION_FINISHED.

Signal Details

Adw.Animation.signals.done(animation)
Signal Name:

done

Flags:

RUN_LAST

Parameters:

animation (Adw.Animation) – The object which received the signal

This signal is emitted when the animation has been completed, either on its own or via calling [method`Animation`.skip].

Property Details

Adw.Animation.props.follow_enable_animations_setting
Name:

follow-enable-animations-setting

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to skip the animation when animations are globally disabled.

The default behavior is to skip the animation. Set to FALSE to disable this behavior.

This can be useful for cases where animation is essential, like spinners, or in demo applications. Most other animations should keep it enabled.

See [property`Gtk`.Settings:gtk-enable-animations].

New in version 1.3.

Adw.Animation.props.state
Name:

state

Type:

Adw.AnimationState

Default Value:

Adw.AnimationState.IDLE

Flags:

READABLE

The animation state.

The state indicates whether the animation is currently playing, paused, finished or hasn’t been started yet.

Adw.Animation.props.target
Name:

target

Type:

Adw.AnimationTarget

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

The target to animate.

Adw.Animation.props.value
Name:

value

Type:

float

Default Value:

0.0

Flags:

READABLE

The current value of the animation.

Adw.Animation.props.widget
Name:

widget

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The animation widget.

It provides the frame clock for the animation. It’s not strictly necessary for this widget to be same as the one being animated.

The widget must be mapped in order for the animation to work. If it’s not mapped, or if it gets unmapped during an ongoing animation, the animation will be automatically skipped.