Basic Usage¶
Clutter¶
In Clutter we work in a Stage where we would put a number of Actors. The typical Hello World example would be:
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
from gi.repository import Clutter
import sys
if __name__ == '__main__':
Clutter.init( sys.argv )
# Create Stage
_stage = Clutter.Stage()
_stage.set_title( "Basic Usage" )
_stage.set_size( 400, 200 )
# Create Actor
_red = Clutter.Color().new(255, 0, 0, 255) # R,G,B,alpha
_actor = Clutter.Text().new_full(
"Mono 10",
"Hello World!",
_red )
_actor.set_position( 100,100 )
# Add Actor to the Stage
_stage.add_actor( _actor )
_stage.connect("destroy", lambda w: Clutter.main_quit() )
_stage.show_all()
Clutter.main()
where:
- Clutter is initialized.
- A Stage is created.
- An actor is created (just some formatted text) and its position is set.
- The actor is added to the stage.
- The signal “destroy” in the stage is connected to a function
being the result:
Mx¶
Mx is a toolbox based on Clutter. We could say it creates a number of actor that can be used in a Clutter stage:
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
from gi.repository import Clutter, Mx
import sys
if __name__ == '__main__':
Clutter.init( sys.argv )
# Create Stage
_stage = Clutter.Stage()
_stage.set_title( "Basic Usage" )
_stage.set_size( 400, 200 )
# Create Actor
_label = Mx.Label()
_label.set_text("Hello world")
# Add Actor to the Stage
_stage.add_actor( _label )
_stage.connect("destroy", lambda w: Clutter.main_quit() )
_stage.show_all()
Clutter.main()
where:
- Clutter is initialized.
- A Stage is created.
- An actor (a label from the Mx toolkit) is created.
- The actor is added to the stage.
- The signal “destroy” in the stage is connected to a function
being the result: