<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zeta-Puppis.com &#187; clutter</title>
	<atom:link href="http://zeta-puppis.com/category/clutter/feed/" rel="self" type="application/rss+xml" />
	<link>http://zeta-puppis.com</link>
	<description>my very own personal corner</description>
	<lastBuildDate>Sat, 18 Feb 2012 12:53:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>An introduction to pyclutter (part three)</title>
		<link>http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-introduction-to-pyclutter-part-three</link>
		<comments>http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 20:32:14 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[clutter]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[pyclutter]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/</guid>
		<description><![CDATA[<a href="http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/" title="An introduction to pyclutter (part three)"></a>This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&#160;old. Last time we have seen how to draw the (maybe) most basic shape of clutter: the rectangles. We also positioned them together in the stage, &#8230;<p class="read-more"><a href="http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/" title="An introduction to pyclutter (part three)"></a><p><strong style="color: red;">This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&nbsp;old.</strong></p>
<p>Last time we have seen how to draw the (maybe) most basic shape of clutter: the rectangles. We also positioned them together in the stage, and said (in part one) that the stage is a special kind of&nbsp;<strong>container</strong>.</p>
<p>Today it&#8217;s time to explain better what groups are and how to use them, so I&#8217;ll introduce to you the <strong>ClutterGroup</strong> and the&nbsp;<strong>ClutterHBox/ClutterVBox</strong>.</p>
<p><span id="more-59"></span></p>
<p>In the first part of this tutorial we said that the stage is a top level &#8220;window&#8221; on which child actors are placed and manipulated. That&#8217;s correct, but we also said that a stage is a special kind of container. Container, but it is self explanatory, contains objects: in the clutter&#8217;s case, these <strong>objects can be other containers or&nbsp;actors</strong>.</p>
<p>If you have some experience with GTK, you know that GTK uses HBox and VBox for placing the widgets respectively horizontally and vertically. Clutter has the same concept with ClutterHBox and ClutterVBox but, since clutter uses 3D effects, we also have <strong>a depth dimension</strong>, and we must be able to handle it in some way. Here comes the ClutterGroup: it contains objects exactly like HBox/VBox, but they&#8217;re not added sequentially horizontally or vertically, they&#8217;re added one up the other. Additionally, with ClutterGroups, we can use the relative positioning (we&#8217;ll see how&nbsp;later).</p>
<p>But before to talk about groups, it&#8217;s better to talk about HBox/VBox. I already said that HBox or VBox are used to place actors (or even other containers) sequentially. That said, if we add a label to a HBox and then we add a rectangle, the label and the rectangle will be placed <strong>sequentially</strong> starting from&nbsp;left.</p>
<p>Maybe it&#8217;s better to see this behaviour directly in&nbsp;action:</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(420, 200)
    stage.set_color(clutter.color_parse("#FFF"))

    hbox = clutter.HBox()
    hbox.set_position(10, 10)
    rect_h1 = clutter.Rectangle()
    rect_h1.set_size(200, 50)
    rect_h1.set_color(clutter.color_parse("#FF0000"))
    rect_h2 = clutter.Rectangle()
    rect_h2.set_size(200, 50)
    rect_h2.set_color(clutter.color_parse("#800000"))
    rect_h2.set_border_width(1)
    rect_h2.set_border_color(clutter.color_parse("#000000"))

    vbox = clutter.VBox()
    vbox.set_position(10, 80)
    rect_v1 = clutter.Rectangle()
    rect_v1.set_size(200, 50)
    rect_v1.set_color(clutter.color_parse("#00FF00"))
    rect_v2 = clutter.Rectangle()
    rect_v2.set_size(200, 50)
    rect_v2.set_color(clutter.color_parse("#008000"))
    rect_v2.set_border_width(1)
    rect_v2.set_border_color(clutter.color_parse("#000000"))

    rect_h1.show()
    rect_h2.show()
    rect_v1.show()
    rect_v2.show()
    hbox.add(rect_h1, rect_h2)
    vbox.add(rect_v1, rect_v2)
    stage.add(hbox, vbox)

    hbox.show_all()
    vbox.show_all()
    stage.show_all()

    stage.connect("key-press-event", clutter.main_quit)
    clutter.main()

if __name__ == '__main__':
    main()
</code></pre>
<p>The above code will produce&nbsp;this:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/10/example05-hvbox.jpg' title='Example 05: HBox and VBoxes'><img src='http://zeta-puppis.com/wp-content/uploads/2007/10/example05-hvbox.thumbnail.jpg' alt='Example 05: HBox and VBoxes' /></a></p>
<p>You may ask yourself why we use multiple <code>show()</code> instead of having a single <code>show_all()</code> on the stage. The reason is that <code>show_all()</code> <strong>doesn&#8217;t recurse inside a Group</strong> because you might be hiding some of the actors inside that group for a later use. Anyway, it&#8217;s possible to subclass a <code>clutter.Group</code> and override the <code>show_all()</code> method so it recurse inside all its children, but that&#8217;s a bit more advanced topic that I hope I&#8217;ll be able to cover in another part of the&nbsp;tutorial.</p>
<p>As you can see, the rectangles have been placed sequentially in horizontal (for the HBox) or vertical (for the VBox) direction. In this way we can build a basic interface, since we can have <strong>nested boxes</strong>, that said HBoxes that contains other HBoxes or VBoxes (this is true for VBox too,&nbsp;obviously):</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(420, 200)
    stage.set_color(clutter.color_parse("#FFF"))

    hbox = clutter.HBox()
    hbox.set_position(10, 10)
    rect_h1 = clutter.Rectangle()
    rect_h1.set_size(200, 50)
    rect_h1.set_color(clutter.color_parse("#FF0000"))

    vbox = clutter.VBox()
    vbox.set_position(10, 80)
    rect_v1 = clutter.Rectangle()
    rect_v1.set_size(200, 50)
    rect_v1.set_color(clutter.color_parse("#00FF00"))
    rect_v2 = clutter.Rectangle()
    rect_v2.set_size(200, 50)
    rect_v2.set_color(clutter.color_parse("#008000"))
    rect_v2.set_border_width(1)
    rect_v2.set_border_color(clutter.color_parse("#000000"))

    rect_h1.show()
    rect_v1.show()
    rect_v2.show()
    vbox.add(rect_v1, rect_v2)
    hbox.add(rect_h1, vbox)
    stage.add(hbox)

    hbox.show_all()
    vbox.show_all()
    stage.show_all()

    stage.connect("key-press-event", clutter.main_quit)
    clutter.main()

if __name__ == '__main__':
    main()
</code></pre>
<p>It works in this&nbsp;way:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/10/example06-hvbox-nested.jpg' title='Example 06: nested HBox and VBoxes'><img src='http://zeta-puppis.com/wp-content/uploads/2007/10/example06-hvbox-nested.thumbnail.jpg' alt='Example 06: nested HBox and VBoxes' /></a></p>
<p>Let do a step back: we introduced the set_position method previously, but we didn&#8217;t explained extensively how this method works. The set_position set the specified actor&#8217;s position to the coordinates <strong>relatives to its father container</strong>. So, if we don&#8217;t have any container it reverts to the stage, that is the father of all the childs in a window (and we have absolute positioning), otherwise it will set the actor&#8217;s position to the first father it finds. Let see this scheme to clarify a&nbsp;bit:</p>
<p><img src='http://zeta-puppis.com/wp-content/uploads/2007/10/relative_scheme.png' alt='A scheme illusrtating the relative and absolute positionment' /></p>
<p>Groups shares most of the properties of HBox and VBox, but instead of placing the elements horizontally or vertically, it positions them on the z-axis (it put the actors <strong>one up the other</strong>). In this way we can also have a container that help us in achieving the relative&nbsp;positioning:</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(500, 500)
    stage.set_color(clutter.color_parse("#FFF"))

    rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), clutter.Rectangle()
    group1, group2, group3 = clutter.Group(), clutter.Group(), clutter.Group()

    group1.add(rect1, group2)
    group2.add(rect2, group3)
    group3.add(rect3)

    group1.set_position(100, 100)
    group2.set_position(100, 100)
    group3.set_position(100, 100)

    rect1.set_position(0, 0)
    rect2.set_position(0, 0)
    rect3.set_position(0, 0)

    rect1.set_size(150, 150)
    rect2.set_size(150, 150)
    rect3.set_size(150, 150)

    rect1.set_color(clutter.color_parse("#FF000090"))
    rect2.set_color(clutter.color_parse("#00FF0090"))
    rect3.set_color(clutter.color_parse("#0000FF90"))

    stage.add(group1)

    stage.show_all()
    group1.show_all()
    group2.show_all()
    group3.show_all()

    stage.connect("key-press-event", clutter.main_quit)
    clutter.main()

if __name__ == '__main__':
    main()</code></pre>
<p>With the above code, we&#8217;ll position each group <strong>relatively to its father</strong>. Only the first group will have the stage as father, all the others are relative positioned to the previous&nbsp;stage.</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/10/example07-groups.jpg' title='Example 07: groups'><img src='http://zeta-puppis.com/wp-content/uploads/2007/10/example07-groups.thumbnail.jpg' alt='Example 07: groups' /></a></p>
<p>That&#8217;s all for today&nbsp;:)</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2007/10/22/an-introduction-to-pyclutter-part-three/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>An introduction to pyclutter (part two)</title>
		<link>http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-introduction-to-pyclutter-part-two</link>
		<comments>http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 20:48:33 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[clutter]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[pyclutter]]></category>
		<category><![CDATA[pygtk]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/</guid>
		<description><![CDATA[<a href="http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/" title="An introduction to pyclutter (part two)"></a>This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&#160;old. Last time we learned how to have our first stage drawn, so now it&#8217;s time to begin to insert something into that&#160;stage. Let do a &#8230;<p class="read-more"><a href="http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/" title="An introduction to pyclutter (part two)"></a><p><strong style="color: red;">This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&nbsp;old.</strong></p>
<p>Last time we learned how to have our first stage drawn, so now it&#8217;s time to begin to <strong>insert something into that&nbsp;stage</strong>.</p>
<p>Let do a summary of what we are going to do in this&nbsp;&#8220;lesson&#8221;:</p>
<ul>
<li>change the stage&#8217;s&nbsp;color</li>
<li>add a rectangle to the&nbsp;stage</li>
<li>add another rectangle to the&nbsp;stage</li>
</ul>
<p><span id="more-55"></span></p>
<p>The first thing we want to do is to <strong>change the stage&#8217;s color</strong>. This can be done by using the <code>set_color()</code> method of the stage&nbsp;object:</p>
<pre><code>    stage.set_color(clutter.color_parse("#00000"))</code></pre>
<p>In this way we have a black stage. But how does it works? The <code>set_color()</code> method <strong>needs a ClutterColor object in input</strong>, and we can have it by calling the <code>color_parse()</code> function. The <code>color_parse()</code> has the same syntax of <code>pango_color_parse()</code> (a built-in GTK function), so it accepts both hexadecimal specifications of the color (i.e.: #000000 or #000 for black, #FF0000 or #F00 for red) and literal color values like &#8220;black&#8221; or &#8220;red&#8221;. Additionally, <strong>we can specify a pixel alpha value</strong> (the object&#8217;s <em>opacity</em> level) by using a hexadecimal specification like #000000FF, where FF is the alpha value. We can specify an alpha value for the stage but it won&#8217;t work since <strong>the stage hasn&#8217;t a alpha&nbsp;layer</strong>.</p>
<p>After this, our window will look like&nbsp;this:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/09/example02-stage-color.jpg' title='Example 02: a newly created stage with a specified color'><img src='http://zeta-puppis.com/wp-content/uploads/2007/09/example02-stage-color.thumbnail.jpg' alt='Example 02: a newly created stage with a specified color' /></a></p>
<p>Note that now the window became black as we specified. Now that we completed the first goal, it&#8217;s time for us to introduce a new clutter object: <strong>the&nbsp;rectangle</strong>.</p>
<p>A rectangle is made up by <strong>the rectangle itself and a border</strong>. That said, if we tell clutter to draw a 100x100px rectangle with a 2px border, the resulting rectangle will be 2px + 100px + 2px&nbsp;large.</p>
<p>Now that we had enough theory, we can begin to draw our first&nbsp;rectangle:</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(500, 500)
    stage.set_color(clutter.color_parse("#000000"))

    rect = clutter.Rectangle()
    rect.set_position(20, 20)
    rect.set_size(200, 300)
    rect.set_color(clutter.color_parse("#A02020"))

    stage.add(rect)

    rect.show()
    stage.show()

    stage.connect("key-press-event", clutter.main_quit)
    clutter.main()

if __name__ == '__main__':
    main()
</code></pre>
<p>This code will give us this&nbsp;output:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/09/example03-rectangle.jpg' title='Example 03: a window with a red rectangle'><img src='http://zeta-puppis.com/wp-content/uploads/2007/09/example03-rectangle.thumbnail.jpg' alt='Example 03: a window with a red rectangle' /></a></p>
<p>And now it&#8217;s time to analyze what we done by looking at the code line per line (I&#8217;ll skip the lines that we already&nbsp;seen):</p>
<pre><code>    rect = clutter.Rectangle()</code></pre>
<p>In order to draw a rectangle we need an instance of the rectangle object, right? We can get this instance by calling the <code>Rectangle</code> constructor&nbsp;function.</p>
<p>Once we have our rectangle instance, we can make operations like positioning and coloring on&nbsp;it:</p>
<pre><code>    rect.set_position(20, 20)
    rect.set_size(200, 300)
    rect.set_color(clutter.color_parse("#A02020"))</code></pre>
<p>The first line moves the upper left corner of the rectangle at position (20, 20) in the stage. The second and the third line, instead, are functions that we have already seen: both the rectangle&#8217;<code>set_size()</code> and <code>set_color()</code> functions works exactly as the stage&#8217;s one (we&#8217;ll see further in another part of this tutorial why the name and the implementation is the same). Indeed, in this way <strong>we can specify both a size and a color</strong> for our&nbsp;rectangle.</p>
<pre><code>    stage.add(rect)</code></pre>
<p>We <strong>drawn our rectangle</strong>, but now we need to tell clutter <em>where</em> to put it: this is done by using the <code>add()</code> method of the stage object (if this operation looks useless to you it&#8217;s because we still didn&#8217;t talked about Groups and Box; we&#8217;ll do that another time, now just take this line <em>as&nbsp;is</em>).</p>
<p>The last line of interest is this&nbsp;one:</p>
<pre><code>    rect.show()</code></pre>
<p>We&#8217;ve already explained in the previous part how the <code>show()</code> method works for the stage: here&#8217;s is exactly the same&nbsp;thing.</p>
<p>Now that we have our first rectangle, is time to <strong>draw the second&nbsp;one</strong>:</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(500, 500)
    stage.set_color(clutter.color_parse("#000000"))

    rect1 = clutter.Rectangle()
    rect2 = clutter.Rectangle()

    rect1.set_position(20, 20)
    rect1.set_size(200, 300)
    rect1.set_color(clutter.color_parse("#A02020"))

    rect2.set_position(50, 100)
    rect2.set_size(350, 300)
    rect2.set_color(clutter.color_parse("#FFFFFF50"))
    rect2.set_border_width(20)
    rect2.set_border_color(clutter.color_parse("blue"))

    stage.add(rect1, rect2)

    rect1.show()
    rect2.show()
    stage.show()

    stage.connect("key-press-event", clutter.main_quit)
    clutter.main()

if __name__ == '__main__':
    main()
</code></pre>
<p>We&#8217;ll obtain&nbsp;this:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/09/example04-two-rectangles.jpg' title='Example 04: two rectangles'><img src='http://zeta-puppis.com/wp-content/uploads/2007/09/example04-two-rectangles.thumbnail.jpg' alt='Example 04: two rectangles' /></a></p>
<p><em>(if you see the second rectangle&#8217;s border partially drawn, or not drawn at all, you are probably using a version of clutter older than 0.4.2, where a bug in the border generation deny you from having the rectangle shown&nbsp;correctly)</em></p>
<p>We&#8217;ve already discussed many of the functions in the code above, so I&#8217;ll quickly jump to the more complex part. First of all, let do a resume of what we do in this&nbsp;script:</p>
<ol>
<li>we create the <strong>first</strong> rectangle named&nbsp;<code>rect1</code></li>
<li>we create the <strong>second</strong> rectangle named&nbsp;<code>rect2</code></li>
<li>we <strong>set up properties</strong> for both rectangles (please note that for the second rectangle we specified a pixel alpha value&nbsp;too)</li>
<li>then we <strong>add the rectangle to the stage</strong> and show&nbsp;them</li>
</ol>
<p>The only thing I should explain is the point number four: the <code>add</code> method of a container (a stage, in this case), can have <strong>multiple arguments</strong>. Indeed, we can tell clutter to add multiple elements to a container. So in our example, we added both <code>rect1</code> and <code>rect2</code> in a single line of code instead of having two separate <code>add</code>&nbsp;statements.</p>
<p>After having the actors added to the stage, we show them by calling the <code>show()</code> method on every single actor. This approach works, but sometimes could be more useful (and time saving) to call a special <code>show</code> method on the parent. We&#8217;ll discuss this behaviour better when we&#8217;ll talk about groups, but by now on I&#8217;ll use the <code>show_all()</code> method on the stage in order to <strong>show all its children in one line of&nbsp;code</strong>.</p>
<p>See you for the next part of this tutorial&nbsp;:)</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2007/09/30/an-introduction-to-pyclutter-part-two/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>An introduction to pyclutter (part one)</title>
		<link>http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-introduction-to-pyclutter-part-one</link>
		<comments>http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 12:04:13 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[clutter]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[pyclutter]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/</guid>
		<description><![CDATA[<a href="http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/" title="An introduction to pyclutter (part one)"></a>This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&#160;old. This tutorial is the first of a series that will try to learn to you how to use clutter with the help of python, or &#8230;<p class="read-more"><a href="http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/" title="An introduction to pyclutter (part one)"></a><p><strong style="color: red;">This tutorial is outdated: it refers to version 0.4 of clutter that now is VERY&nbsp;old.</strong></p>
<p>This tutorial is the first of a series that will try to learn to you how to use <a href="http://clutter-project.org">clutter</a> with the help of python, or better: <strong>a tutorial about&nbsp;pyclutter</strong>.</p>
<p>But before to begin, it&#8217;s better to give an overview on what clutter is. Citing the clutter&#8217;s&nbsp;homepage:</p>
<p><quote>Clutter is an open source software library for creating fast, visually rich and animated graphical user interfaces. Clutter uses OpenGL (and optionally OpenGL ES) for rendering but with an API which hides the underlying GL complexity from the developer. The Clutter API is intended to be easy to use, efficient and flexible.</quote></p>
<p>That said, while clutter is the main library (written in C), there are bindings to other languages like perl, vala, ruby, C# and python. The python binding is commonly named&nbsp;<strong>pyclutter</strong>.</p>
<p>The requirements needed to better follow the tutorial&nbsp;are:</p>
<ul>
<li>a <strong>good python knowledge</strong> (of course); if you don&#8217;t know it, you can always learn it by following the excellent <a href="http://diveintopython.org">dive into&nbsp;python</a></li>
<li>some <strong>basic knowledge of how the GTK environment works</strong>; although it isn&#8217;t really needed since we won&#8217;t use GTK functions, it is very useful since, under a certain point of view, clutter inherits many things from&nbsp;GTK</li>
<li><strong>clutter 0.4.2</strong> or&nbsp;newer</li>
</ul>
<p><span id="more-53"></span></p>
<p>In clutter we have mainly two kind of objects: <strong>actors</strong> and <strong>containers</strong>. Stages, additionally, are a special kind of container. We can see the clutter actors like the GTK widgets and the stages like the GTK windows. A stage, as the documentation says, is a top level &#8220;window&#8221; on which child actors are placed and&nbsp;manipulated.</p>
<p>Let see the stage <strong>as our workspace</strong>: in it we will place all the objects as we do with a GTK Window. So, let build our first clutter&nbsp;window:</p>
<pre><code>import clutter

def main():
    stage = clutter.stage_get_default()
    stage.set_size(500, 500)
    stage.show()
    stage.connect("key-press-event", clutter.main_quit)

    clutter.main()

if __name__ == '__main__':
    main()</code></pre>
<p>The above code will produce&nbsp;this:</p>
<p><a href='http://zeta-puppis.com/wp-content/uploads/2007/09/example01-stage.jpg' title='An example of stage'><img src='http://zeta-puppis.com/wp-content/uploads/2007/09/example01-stage.thumbnail.jpg' alt='An example of stage' /></a></p>
<p>Well, that&#8217;s our first window :)<br />
Now let analyze every single line of the&nbsp;script:</p>
<pre><code>import clutter</code></pre>
<p>The line above is, probably, the most important one in the script because without that line nothing will run. If you know Python you&#8217;ll already know what that line does, but if you&#8217;re a python newbie you need to understand that the import statement <strong>import the specified namespace into the current script</strong>. That said, with that line, we can use&nbsp;clutter.</p>
<p>Let jump the <code>main()</code> for a while and let go&nbsp;to:</p>
<pre><code>if __name__ == '__main__':
    main()</code></pre>
<p>Apart from the main() call that is pretty obvious, the line that could create some problem is the one with the <code>if</code> statement. What it does is to call the <code>main()</code> only if <code>__name__</code> is equal to <code>__main__</code>. So the question is: &#8220;when __name__ is &#8216;__main__&#8217;&#8221;? Every module has a built-in attribute <code>__name__</code>, but it assumes the value <code>__main__</code> <strong>only when you execute that script</strong>: if the script is imported, instead, it will contain the module&#8217;s&nbsp;name.</p>
<p>Now jump into the&nbsp;<code>main()</code>:</p>
<pre><code>    stage = clutter.stage_get_default()</code></pre>
<p>It&#8217;s better to spend some more time over the <code>stage_get_default()</code> method. We said that a stage is like a GTK window, but we didn&#8217;t created any window or stage because we don&#8217;t need to do so since clutter does it for us when we call <code>clutter.main()</code>. So <strong>we need a pointer to the newly created stage</strong>, and this pointer is a <code>ClutterStage</code> object that we can retrieve calling&nbsp;<code>clutter.stage_get_default()</code>.</p>
<p>Now that we have a reference to our stage and we have initialized everything, we can begin to set properties on our&nbsp;stage/window:</p>
<pre><code>    stage.set_size(500, 500)</code></pre>
<p>With the <code>set_size</code> method, we say that our stage should be 500x500px big. Pay attention that we <strong>specify the stage dimensions</strong>, that doesn&#8217;t includes the width and height of the decorators that the window manager adds (like the title bar). Then we&nbsp;have:</p>
<pre><code>    stage.show()</code></pre>
<p>We call the <code>show()</code> method of the stage object because, by default, visual object like containers and actors are hidden and we have explicitly tell clutter to show them by using the actor&#8217;s <code>show()</code> method. If we don&#8217;t call this method we won&#8217;t see&nbsp;anything.</p>
<pre><code>    stage.connect("key-press-event", clutter.main_quit)</code></pre>
<p>Pay attention to the above line. With that line we say to clutter to quit when some key on the keyboard is pressed. That said, we <strong>connected an &#8220;event&#8221; to a &#8220;callback function&#8221;</strong> where, in this case, the event is <code>key-press-event</code> (that indicates that a key has been pressed) and the callback is <code>clutter.main_quit</code> (without parenthesis because we are NOT calling it but, instead, we&#8217;re just giving it&#8217;s address so it can be called later by the clutter event handler). The <code>clutter.main_quit()</code> function is the function that clutter uses to stop the program&#8217;s execution and,&nbsp;with</p>
<pre><code>    clutter.main()</code></pre>
<p>starts and stop the program flow (<code>clutter.main()</code>, as the name says, is the function that <em>starts</em> the&nbsp;program).</p>
<p>We did our first clutter program, and I think is enough for now. So let see you on the part two of this tutorial where I&#8217;ll begin to explain how to begin to insert something into our&nbsp;stage.</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2007/09/23/an-introduction-to-pyclutter-part-one/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

