<?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>pintant... &#187; Programari Lliure</title>
	<atom:link href="http://pintant.cat/category/programari-lliure/feed/" rel="self" type="application/rss+xml" />
	<link>http://pintant.cat</link>
	<description>amb teclat qwerty</description>
	<lastBuildDate>Sat, 19 May 2012 08:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Power off a USB device</title>
		<link>http://pintant.cat/2012/05/12/power-off-usb-device/</link>
		<comments>http://pintant.cat/2012/05/12/power-off-usb-device/#comments</comments>
		<pubDate>Sat, 12 May 2012 08:11:02 +0000</pubDate>
		<dc:creator>carles</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Programari Lliure]]></category>
		<category><![CDATA[Tecnologia]]></category>

		<guid isPermaLink="false">http://pintant.cat/?p=1232</guid>
		<description><![CDATA[I wanted to power off a USB device. Searching in Google for &#8220;power off usb&#8221; returns different results but I didn&#8217;t succeed with any of the suggestions (Linux version 3.2.0). I asked in the linux-usb mailing list (question, see one of the relevant answers (from Alan Stern). In short: not possible. Using a USB hub [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to power off a USB device. Searching in Google for &#8220;power off usb&#8221; returns different results but I didn&#8217;t succeed with any of the suggestions (Linux version 3.2.0).</p>
<p>I asked in the <a href="http://www.linux-usb.org/">linux-usb mailing list</a> (<a href="http://marc.info/?l=linux-usb&#038;m=133517101616417&#038;w=2">question</a>, see <a href="http://marc.info/?l=linux-usb&#038;m=133519454726017&#038;w=2">one of the relevant answers</a> (from Alan Stern). In short: not possible. Using a USB hub it&#8217;s then maybe possible -some models only-. The answer includes a link to a small program to try to disable the port. I could disable the port, but the device had still power.<br />
<span id="more-1232"></span><br />
I still didn&#8217;t want to give up. I remembered that I bought, 2 years ago, a USB relay. Actually that one could be used it says with 220VAC/10A, so I could power on a heating or some big device.</p>
<p>I did a bit of very bad-done hardware work: I &#8220;broke&#8221; a USB cable, got the red inner-cable to pass through the relay. Then using one USB port I control the relay and I can switch on and off the other USB device like I wanted initially.</p>
<p>As you can see in the photo I broke too much the shield -because a confussion not directly related with the project-. Still, it works well with my dumb device and other devices.</p>
<p><a href="http://pintant.cat/wp-content/uploads/usb-relay.jpg"><img src="http://pintant.cat/wp-content/uploads/usb-relay.jpg" alt="" title="usb-relay" width="502" height="377" class="aligncenter size-full wp-image-1234" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://pintant.cat/2012/05/12/power-off-usb-device/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Joc de la Vida: amb i sense Viquipèdia</title>
		<link>http://pintant.cat/2012/02/19/joc-de-la-vida-amb-i-sense-viquipedia/</link>
		<comments>http://pintant.cat/2012/02/19/joc-de-la-vida-amb-i-sense-viquipedia/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 17:00:00 +0000</pubDate>
		<dc:creator>carles</dc:creator>
				<category><![CDATA[Programari Lliure]]></category>

		<guid isPermaLink="false">http://pintant.cat/?p=1141</guid>
		<description><![CDATA[Fa molts anys vaig començar a aprendre C++ i Qt. El 2001 o 2002 segur (recordo que estava a la residència d&#8217;estudiants fent coses. Una de les coses recordo que era un programa que es connectava a alguna Web, agafava la temperatura i l&#8217;ensenyava). Els meus temes varien poc (veure i entrada aquí al blog, [...]]]></description>
			<content:encoded><![CDATA[<p>Fa molts anys vaig començar a aprendre C++ i Qt. El 2001 o 2002 segur (recordo que estava a la residència d&#8217;estudiants fent coses. Una de les coses recordo que era un programa que es connectava a alguna Web, agafava la temperatura i l&#8217;ensenyava). Els meus temes varien poc (<a href="http://pinux.info/temps2/">veure</a> i entrada aquí al <a href="http://pintant.cat/2009/11/11/comparacio-de-temperatures/">blog</a>, això és del 2009, el 2006 quan estava a Estònia vaig fer la primera versió).</p>
<p>Una de les &#8220;practiques&#8221; que vaig fer va ser el Joc de la Vida de Conwall (<a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Wikipedia-en</a> , <a href="http://ca.wikipedia.org/wiki/Joc_de_la_vida">Wikipedia-ca</a>). És un joc per 0 jugadors (no s&#8217;interactua un cop està funcionant), l&#8217;estat inicial del taulell va evolucionant seguint unes regles.<br />
<span id="more-1141"></span><br />
Ho vaig fer, el taulell va evolucionar, vaig pensar &#8220;que guai&#8221; i ja va estar, o poc més.</p>
<p>Ara, amb Viquipèdia, es poden veure figures que fan coses pel taulell. Que es mouen, que commuten estats, etc. etc.</p>
<p>El passat Python Code Dojo va ser el problema a resoldre més votat. Vaig pensar &#8220;vaja, ja l&#8217;he fet, tampoc era tan divertit&#8221;. Però gràcies a Wikipedia doncs vaig descobrir coses i va ser més divertit.</p>
<p>Els codi font de diferents grups del Python Dojo es pot trobar a <a href="https://github.com/ldnpydojo/game-of-life<br />
">github</a>.</p>
<p>Qui hagués tingut Viquipèdia a la joventut. Segur que tot el que hi ha allà es pot trobar a altres llocs (evidentment) però és tant fàcil anar i llegir fàcilment&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://pintant.cat/2012/02/19/joc-de-la-vida-amb-i-sense-viquipedia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Camiseta Fosdem 2012</title>
		<link>http://pintant.cat/2012/02/13/camiseta-fosdem-2012/</link>
		<comments>http://pintant.cat/2012/02/13/camiseta-fosdem-2012/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 00:45:23 +0000</pubDate>
		<dc:creator>carles</dc:creator>
				<category><![CDATA[Programari Lliure]]></category>

		<guid isPermaLink="false">http://pintant.cat/?p=1136</guid>
		<description><![CDATA[La setmana passada, i tal com i ja havia comentat, va ser el cap de setmana que vaig anar al Fosdem. De Catux només va venir en Fran. Divendres a la nit miràvem quin autobús / tramvia agafar, a quina hora, etc. Vaig revisar la línia d&#8217;autobús i vaig mirar els horaris (recordo que el [...]]]></description>
			<content:encoded><![CDATA[<p>La setmana passada, i tal com i ja havia <a href="http://pintant.cat/2012/01/08/cap-al-fosdem-2012/">comentat</a>, va ser el cap de setmana que vaig anar al Fosdem.</p>
<p>De Catux només va venir en <a href="http://franhp.net/">Fran</a>. Divendres a la nit miràvem quin autobús / tramvia agafar, a quina hora, etc.</p>
<p>Vaig revisar la línia d&#8217;autobús i vaig mirar els horaris (recordo que el tramvia passava cada&#8230; 40 minuts?). Total, el què no vàrem revisar és a quina hora començava el Fosdem. El Fran va dir, crec, a les 9:30 (o potser les 9?). Total, vàrem arribar allà ven d&#8217;hora. Però el Fosdem començava a les 10:30!</p>
<p>Així que vaig fer la meva donació al Fosdem, la que et donen una camiseta. Tinc la donació número&#8230; 2!:<br />
<a href="http://pintant.cat/wp-content/uploads/fosdem_tshirt.jpg"><img src="http://pintant.cat/wp-content/uploads/fosdem_tshirt.jpg" alt="" title="Donació Fosdem" width="500" height="409" class="aligncenter size-full wp-image-1137" /></a></p>
<p>Gràcies Fran! <img src='http://pintant.cat/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ens vàrem llevar d&#8217;hora, però vàrem tenir la segona camiseta, veure els llibres d&#8217;OReilly amb calma, esmorzar tranquil·lament, planificar les conferències&#8230;</p>
<p>Fosdem: fins l&#8217;any vinent!</p>
]]></content:encoded>
			<wfw:commentRss>http://pintant.cat/2012/02/13/camiseta-fosdem-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cap al Fosdem 2012</title>
		<link>http://pintant.cat/2012/01/08/cap-al-fosdem-2012/</link>
		<comments>http://pintant.cat/2012/01/08/cap-al-fosdem-2012/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 18:49:18 +0000</pubDate>
		<dc:creator>carles</dc:creator>
				<category><![CDATA[Programari Lliure]]></category>

		<guid isPermaLink="false">http://pintant.cat/?p=1123</guid>
		<description><![CDATA[Igual que anys anteriors: també vaig al Fosdem 2012. A veure quines sorpreses hi haurà enguany, bons conferenciants, etc. (breument, és la conferència de programari lliure més gran d&#8217;Europa i imagino que del món) Normalment surto de cada Fosdem amb una llista de projectes, programes, coses a mirar que tardo uns quants dies&#8230; Si algú [...]]]></description>
			<content:encoded><![CDATA[<p>Igual que anys anteriors: també vaig al <a href="http://fosdem.org/2012/">Fosdem 2012</a>. A veure quines sorpreses hi haurà enguany, bons conferenciants, etc.<br />
(breument, és la conferència de programari lliure més gran d&#8217;Europa i imagino que del món)</p>
<p>Normalment surto de cada Fosdem amb una llista de projectes, programes, coses a mirar que tardo uns quants dies&#8230;</p>
<p>Si algú ve i vol saludar que avisi. Companys de <a href="http://www.catux.org">Catux</a> també venen.</p>
]]></content:encoded>
			<wfw:commentRss>http://pintant.cat/2012/01/08/cap-al-fosdem-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Screensaver for KDE using Python and Pygame</title>
		<link>http://pintant.cat/2011/09/11/screensaver-for-kde-using-python-and-pygame/</link>
		<comments>http://pintant.cat/2011/09/11/screensaver-for-kde-using-python-and-pygame/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 17:49:13 +0000</pubDate>
		<dc:creator>carles</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Programari Lliure]]></category>
		<category><![CDATA[Tecnologia]]></category>

		<guid isPermaLink="false">http://pintant.cat/?p=1064</guid>
		<description><![CDATA[At Mendeley we have already done two hackdays. That&#8217;s quite interesting event: during a period of time (first one was on Friday until late night or overnight, second one Saturday and Sunday) we do whatever we want to do, it only needs to be a bit related with Mendeley. On the last hack weekend I [...]]]></description>
			<content:encoded><![CDATA[<p>At Mendeley we have already done two hackdays. That&#8217;s quite interesting event: during a period of time (first one was on Friday until late night or overnight, second one Saturday and Sunday) we do whatever we want to do, it only needs to be a bit related with Mendeley.</p>
<p>On the last hack weekend I did a screensaver using Python, which one is integrated with KDE. Probably with some small changes would work in other systems.</p>
<p>In this entry I&#8217;ll cover the basic of the screensavers in KDE (how to integrate the new screensaver in KDE), and how KDE interacts with the screensaver. You should know a little bit of Python and Pygame, but if you don&#8217;t know you can still understand the code and do the same using other systems.</p>
<p>The code is in <a href="http://git.pinux.info/?p=misc.git;a=tree;f=mendeley_screensaver;h=0a06a38244df08c0c926ca9455eaa912956cf995;hb=HEAD">Git</a>. Or if you want the quick example <a href="http://git.pinux.info/?p=misc.git;a=tree;f=mendeley_screensaver;hb=HEAD">look here.</a></p>
<p><span id="more-1064"></span></p>
<h2>How to add a new screensaver in the screensavers list from the system</h2>
<p>In KDE, in Settings, Display icon, screensavers: there is a list of screensavers (if you don&#8217;t have any you can install the packages kde-window-manager and kscreensaver-xsavers).</p>
<p>If you want to add a new screensaver there, you can create a file in the directory /usr/share/kde4/services/ScreenSavers , My new file is named &#8220;Mendeley.desktop&#8221; where you can follow the same structure than other entries there. My one looks like:<br />
<code><br />
[Desktop Entry]<br />
Exec=mendeley.kss<br />
Icon=preferences-desktop-screensaver<br />
Type=Service<br />
X-KDE-ServiceTypes=ScreenSaver<br />
Actions=Setup;InWindow;Root;<br />
# X-KDE-Category=Miscellaneous<br />
Name=Mendeley<br />
Name[ca]=Mendeley</p>
<p>[Desktop Action Setup]<br />
Exec=mendeley.kss -setup<br />
Name=Setup...<br />
Name[ca]=Arranjament...<br />
Icon=preferences-desktop-screensaver</p>
<p>[Desktop Action InWindow]<br />
Exec=mendeley.kss -window-id %w<br />
Name=Display in Specified Window<br />
Name[ca]=Mostra a la finestra especificada<br />
NoDisplay=true</p>
<p>[Desktop Action Root]<br />
Exec=mendeley.kss -root<br />
Name=Display in Root Window<br />
Name[ca]=Mostra a la finestra arrel<br />
NoDisplay=true<br />
</code><br />
See the different sections: Desktop Entry is a general one, defining which actions that particular screensaver can do (in the example: all of them: setup, preview -InWindow- and the real screensaver thing -root).</p>
<p>In each action it defines which the parameters will be passed to the binary. They can be changed, I&#8217;ve used the same than other screensavers.</p>
<p>In the above case, it says that when mendeley screensaver will be called in preview mode (or test mode) it will pass the parameter -window-id and then the window id. In execution mode it will pass only -root parameter, and in setup mode -setup.</p>
<p>In our case, mendeley.kss is just a Python file (the extension .kss is to use the same extensions than other screensavers, could be whatever we want).</p>
<p>The mendeley.kss should be in some directory in the path of the current user (else, the full path could be also used).</p>
<h2>Preview / test mode: window-id parameter</h2>
<p>Pygame, by default, uses SDL as an output. And SDL reads an environment variable (SDL_WINDOWID), if the variable exists uses that window to pain the things. Else SDL creates a new window, as it usually happens.</p>
<p>The basic code to handle the test and the preview mode would be like:</p>
<p><code><br />
#!/usr/bin/python</code></p>
<p>import os<br />
import pygame</p>
<p>if sys.argv[1] == &#8220;-window-id&#8221;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;os.environ['SDL_WINDOWID'] = sys.argv[2]</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;pygame.init()<br />
self.window = pygame.display.set_mode((0,0)) # auto-resize</p>
<p>From here on we would just write standard Python using Pygame.</p>
<h2>Root window: the real case</h2>
<p>In case that the screensaver executable receives -root parameter, we need to search the root window of the current desktop.</p>
<p>As a first approach (that doesn&#8217;t work here), this could be found using xprop -root and then getting the &#8220;window id&#8221; from the output of the command. But we will find that when KDE is trying to use the screensaver, nothing will appear on the screen (as a note, here is where I spent quite a long time to understand what was happening&#8230;).</p>
<p>What we need to do is search for the virtual root window. This is a window that we need to use. This virtual root window is a window child of the root window and that one of the properties is __SWM_ROOT. Code to do this can be found in <a href="http://git.pinux.info/?p=misc.git;a=blob;f=mendeley_screensaver/virtualroot.py;h=2a0c6d459eee7dd53e9b1c6375d109fcc16a7df2;hb=HEAD">git</a>.</p>
<p>What the code does is to get all the children of the real root window, iterate over them and search which one contains __SWM_VROOT. Then returns the window id of the window that contains __SWM_VROOT.</p>
<p>The first version of the screensaver used a small C executable with some code borrowed from xscreensaver project that was doing the same using C libraries (libx11). I thought that would be more clear, Pythonic and easier to understand if I would implement it using xwininfo and xprop. If somebody knows a way to get the same result using just Python (without external calls) feel free to commend or mail me.</p>
<p>The code in mendeley.kss (which is the main Python file) to get the Virtual Root Window is like:<br />
<code><br />
if sys.argv[1] == "-root":<br />
&nbsp;&nbsp;&nbsp;&nbsp;windowid = virtualroot.getVirtualRootWindow()<br />
&nbsp;&nbsp;&nbsp;&nbsp;os.environ['SDL_WINDOWID'] = windowid<br />
</code></p>
<p>Instead of using the window-id that KDE provides us: searches for the windowid of the virtual root window and uses it.</p>
<h2>Configuration</h2>
<p>Maybe we would like to have a setup dialog for our new shiny screensaver. In that case (already specified in the .desktop file) KDE will launch the executable with the option -setup. I did something very simple as a proof of concept: I just launch a Qt dialog where the user can change some values, and the values are saved in a .py file. The main screensaver file just imports that .py file. Don&#8217;t do the same into the wild!</p>
<p>The code to do this (including the Qt code, etc.) can be found in the file mendeleyScreensaverSetup.py.</p>
<h2>Exiting</h2>
<p>When the user moves the mouse (or after writing the password): the KDE screensaver system will kill send a SIGTERM to the screensaver. In the handle_input of the screensaver code we can do:</p>
<p><code><br />
def handle_input(self,events):<br />
for event in events:<br />
# SIGTERM is handled by SDL and received a QUIT event<br />
if event.type == QUIT:<br />
&nbsp;&nbsp;&nbsp;&nbsp;sys.exit(0)<br />
</code></p>
<h2>All together now&#8230;</h2>
<p>All the code for the Mendeley screensaver can be found in <a href="http://git.pinux.info/?p=misc.git;a=tree;f=mendeley_screensaver;h=0a06a38244df08c0c926ca9455eaa912956cf995;hb=HEAD">git</a>.</p>
<p>I&#8217;ve done a reduced version without mainly any logic (only a text is displayed) so you could create your own screensaver from there on. <a href="http://git.pinux.info/?p=misc.git;a=blob;f=mendeley_screensaver/easy_example.kss;h=9b5de56eebb2bb67c8831b37533bf51c3fa4408a;hb=HEAD">See the code.</a></p>
<p>In my system, when the screensaver is printing something to the standard output, this is saved in the file ~/.xsession-errors .</p>
<h2>What about other desktop systems? (or operating systems?)</h2>
<p>Screensavers in Gnome? Maybe just xscreensaver? Or even on Mac OS X? Microsoft Windows? I haven&#8217;t done it, but as far as I&#8217;ve seen in Google the principles are quite similar. Good luck, comment here if you do. And perhaps I&#8217;ll do some other article about how to do screensavers in the other systems.</p>
<p>Here I found some information regarding Microsoft Windows (I haven&#8217;t tested): http://archives.seul.org/pygame/users/Mar-2003/msg00162.html</p>
<h2>Conclusion</h2>
<p>Doing screensaver using Python and Pygame is easy (when you have the basic) and can be very fun. And leave a quite big potential there: would you like your screensaver to do some network connections and show webpages? Or perhaps take photos of your desk? Or maybe a clock with how long you haven&#8217;t been there? Or show randomly your last git messages? everything can be done, it&#8217;s just Python code.</p>
<p>Also, thanks to Mendeley to organise the hackdays / hackweekends. It&#8217;s fun, you learn, you code for fun&#8230; without thinking too much about maintenance or other constraints. We did a blog post with some screenshots of some hacks.</p>
<p>Also, if you have some idea for some hackday: tell me. It&#8217;s usually more fun to do something that could potentially be useful (like an amazing screensaver <img src='http://pintant.cat/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) than something not so terribly useful.</p>
<p>If you are curious what the Mendeley screensaver does: it connects to Mendeley using the Open-API, fetches some stats, shows on the screen using a black background and green fixed-width font, with a scrolling up. It also shows a random paper from your library and a random paper from the Mendeley catalog.</p>
]]></content:encoded>
			<wfw:commentRss>http://pintant.cat/2011/09/11/screensaver-for-kde-using-python-and-pygame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

