Clutter Timeline

#!/usr/bin/env python
#
# [SNIPPET_NAME: Clutter Timeline]
# [SNIPPET_CATEGORIES: Clutter]
# [SNIPPET_DESCRIPTION: Creates two timelines and adds them to the Clutter Score at certain points in the timeline]
# [SNIPPET_AUTHOR: Andy Breiner <[email protected]>]
# [SNIPPET_LICENSE: GPL]
# [SNIPPET_DOCS: http://otherwiseingle.blogspot.com/2010/02/pyclutter-recipes.html, http://clutter-project.org/docs/pyclutter/stable/]


import clutter
from clutter import cogl

class ClutterTimeline:
    def __init__ (self):
        # Create stage and set its properties.
        self.stage = clutter.Stage()
        self.stage.set_color(clutter.color_from_string('Black'))
        self.stage.set_size(500, 500)
        self.stage.set_title('Clutter Timeline')
        self.stage.connect("destroy",clutter.main_quit)

        # Creates a rectangle and its properties
        rrect = clutter.Rectangle()
        rrect.set_color(clutter.color_from_string("#FF000090"))
        rrect.set_size(50, 50)
        rrect.set_position(100, 100)
    
        # Sets the duration of the timeline
        rtimeline = clutter.Timeline(10000)

        # This is used to calculate how much time has passed on
        # the timeline
        ralpha = clutter.Alpha(rtimeline,clutter.LINEAR)

        # This creates an animation that will be executed over the current
        # timeline and applies it to the actor
        rbehaviour = clutter.BehaviourRotate(clutter.Z_AXIS, 0.0, 360.0, alpha = ralpha)
        rbehaviour.apply(rrect)

        # Repeat the timeline
        rtimeline.set_loop(True)
        self.stage.add(rrect)

        # Does the same as above
        brect = clutter.Rectangle()
        brect.set_color(clutter.color_from_string("#0000FF90"))
        brect.set_size(100, 100)
        brect.set_position(150, 150)
        btimeline = clutter.Timeline(5000)
        balpha = clutter.Alpha(btimeline,clutter.LINEAR)
        bbehaviour = clutter.BehaviourRotate(clutter.Z_AXIS, 0.0, 360.0, alpha = balpha)
        bbehaviour.apply(brect)
        self.stage.add(brect)

        # Creates a score that allows you to add timelines
        # You can start, stop or pause your timeline
        s = clutter.Score()
        s.append(rtimeline)

        # Create a markers and labels it "go_blue"
        rtimeline.add_marker_at_time("go_blue", 2000)
        # In the red rectangle's timeline at marker "go_blue" it needs to
        # start the blue rectangle's timeline
        s.append_at_marker(rtimeline, "go_blue", btimeline)
        s.start()

        self.stage.show_all()
        clutter.main()

if __name__ == '__main__':
    main = ClutterTimeline()