Animation package: handle animation with ease in PyMT

Animation package: handle animation with ease in PyMT

Animation

This is an Animation Framework, using which you can animate any property of an object over a provided duration. You can even animate CSS property.

Simple Animation

Example of a widget

widget = SomeWidget()
animobj = Animation(duration=5,x=100,
                    style={'bg-color':(1.0,1.0,1.0,1.0)})
widget.do (animobj)

You create a animation class object and pass the object into the widget that you would like to animate, the object will be animated from its current state to the state specified in the animation object.

You can also use animate() method of the Animation class to animate the widget

animobj.animate(widget)

You can also pass multiple widgets, to animate the same way

# solution 1
animobj.animate(widget1, widget2)

# solution 2
widget1.do(animobj)
widget2.do(animobj)

Complex Animations

You can sequence several animations together

anim1 = Animation(duration=1, x=100)
anim2 = Animation(duration=2, y = 200)
anim3 = Animation(duration=1, rotation = 60)

anim_xyrot = anim1 + anim2 + anim3

widget.do(anim_xyrot)

This is execute the animations sequentially, “+” is used to execute them sequentially. First the widget will move to x=100 in 1 sec then it will move to y=200 in secs and finally rotate clockwise 60 Degress in 1 sec.

You can also run several animations parallel

anim1 = Animation(duration=1, x=100)
anim2 = Animation(duration=2, y = 200)
anim3 = Animation(duration=1, rotation = 60)

anim_xyrot = anim1 & anim2 & anim3

widget.do(anim_xyrot)

This will execute all the animations on the properties togather. “&” operator is used to run them parallel

class pymt.ui.animation.AnimationAlpha

Bases: object

Collection of animation function, to be used with Animation object. Easing Functions ported into PyMT from Clutter Project http://www.clutter-project.org/docs/clutter/stable/ClutterAlpha.html

static ease_in_back(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_back

static ease_in_bounce(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_bounce

static ease_in_circ(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_circ

static ease_in_cubic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_cubic

static ease_in_elastic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_elastic

static ease_in_expo(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_expo

static ease_in_out_back(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_back

static ease_in_out_bounce(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_bounce

static ease_in_out_circ(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_circ

static ease_in_out_cubic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_cubic

static ease_in_out_elastic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_elastic

static ease_in_out_expo(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_expo

static ease_in_out_quad(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_quad

static ease_in_out_quart(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_quart

static ease_in_out_quint(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_quint

static ease_in_out_sine(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_out_sine

static ease_in_quad(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_quad

static ease_in_quart(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_quart

static ease_in_quint(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_quint

static ease_in_sine(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_in_sine

static ease_out_back(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_back

static ease_out_bounce(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_bounce

static ease_out_circ(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_circ

static ease_out_cubic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_cubic

static ease_out_elastic(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_elastic

static ease_out_expo(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_expo

static ease_out_quad(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_quad

static ease_out_quart(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_quart

static ease_out_quint(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_quint

static ease_out_sine(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#ease_out_sine

static linear(progress)

See documentation at http://pymt.eu/wiki/DevGuide/EasingFunctions#linear

class pymt.ui.animation.Animation(**kwargs)

Bases: pymt.event.EventDispatcher

Animation Class is used to animate any widget. You pass duration of animation and the property that has to be animated in that duration.

Usage

widget = SomeWidget()
animobj = Animation(duration=5, x=100,
                    style={'bg-color':(1.0,1.0,1.0,1.0)})
widget.do(animobj)
Parameters :
duration or d: float, default to 1

Number of seconds you want the animation to execute.

generate_event : bool, default to True

Generate on_animation_complete event at the end of the animation

type : str, default to absolute

Specifies what type of animation we are defining, Absolute or Delta

alpha_function or f: str, default to AnimationAlpha.linear

Specifies which kind of time variation function to use

Events :
on_start

Fired when animation starts

on_complete

Fired when animation completes

animate(*largs)

Animate the widgets specified as parameters to this method.

Parameters :
widget : Widget

A Widget or a group of widgets separated by comma “,”

reset(widget)

Calls AnimationBase objects reset function.

set_widget(widgetx)

Creates a new animationBase object and sets the widget to it for animation. This is a internal function and should not be used by user.

Parameters :
widget : MTWidget, default is None

Indicates which widget is to be set.

start(widget)

Starts animating the widget. This function should not be used by the user directly. Users have to use do() method of the widget to animate.

stop(widget)

Stops animating the widget and raises a event.

class pymt.ui.animation.Repeat(animation, **kwargs)

Bases: pymt.event.EventDispatcher

Repeat Controller class is used to repeat a particular animations. It repeats n times as specified or repeats indefinately if number of times to repeat is not specified. Repeat class is useful only for delta animations.

Usage

widget = SomeWidget()
animobj = Animation(duration=5, x=100,
                    style={'bg-color':(1.0,1.0,1.0,1.0)})
rept = Repeat(animobj, times=5) #Repeats 5 times
rept_n = Repeat(animobj) #Repeats indefinately
Parameters :
times : integer, default to infinity

Number of times to repeat the Animation

Events :
on_start

Fired when animation starts

on_complete

Fired when animation completes

on_repeat

Fired on every repetition. It also returns what is the current repetition count.

repeat(widget)

Internal function used by the Repeat controller to check for repetitions

set_widget(widgetx)

Called by the widget to set the widget which has to be animated

start(widget)

Starts the animation

stop(widget)

Stops the animation

class pymt.ui.animation.Delay(**kwargs)

Bases: pymt.ui.animation.Animation

Delay class is used to introduce delay in your animations. You can provide the duration in your animation class creation

Usage

widget = SomeWidget()
moveX = Animation(duration=5, x=100,
                  style={'bg-color':(1.0,1.0,1.0,1.0)})
delay5 = Delay(duration=5)
animobj = delay5 + moveX
# This will wait for 5 secs and then start animating moveX
Parameters :
duration : float, default to 1

Number of seconds you want delay.

Table Of Contents

Previous topic

Window package: provide a window + a touch display

Next topic

Colors: css & themes

This Page