<?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>Smörgåsbord &#187; lirc</title>
	<atom:link href="http://smorgasbord.gavagai.nl/tags/lirc/feed/" rel="self" type="application/rss+xml" />
	<link>http://smorgasbord.gavagai.nl</link>
	<description>Ambachtelijk bereide beschouwingen.</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:17:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>LIRC plugin for Exaile</title>
		<link>http://smorgasbord.gavagai.nl/2009/12/lirc-plugin-for-exaile/</link>
		<comments>http://smorgasbord.gavagai.nl/2009/12/lirc-plugin-for-exaile/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 01:44:58 +0000</pubDate>
		<dc:creator>Wicher</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[en_GB]]></category>
		<category><![CDATA[exaile]]></category>
		<category><![CDATA[lirc]]></category>
		<category><![CDATA[lircaile]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://smorgasbord.gavagai.nl/?p=718</guid>
		<description><![CDATA[Just finished up a 0.1 version of a LIRC (Linux Infrared Control) plugin for the Exaile media player. Now you can use your remote with Exaile efficiently. The plugin is in the public repository and is called Lircaile.
I haven&#8217;t touched Python much as of yet, but I&#8217;m pleased with it: it appears to be a [...]]]></description>
			<content:encoded><![CDATA[<p>Just finished up a 0.1 version of a <a href="http://lirc.org">LIRC</a> (Linux Infrared Control) plugin for the <a href="http://exaile.org/">Exaile media player</a>. Now you can use your remote with Exaile efficiently. The plugin is in <a href="http://smormedia.gavagai.nl/dist/">the public repository</a> and is called Lircaile.<br />
I haven&#8217;t touched Python much as of yet, but I&#8217;m pleased with it: it appears to be a consistent language. Well, here&#8217;s my 0.1 effort. I desperately wanted to have some fun with introspection, but I have the feeling the nested exception logic is a bit&#8230; unusual.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># A LIRC plugin for Exaile. Depends on pylirc from http://sourceforge.net/projects/pylirc/</span>
<span style="color: #808080; font-style: italic;"># Copyright (C) 2009 Wicher Minnaard, http://smorgasbord.gavagai.nl / wicher@gavagai.eu</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># This program is free software: you can redistribute it and/or modify</span>
<span style="color: #808080; font-style: italic;"># it under the terms of the GNU General Public License as published by</span>
<span style="color: #808080; font-style: italic;"># the Free Software Foundation, either version 3 of the License, or</span>
<span style="color: #808080; font-style: italic;"># (at your option) any later version.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> xl <span style="color: #ff7700;font-weight:bold;">import</span> playlist, player, event
<span style="color: #ff7700;font-weight:bold;">import</span> pylirc, <span style="color: #dc143c;">logging</span>
&nbsp;
LIRCAILE = <span style="color: #008000;">None</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> enable<span style="color: black;">&#40;</span>exaile<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>exaile.<span style="color: black;">loading</span><span style="color: black;">&#41;</span>:
        event.<span style="color: black;">add_callback</span><span style="color: black;">&#40;</span>_enable, <span style="color: #483d8b;">'exaile_loaded'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        _enable<span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, exaile, <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _enable<span style="color: black;">&#40;</span>eventname, exaile, nothing<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">global</span> LIRCAILE
  LIRCAILE = Lircaile<span style="color: black;">&#40;</span>exaile<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> disable<span style="color: black;">&#40;</span>exaile<span style="color: black;">&#41;</span>:
  pylirc.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Lircaile<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> polLirc<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Pops all queued signals off of the LIRC queue and hands them to
    handleCode() for further processing.&quot;&quot;&quot;</span>
    gopoll = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">while</span><span style="color: black;">&#40;</span>gopoll<span style="color: black;">&#41;</span>:
      <span style="color: #dc143c;">code</span> = <span style="color: black;">&#40;</span>pylirc.<span style="color: black;">nextcode</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">code</span><span style="color: black;">&#41;</span>:
        comval = <span style="color: #dc143c;">code</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>comval<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
          <span style="color: #008000;">self</span>.<span style="color: black;">handleCode</span><span style="color: black;">&#40;</span>comval<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>          
        <span style="color: #ff7700;font-weight:bold;">else</span>:
          <span style="color: #008000;">self</span>.<span style="color: black;">handleCode</span><span style="color: black;">&#40;</span>comval<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, comval<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #808080; font-style: italic;"># We're done, the queue is empty.</span>
        gopoll = <span style="color: #008000;">False</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, exaile<span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">exaile</span> = exaile
    <span style="color: #008000;">self</span>.<span style="color: black;">logger</span> = <span style="color: #dc143c;">logging</span>.<span style="color: black;">getLogger</span><span style="color: black;">&#40;</span>__name__<span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">socket</span> = pylirc.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'lircaile'</span><span style="color: black;">&#41;</span>
    event.<span style="color: black;">EventTimer</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0.05</span>, <span style="color: #008000;">self</span>.<span style="color: black;">polLirc</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> handleCode<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, command, <span style="color: #66cc66;">*</span>arg<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Takes LIRC signals and uses introspection to try to find appropriate 
    exaile functions to call based on the name of the signal. &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>command == <span style="color: #483d8b;">'chvol'</span><span style="color: black;">&#41;</span>:
      <span style="color: #008000;">self</span>.<span style="color: black;">exaile</span>.<span style="color: black;">player</span>.<span style="color: black;">set_volume</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">exaile</span>.<span style="color: black;">player</span>.<span style="color: black;">get_volume</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>arg<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
      func = <span style="color: #008000;">None</span>
      <span style="color: #808080; font-style: italic;"># Look for a matching playlist function</span>
      <span style="color: #ff7700;font-weight:bold;">try</span>:
        func = <span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">exaile</span>.<span style="color: black;">queue</span>, command<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">AttributeError</span>:
        <span style="color: #808080; font-style: italic;"># No? Then look for a matching player function</span>
        <span style="color: #ff7700;font-weight:bold;">try</span>:
          func = <span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">exaile</span>.<span style="color: black;">player</span>, command<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">AttributeError</span>:
          <span style="color: #808080; font-style: italic;"># No? Then we're out of options</span>
          <span style="color: #008000;">self</span>.<span style="color: black;">logger</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'No function to handle &quot;'</span>+ command +<span style="color: #483d8b;">'&quot; LIRC event'</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">callable</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
        func<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://smorgasbord.gavagai.nl/2009/12/lirc-plugin-for-exaile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
