Chapter 3. The Stage

Table of Contents

Stage Basics

Each PyClutter application contains at least one clutter.Stage. This stage contains Actors such as rectangles, images, or text. We will talk more about the actors in the next chapter, but for now let's see how a stage can be created and how we can respond to user interaction with the stage itself.

First make sure that you have imported the clutter module. You may then get the application's stage with clutter.Stage(). This always returns the same instance, with its own window. You could instead use a cluttergtk.Embed widget inside a more complicated GTK+ window - see the Stage Widget section.

clutter.Stage is derived from the clutter.Actor object so many of that object's functions are useful for the stage. For instance, call stage.show() to make the stage visible.

clutter.Stage also implements the clutter.Container interface, allowing it to contain child actors via calls to container.add().

Call clutter.main() to start a main loop so that the stage can animate its contents and respond to user interaction.

Reference

Example

The following example shows a clutter.Stage and handles clicks on the stage. There are no actors yet so all you will see is a black rectangle.

Figure 3.1. Stage

Stage

Source Code

File: main.py

import sys

import clutter

def on_stage_button_press(stage, event):
    print "Stage clicked at (%f, %f)" % (event.x, event.y)


def main():
    stage = clutter.Stage()

    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(clutter.Color(0, 0, 0, 255))

    stage.connect('button-press-event', on_stage_button_press)
    stage.connect("destroy", clutter.main_quit)
    stage.show()

    clutter.main()

    return 0

if __name__ == '__main__':
    sys.exit(main())