<?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; gtk</title>
	<atom:link href="http://zeta-puppis.com/category/gtk/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 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>
		<item>
		<title>When you&#8217;re a collector (and a programmer)</title>
		<link>http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=when-youre-a-collector-and-a-programmer</link>
		<comments>http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 14:28:36 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Geekness]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/</guid>
		<description><![CDATA[<a href="http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/" title="When you&#039;re a collector (and a programmer)"></a>As above, when you&#8217;re both a collector and a programmer, strange things could happen. I&#8217;m a beer coaster collector and my collection now reached 250+ unique items so it became a bit a mess to keep that well&#160;organized. So that&#8217;s &#8230;<p class="read-more"><a href="http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/" title="When you&#039;re a collector (and a programmer)"></a><p>As above, when you&#8217;re both a collector and a programmer, strange things could happen. I&#8217;m a <strong>beer coaster</strong> collector and my collection now reached 250+ unique items so it became a bit a mess to keep that well&nbsp;organized.</p>
<p>So that&#8217;s why a developed <strong>BeerCoaster manager</strong>. Yes, I done a program that help me to keep my collection organized. It is still a bit rudimentary but does  its job pretty well. So, if you&#8217;re a beer coaster collector like me, you&#8217;ll found this&nbsp;useful.</p>
<p>It&#8217;s written in Python and uses sqlite as database to store it&#8217;s informations, so <strong>it is portable</strong> across various platforms (i.e.: you can copy &amp; paste your files from Linux to Windows and it will keep&nbsp;working).</p>
<p>Currently, it can be downloaded only by SVN and it <strong>is everything but stable</strong>. I hope to release something good within the end of&nbsp;year.</p>
<p>The project homepage is hosted on Google project:&nbsp;<a href="http://bcmanager.googlecode.com/">http://bcmanager.googlecode.com/</a></p>
<p>Getting it working under Windows, currently, is really hard: for the final releases, though, I should provide a <strong>Windows&nbsp;installer</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2007/09/14/when-youre-a-collector-and-a-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inserting images in a TreeView/ListView</title>
		<link>http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inserting-images-in-a-treeviewlistview</link>
		<comments>http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 14:27:34 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/</guid>
		<description><![CDATA[<a href="http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/" title="Inserting images in a TreeView/ListView"></a>I already know that this post will be useful just to me, because I know that someday I&#8217;ll forgot how to do this and I&#8217;ll be looking for a solution. So here&#8217;s how to insert an image in a TreeView &#8230;<p class="read-more"><a href="http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/" title="Inserting images in a TreeView/ListView"></a><p>I already know that this post will be useful just to me, because I know that someday I&#8217;ll forgot how to do this and I&#8217;ll be looking for a solution. So here&#8217;s how to <strong>insert an image in a <strike>TreeView</strike> ListView</strong> using&nbsp;python.</p>
<p>Technically, <strong>a ListView widget doesn&#8217;t exists</strong>, but it is a TreeView with a ListStore model associated in place of a TreeModel. And this &#8220;howto&#8221; uses a ListView as example as it is easier to set up, but the concept remains the same for all the kind of&nbsp;TreeViews.</p>
<p><span id="more-51"></span></p>
<p>First thing: a TreeView (ehm, ListView) in gtk is made up by TreeViewColumns and CellRendererers of various type, according to what you want to display. But the first thing to do is to <strong>import the needed pygtk&#8217;s&nbsp;modules</strong>.</p>
<pre><code>import pygtk
pygtk.require("2.0")
import gtk
import gobject</code></pre>
<p>Then we must <strong>set up a model</strong> for our ListView and associate it to the newly created TreeView object, before than building it with&nbsp;columns:</p>
<pre><code>treeview = gtk.TreeView()
model = gtk.ListStore(
    gobject.TYPE_STRING, # a column will contain a string
    gtk.gdk.Pixbuf) # and another column will contain our image

treeview.set_model(model)</code></pre>
<p>After we done this, we must <strong>create the columns</strong> and the <strong>cells</strong>. A cell, under the gtk point of view, is every single place in the TreeView where a value can be inserted, that is every intersection of a row with a column. While the column are created using nearly always the same funtion (<code>gtk.TreeViewColumn()</code>), the cells aren&#8217;t. They have a different function according to the type of data you intend to&nbsp;show.</p>
<p>In our example we&#8217;ll use two functions: <code>gtk.CellRendererText()</code> and <code>gtk.CellRendererPixbuf()</code>. The former is used to render <strong>text items</strong>, while the latter for &#8220;<strong>images</strong>&#8221;.</p>
<p>So, after we created the model, we must <strong>create the columns</strong> and associate the cells to them. This is done by using the following code (in this example we&#8217;ll create a text&nbsp;column):</p>
<pre><code>cell_text = gtk.CellRendererText()
col_text = gtk.TreeViewColumn("A text column", cell_text, text = 0)
treeview.append_column(col_text)</code></pre>
<p>In this way we created a text-rendered column. The important part of the example is on the second line, when we set the text attribute with text = 0. Doing this we said to gtk to <strong>render a text column on the first column</strong> (0, not 1, because the numbering starts from 0). Now it&#8217;s time to show how to show an image, instead. This is done in a very similar&nbsp;way:</p>
<pre><code>cell_img = gtk.CellRendererPixbuf()
col_img = gtk.TreeViewColumn("An image!", cell_img, pixbuf = 1)
treeview.append_column(col_img)</code></pre>
<p>The only different thing is that, this time, <strong>we specified a pixbuf attribute</strong> in place of a text&nbsp;one.</p>
<p>Now that we created our treeview, we must add rows to&nbsp;it:</p>
<pre><code>item = model.append(None)
model.set_value(item, 0, "Hey, I'm text!")
model.set_value(item, 1, gtk.gdk.pixbuf_new_from_file("/path/to/image.jpg")</code></pre>
<p>The important thing to remember is that we must pass <strong>a gtk.gdk.Pixbuf object as image</strong>. That&#8217;s all&nbsp;:)</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2007/09/11/inserting-images-in-a-treeviewlistview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

