<?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>Andrea Grandi &#187; Igalia</title>
	<atom:link href="http://www.andreagrandi.it/category/igalia/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreagrandi.it</link>
	<description>Pensieri, progetti e qualche informazione su di me</description>
	<lastBuildDate>Sun, 05 Sep 2010 18:25:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Giving Lightning Talks</title>
		<link>http://www.andreagrandi.it/2009/09/03/giving-lightning-talks/</link>
		<comments>http://www.andreagrandi.it/2009/09/03/giving-lightning-talks/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 16:21:09 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[amsterdam]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[lightning]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[summit]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=319</guid>
		<description><![CDATA[During next Maemo Summit we will have at least 2 hours  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F09%2F03%2Fgiving-lightning-talks%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F09%2F03%2Fgiving-lightning-talks%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="alignright size-full wp-image-320" title="lightning" src="http://www.andreagrandi.it/wp-content/uploads/2009/09/lightning.jpg" alt="lightning" width="131" height="183" />During next <a href="http://wiki.maemo.org/Maemo_Summit_2009"><strong>Maemo Summit</strong></a> we will have at least 2 hours (one on saturday and another one on sunday) of lightning talks, about 20 talks where people will try to explain or present something in just <strong>5 minutes</strong>.</p>
<p>Last year, during Maemo Summit 2008, I did a lightning talk too and I must admit: even if I knew a lot about the subject of my talk and even if I had already done many other talks, I think it wasn't so good as I expected.</p>
<p>This year I've been selected again (more details will follow) to give a 5 minutes talk and with this great news the kind <a href="http://maemo.org/profile/view/dneary"><strong>Dave Neary</strong></a> also suggested me a <a href="http://www.perl.com/pub/a/2004/07/30/lightningtalk.html">link</a> with an article about some best practices when giving lightning talks. I'll try to resume the most important points, hoping this will be useful for people who is going to give a short presentation at Summit.</p>
<p><strong>Go straight to the point:</strong> five minutes finish sooner than you can expect. You have to talk about the main topic of your talk within the two first minutes, else you risk to talk too much about the rest and you couldn't have the time for the most important thing.</p>
<p><strong>Leave details away:</strong> people will never remember too many details explained in so little time. It's better to leave them away and put them in a more detailed blog post that you can link within your slides.</p>
<p><strong>Slides:</strong> for a five minute talk you can avoid preparing slides, but if this can help you to concentrate on points you have to talk about, please prepare them. Two or three slides can be useful to introduce yourself, to write any reference of what you're talking about many other things. Another important thing, make sure your slides are ready before starting your presentation: people don't want to wait 20-30 seconds it takes to start Open Office or any other similar application.</p>
<p><strong>Consider any eventuality:</strong> the presentation file could be damaged (be sure to have a copy of it, better in PDF format), your laptop could have no more battery (make sure you've a copy of your slides in a USB key), aliens could take you away, ecc... (ok, this last eventuality is remote).</p>
<p><strong>Concluding your talk:</strong> don't worry if you finish one or two minutes before, people won't bother about it. It's better to finish one minute before than 30 seconds later. If you want to leave an URL where people can find more details, how to contact you, put it in every slide so people will be able to take note of it from the first minute.</p>
<p>I hope to have resumed the most important points of the <a href="http://www.perl.com/pub/a/2004/07/30/lightningtalk.html">original article</a>. If you think there are any other important things to say, please leave me a comment and I'll add them. I really hope you will enjoy Maemo Summit and its lightning talks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/09/03/giving-lightning-talks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries – (3) – Building and Installing with distutils</title>
		<link>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/</link>
		<comments>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 09:39:50 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[distutils]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=315</guid>
		<description><![CDATA[In the last post of this series, we saw how to write a  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F13%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-3-%25e2%2580%2593-building-and-installing-with-distutils%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F13%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-3-%25e2%2580%2593-building-and-installing-with-distutils%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>In the last post of this series, we saw how to write a simple binding and we finished to build and install it manually. This is of course not a good way to manage the building/installation procedure.</p>
<p>In Python we can use a library called <strong>distutils</strong> that let us to automatize the building and installing process. I'll use the <strong>foo</strong> source code to create the package, so it will be easier to understand.</p>
<h2>Using distutils</h2>
<p>All we have to do is to write a <strong>setup.py</strong> file similar to this one:</p>
<pre class="brush: python;">
from distutils.core import setup, Extension

foomodule = Extension('foo', sources = ['foo.c'])

setup (name = 'Foo',
       version = '1.0',
       description = 'This is a package for Foo',
       ext_modules = [foomodule])
</pre>
<p>As you can see, we have to first import needed modules with: <strong>from distutils.core import setup, Extension</strong><br />
then we create an entry for each module we have (in this case just one, "foomodule"). We then call the <strong>setup()</strong> method passing it all the parameters and our <strong>setup.py</strong> is complete.</p>
<h2>Building and installing</h2>
<p>To test it we can try to build the package in this way:</p>
<p><code>python2.5 setup.py build</code></p>
<p>if we want to install the module in our system:</p>
<p><code>python2.5 setup.py install</code></p>
<h2>References</h2>
<ul>
<li>Official Python documentation: <a href="http://docs.python.org/extending/building.html">http://docs.python.org/extending/building.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyMaemo (Python for Maemo) second beta release for Fremantle</title>
		<link>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/</link>
		<comments>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 08:20:09 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[fremantle]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[pymaemo]]></category>
		<category><![CDATA[tablet]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=312</guid>
		<description><![CDATA[The PyMaemo team is pleased to announce the second beta [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F10%2Fpymaemo-python-for-maemo-second-beta-release-for-fremantle%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F10%2Fpymaemo-python-for-maemo-second-beta-release-for-fremantle%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>The <strong>PyMaemo</strong> team is pleased to announce the second beta release of  PyMaemo for <strong>Fremantle</strong>!</p>
<p>This new release is available through the <strong>extras-devel</strong> repository, see  installation instructions in<br />
<a href="http://pymaemo.garage.maemo.org/sdk_installation.html#fremantle" target="_blank">http://pymaemo.garage.maemo.org/sdk_installation.html#fremantle</a></p>
<h2>What is it?</h2>
<p>Python for Maemo (PyMaemo for short) main objective is to make  possible to use <strong>Python</strong> programming language as the scripting and  development language for Maemo Platform, providing a better  alternative for fast prototyping and programming in Maemo environment  besides the C programming language.</p>
<p>Python is for serious programming and to have fun. Python has a nice  syntax, it is easy to learn and powerful enough for a vast range of  applications, this is why we choose Python for Maemo.</p>
<h2>What has changed?</h2>
<p><strong>New packages:</strong></p>
<ul>
<li> <strong>python-mafw</strong> (0.1-1maemo1)
<ul>
<li>Python bindings for the Media Application Framework [1]</li>
<li>Supported API is very basic at the moment, and there are some bugs. Feedback is welcome!</li>
</ul>
</li>
<li><strong>python-hildondesktop</strong> (0.0.3-1maemo1)
<ul>
<li>Python bindings for the home/status widgets API</li>
</ul>
</li>
<li><strong>python-notify</strong> (0.1.1-2maemo1)
<ul>
<li>Python bindings for libnotify</li>
</ul>
</li>
<li><strong>pyclutter</strong> (0.8.0-1maemo2)
<ul>
<li>Python bindings for the Clutter API [2]</li>
<li>Experimental package, waiting for developer feedback</li>
</ul>
</li>
</ul>
<p><strong> Updated packages:</strong></p>
<ul>
<li> <strong>gnome-python</strong> (2.26.1-1maemo1)
<ul>
<li>major upgrade, matching current Debian testing release;</li>
<li>feedback on this is welcome, as it replaces a fairly old version (2.18).</li>
</ul>
</li>
<li><strong>pygtk</strong> (2.12.1-6maemo7)
<ul>
<li>Enable glade support.</li>
</ul>
</li>
<li><strong>python2.5</strong> (2.5.4-1maemo1)
<ul>
<li>Updated to latest upstream 2.5.x release.</li>
<li>add support to --install-layout=deb flag.</li>
</ul>
</li>
<li><strong>python-central</strong> (0.6.11.1maemo1)
<ul>
<li>dependency needed by the new python-setuptools version.</li>
</ul>
</li>
<li><strong>python-defaults</strong> (2.5.2-3maemo3)
<ul>
<li>Change PREVVER in debian/rules, avoiding old python2.5-minimal versions that had "/usr/bin/python" and thus conflicts with python-minimal.</li>
</ul>
</li>
<li><strong>python-hildo</strong>n (0.9.0-1maemo10)
<ul>
<li>lots of bug fixes</li>
</ul>
</li>
<li><strong>python-setuptools</strong> (0.6c9-1maemo1)
<ul>
<li>add support to --install-layout=deb flag.</li>
</ul>
</li>
</ul>
<p><strong> Bugs fixed:</strong> MB#4530 [3], MB#4450 [4], MB#4629 [5], MB#4628 [6],<br />
MB#4647 [7], MB#4632 [8],  MB#4646 [9],  MB#4750 [10],  MB#4749 [11],<br />
MB#4791 [12]</p>
<h2>Known issues</h2>
<p>MB#4782 [13]: osso.Context causes segmentation fault<br />
MB#4821 [14]: Cannot create HildonTouchSelector with single text column<br />
MB#4824 [15]: python-mafw: source_browsing.py example does not work<br />
MB#4839 [16]: python-mafw: mafw.Registry lacks list_plugins() method<br />
MB#4849 [17]: python-mafw: MafwPluginDescriptorPublic structure is missing</p>
<p>We will not migrate to python2.6 in fremantle due to a (unresolved)  bug (MB#4734 [18]), where a core SDK package explicitly conflicts with  python &gt;= 2.6, preventing any further upgrades from the 2.5.x series.</p>
<p>This release is supposed to be compatible with previous releases. If  you have any issues regarding building your Python application on  Fremantle, feel free to report it on the pymaemo-developers mailing list [19].</p>
<h2>Acknowledgments</h2>
<p>Thanks to everybody who helped making this release possible.</p>
<p>Bug reports, as always, should go to our Bugzilla [20]. Use the  <strong>pymaemo-developers</strong> mailing list for help, feedback or suggestions.</p>
<h2>References</h2>
<p>[1] <a href="https://garage.maemo.org/projects/mafw/" target="_blank">https://garage.maemo.org/projects/mafw/</a><br />
[2] <a href="http://www.clutter-project.org/" target="_blank">http://www.clutter-project.org/</a><br />
[3] <a href="https://bugs.maemo.org/show_bug.cgi?id=4530" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4530</a><br />
[4] <a href="https://bugs.maemo.org/show_bug.cgi?id=4450" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4450</a><br />
[5] <a href="https://bugs.maemo.org/show_bug.cgi?id=4629" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4629</a><br />
[6] <a href="https://bugs.maemo.org/show_bug.cgi?id=4628" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4628</a><br />
[7] <a href="https://bugs.maemo.org/show_bug.cgi?id=4647" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4647</a><br />
[8] <a href="https://bugs.maemo.org/show_bug.cgi?id=4632" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4632</a><br />
[9] <a href="https://bugs.maemo.org/show_bug.cgi?id=4646" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4646</a><br />
[10] <a href="https://bugs.maemo.org/show_bug.cgi?id=4750" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4750</a><br />
[11] <a href="https://bugs.maemo.org/show_bug.cgi?id=4749" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4749</a><br />
[12] <a href="https://bugs.maemo.org/show_bug.cgi?id=4791" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4791</a><br />
[13] <a href="https://bugs.maemo.org/show_bug.cgi?id=4782" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4782</a><br />
[14] <a href="https://bugs.maemo.org/show_bug.cgi?id=4821" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4821</a><br />
[15] <a href="https://bugs.maemo.org/show_bug.cgi?id=4824" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4824</a><br />
[16] <a href="https://bugs.maemo.org/show_bug.cgi?id=4839" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4839</a><br />
[17] <a href="https://bugs.maemo.org/show_bug.cgi?id=4849" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4849</a><br />
[18] <a href="https://bugs.maemo.org/show_bug.cgi?id=4734" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4734</a><br />
[19] <a href="https://garage.maemo.org/mailman/listinfo/pymaemo-developers" target="_blank">https://garage.maemo.org/mailman/listinfo/pymaemo-developers</a><br />
[20] <a href="https://bugs.maemo.org/enter_bug.cgi?product=PyMaemo" target="_blank">https://bugs.maemo.org/enter_bug.cgi?product=PyMaemo</a></p>
<h2>Credits</h2>
<p>This post was possible thanks to <strong>Anderson Lizardo</strong>, from PyMaemo team, who posted these informations on pymaemo-developers mailing list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making Maemo email client usable with GMail</title>
		<link>http://www.andreagrandi.it/2009/08/08/making-maemo-email-client-usable-with-gmail/</link>
		<comments>http://www.andreagrandi.it/2009/08/08/making-maemo-email-client-usable-with-gmail/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 12:34:44 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[modest]]></category>
		<category><![CDATA[recent]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=309</guid>
		<description><![CDATA[I must admit, I wasn't using Maemo email client, becaus [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F08%2Fmaking-maemo-email-client-usable-with-gmail%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F08%2Fmaking-maemo-email-client-usable-with-gmail%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>I must admit, I wasn't using Maemo email client, because I did find it was simply unusable, at least with my GMail account.</p>
<p>I tried both POP3 and IMAP, but having about 25.000+ messages in my account, downloading just the headers was a job that the client simply couldn't manage.</p>
<p>Yesterday I knew about "<strong>recent mode</strong>" support in <strong>POP3</strong>, a functionality that <strong>GMail</strong> supports too. This mode allow you to download<strong> only last 30 days</strong> messages (in my case, no more than 1000)  so the client can manage them without any problem.</p>
<p>All you have to do to enable this mode is put the "<strong>recent:</strong>" string before the username. For example: if your username is "username@gmail.com" you have to write "<strong>recent:username@gmail.com</strong>". Important: this mode only works with POP3, not with IMAP.</p>
<p>To conclude, let me say <strong>thank you</strong> to the kind guy who let me discover this mode. Thank you <a href="http://blogs.igalia.com/svillar/"><strong>Sergio</strong></a>! Now there is another thing I can do with my tablet!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/08/making-maemo-email-client-usable-with-gmail/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries – (2) – A simple example of binding</title>
		<link>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/</link>
		<comments>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 14:44:21 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[maemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=301</guid>
		<description><![CDATA[Introduction
As I promised in the preceding post, I'll [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F06%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-2-%25e2%2580%2593-a-simple-example-of-binding%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F06%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-2-%25e2%2580%2593-a-simple-example-of-binding%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<h2>Introduction</h2>
<p>As I promised in the preceding post, I'll provide a very easy example of a python binding. Let's suppose we don't want to use the methods included in Python to sum two integer values and we want to do it in C and then call the add method from a python script. I'll write the complete source code first and then I'll explain all the parts of it.</p>
<h2>Source Code</h2>
<pre class="brush: cpp;">
#include &lt;Python.h&gt;

static PyObject *foo_add(PyObject *self, PyObject *args)
{
	int a;
	int b;

	if (!PyArg_ParseTuple(args, &quot;ii&quot;, &amp;a, &amp;b))
	{
		return NULL;
	}

	return Py_BuildValue(&quot;i&quot;, a + b);
}

static PyMethodDef foo_methods[] = {
	    { &quot;add&quot;, (PyCFunction)foo_add, METH_VARARGS, NULL },
	    { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initfoo()
{
	    Py_InitModule3(&quot;foo&quot;, foo_methods, &quot;My first extension module.&quot;);
}
</pre>
<h2>How it works</h2>
<p>First of all we have to include <strong>Python.h</strong> in our C file. This allows us to write an extension for Python language. To be able to include this header, we must have the python development packages installed in our system. For example in Debian based distributions we can install them with this command:</p>
<p><code>sudo apt-get install python2.5-dev</code></p>
<p>Every module has at least three parts. In the first part we write methods we want to call from the final python module: in this case we have a method called <strong>foo_add</strong> where "<em>foo</em>" is the name of the module and "<em>add</em>" the name of the method. Every method is declared as <strong>static PyObject</strong>. The method does anything particular except calling PyArg_ParseTuple to validate the input (we'll discuss this later), adding the two passed numbers and returning the result.</p>
<p>In the second part we have something like a dictionary, defined as static <strong>PyMethodDef</strong> and called foo_methods (where "foo" again is the name of the module). For each method we want to expose in our python module, we have to add something like this:</p>
<p><code>{"add", (PyCFunction)foo_add, METH_VARARGS, NULL}</code></p>
<p>where "<em>add</em>" is the name of the method we want to be visible in our module, <em>(PyCFunction)foo_add</em> is a pointer to our foo_add method, implemented in the C module, METH_VARARGS means that we want to pass some parameters to the function and the last one would be the description of the method (we can leave it NULL if we want).</p>
<p>Third part allows us to register the defined method/s and the module:</p>
<p><code>Py_InitModule3("foo", foo_methods, "My first extension module.");</code></p>
<h3>Parsing Parameters</h3>
<p>The <strong>PyArg_ParseTuple</strong> function extracts arguments from the <strong>PyObject</strong> passed as parameter to the current method and follows almost the sscanf syntax to parse parameters (in this case we had <em>"ii"</em> for two integers). You can fin the complete reference here: <a href="http://docs.python.org/c-api/arg.html">http://docs.python.org/c-api/arg.html</a></p>
<h2>Building and installing</h2>
<p>To build the module, we have to be in the source directory and execute this command:</p>
<p><code>gcc -shared -I/usr/include/python2.5 foo.c -o foo.so</code></p>
<p>then we've to copy the generated module to the python's modules directory:</p>
<p><code>cp foo.so /usr/lib/python2.5/site-packages/</code></p>
<h2>Testing our module</h2>
<p>Testing the module is really easy. We've to start a python shell or create a python script with the following source code:</p>
<pre class="brush: python;">
import foo
print foo.add(2, 3)
</pre>
<p>if all is working fine, the printed result should be <strong>5</strong></p>
<h2>References</h2>
<ul>
<li><a href="http://docs.python.org/extending/extending.html">http://docs.python.org/extending/extending.html</a></li>
<li><a href="http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764596543.html">http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764596543.html</a></li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 399px; width: 1px; height: 1px;">python2.5-dev</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 399px; width: 1px; height: 1px;">python2.5-dev</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MAFW and Python: asking for developers feedback</title>
		<link>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/</link>
		<comments>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 09:16:58 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[fremantle]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[mafw]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=303</guid>
		<description><![CDATA[MAFW is a new multimedia framework that will be used in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F05%2Fmafw-and-python-asking-for-developers-feedback%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F05%2Fmafw-and-python-asking-for-developers-feedback%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>MAFW is a new multimedia framework that will be used in Fremantle.</p>
<p>The PyMaemo team is currently working on writing bindings for Python<br />
language for this library and at the moment we've released a 0.1<br />
version of python-mafw that you can install directly from Scratchbox<br />
repository.</p>
<p>Not all the methods are implemented (you can manage the Registry and<br />
the Playlist, but nothing more), because even if we're using codegen<br />
to generate bindings (and it's helping us a lot), we've seen that at<br />
least 30-40 methods have to be overridden by hand so it's taking us<br />
more time than we expected and we're trying to organize how to<br />
continue this work.</p>
<p>We would like to get feedback from python application developers and<br />
also from C application developers that are currently using MAFW so we<br />
can work on a "roadmap" that reflects what developers want:</p>
<ul>
<li>What are the functionalities you're using in your application that you think they cannot miss in the Python binding?</li>
<li>Have you already started using MAFW or even better python-mafw to develop something?</li>
<li>What is the currently missing method/methods you would like to be implemented first?</li>
</ul>
<p>Come on developers! We're waiting for your feedback <img src='http://www.andreagrandi.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries &#8211; (1) &#8211; Introduction</title>
		<link>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/</link>
		<comments>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 09:04:35 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[pymaemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=298</guid>
		<description><![CDATA[This summer I'm having the pleasure of working in Igali [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F03%2Fwriting-python-bindings-of-existing-c-libraries-1-introduction%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F03%2Fwriting-python-bindings-of-existing-c-libraries-1-introduction%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>This summer I'm having the pleasure of working in <a href="http://www.igalia.com"><strong>Igalia</strong></a> (a spanish free software company) for a couple of months and they assigned me to an interesting project: developing <strong> Python bindings</strong> for <strong>MAFW</strong> library (a <strong>Maemo</strong> multimedia library that will be used in <strong>Fremantle</strong> release).</p>
<p>Having the opportunity to work both with <strong>C</strong> (yes, Python bindings are almost C code) and <strong>Python</strong> (it's a good practice to write unittest of all implemented methods) it's a good way to improve my knowledges in both languages and since I wasn't able to find much documentation about these kind of things, I'm going to share my own experiences.</p>
<p><strong>What is a Binding?</strong></p>
<p>A binding is a Python module, written in C language, that allows Python developers to call functions from existing C libraries from their python applications. It's just like a "<em>bridge</em>" from C world to Python one.</p>
<p><strong>Why writing bindings?</strong></p>
<p>There are a couple of reasons to write python bindings instead of writing a library in python language from scratch.</p>
<p>First of all I don't think is good duplicating code, so if a library already exists and it's written in C, why writing it again in another language? There's no reason. A lot of code already exist in C world and all we have to do is to create a bridge with python world.</p>
<p>Another good reason, in particular when a C library doesn't exist yet, is the fact that python code is slower than C code for some tasks (for example multimedia codecs). In these cases is good to implement the core library in C language and then create a python binding for it.</p>
<p><strong>Coming next</strong></p>
<p>As the title of this post says, this is only an introduction to the subjects I'm going to write about. If you have any particular request about any argument you would like to read, please feel free to leave me a comment. Next posts will talk about these things:</p>
<ul>
<li><strong>A simple example of binding:</strong> I'll write a simple library in C language and I'll show how to create the relative python binding, providing complete source code and an example for python developers.</li>
<li><strong>Building and installing python bindings with distutils:</strong> I'll explain how to use <strong>distutils</strong> to build and install the binding (using the well know method "python setup.py install").</li>
<li><strong>Defining new types:</strong> this post will be about how to write new types in C language and being able to use them from python code.</li>
<li><strong>Using codegen to write bindings:</strong> I'll explain how to use <strong>codegen</strong> utils to automate lot of tasks, to generate the most part of binding code and how to customize the generated code using overrides.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I officially joined the PyMaemo team</title>
		<link>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/</link>
		<comments>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 12:54:37 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[freemantle]]></category>
		<category><![CDATA[maemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=295</guid>
		<description><![CDATA[This summer I'm working for 2 months at Igalia, a spani [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F07%2F25%2Fi-officially-joined-the-pymaemo-team%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F07%2F25%2Fi-officially-joined-the-pymaemo-team%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>This summer I'm working for 2 months at <a href="http://www.igalia.com">Igalia</a>, a spanish free software company, and they assigned me the project of writing a <strong>Python binding</strong> for <strong>MAFW</strong> (a new multimedia library that will be included in <strong>Freemantle</strong>).</p>
<p>After few days I discovered that <a href="http://garage.maemo.org/projects/pymaemo/"><strong>PyMaemo</strong></a> team was already working to it, so I asked to join them and they accepted me!</p>
<p>I really love Python language and since I think other developers love it too, I think we should provide good bindings for every library available in Maemo, so lot of developers can start writing their applications in this language.</p>
<p>I'll work to this project full time until the first week of september, so I hope to be able to learn a lot and to contribute as much as I can to this project.</p>
<p>If anyone else want to join PyMaemo team and help us to develop Python bindings, I think he will be welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
