:right-sidebar: True Animation =================================================================== .. currentmodule:: gi.repository.Adw .. class:: Animation(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Adw.SpringAnimation`, :class:`~gi.repository.Adw.TimedAnimation` 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: :obj:`~gi.repository.Adw.TimedAnimation` and :obj:`~gi.repository.Adw.SpringAnimation`\. ``AdwAnimation`` will automatically skip the animation if :obj:`~gi.repository.Adw.Animation.props.widget` is unmapped, or if :obj:`~gi.repository.Gtk.Settings.props.gtk_enable_animations` is ``FALSE``\. The :obj:`~gi.repository.Adw.Animation.signals.done` signal can be used to perform an action after the animation ends, for example hiding a widget after animating its :obj:`~gi.repository.Gtk.Widget.props.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: .. code-block:: c :dedent: static void animation_cb (double value, MyObject *self) { // Do something with @value } static void my_object_animate (MyObject *self) { AdwAnimationTarget *target = adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb, self, NULL); g_autoptr (AdwAnimation) animation = adw_timed_animation_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. Methods ------- .. rst-class:: interim-class .. class:: Animation :no-index: .. method:: get_follow_enable_animations_setting() -> bool Gets whether ``self`` should be skipped when animations are globally disabled. .. versionadded:: 1.3 .. method:: get_state() -> ~gi.repository.Adw.AnimationState Gets the current value of ``self``\. The state indicates whether ``self`` is currently playing, paused, finished or hasn't been started yet. .. method:: get_target() -> ~gi.repository.Adw.AnimationTarget Gets the target ``self`` animates. .. method:: get_value() -> float Gets the current value of ``self``\. .. method:: get_widget() -> ~gi.repository.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. .. method:: pause() -> None Pauses a playing animation for ``self``\. Does nothing if the current state of ``self`` isn't ``ADW_ANIMATION_PLAYING``\. Sets :obj:`~gi.repository.Adw.Animation.props.state` to ``ADW_ANIMATION_PAUSED``\. .. method:: play() -> None 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 :obj:`~gi.repository.Adw.Animation.props.state` to ``ADW_ANIMATION_PLAYING``\. The animation will be automatically skipped if :obj:`~gi.repository.Adw.Animation.props.widget` is unmapped, or if :obj:`~gi.repository.Gtk.Settings.props.gtk_enable_animations` is ``FALSE``\. As such, it's not guaranteed that the animation will actually run. For example, when using :obj:`~gi.repository.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. .. method:: reset() -> None Resets the animation for ``self``\. Sets :obj:`~gi.repository.Adw.Animation.props.state` to ``ADW_ANIMATION_IDLE``\. .. method:: resume() -> None Resumes a paused animation for ``self``\. This function must only be used if the animation has been paused with :obj:`~gi.repository.Animation.pause`\. Sets :obj:`~gi.repository.Adw.Animation.props.state` to ``ADW_ANIMATION_PLAYING``\. .. method:: set_follow_enable_animations_setting(setting: bool) -> None 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 :obj:`~gi.repository.Gtk.Settings.props.gtk_enable_animations`\. .. versionadded:: 1.3 :param setting: whether to follow the global setting .. method:: set_target(target: ~gi.repository.Adw.AnimationTarget) -> None Sets the target ``self`` animates to ``target``\. :param target: an animation target .. method:: skip() -> None 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 :obj:`~gi.repository.Adw.Animation.signals.done` to be emitted. Sets :obj:`~gi.repository.Adw.Animation.props.state` to ``ADW_ANIMATION_FINISHED``\. Properties ---------- .. rst-class:: interim-class .. class:: Animation :no-index: .. attribute:: props.follow_enable_animations_setting :type: bool The type of the None singleton. .. versionadded:: 1.3 .. attribute:: props.state :type: ~gi.repository.Adw.AnimationState The type of the None singleton. .. attribute:: props.target :type: ~gi.repository.Adw.AnimationTarget The type of the None singleton. .. attribute:: props.value :type: float The type of the None singleton. .. attribute:: props.widget :type: ~gi.repository.Gtk.Widget The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: Animation.signals :no-index: .. method:: done() -> None The type of the None singleton. Fields ------ .. rst-class:: interim-class .. class:: Animation :no-index: .. attribute:: parent_instance