Friday, May 28, 2010

[QnA] Use xmodmap to set modifier keys

In the previous article, I described how to change the modifier key for wmii from Mod1(Alt) to Mod4(Windows key). That's no problem for my PCs, but not okay for my laptop, an IBM X31. The laptop has NO Windows key, so I cannot just modify the wmiirc file to make things run.

Fortunately, Google helped me to find the solution again. There is a command called xmodmap to modify keymaps.

The steps are:
  • Create a file, for example, ~/.Xmodmap
  • Paste the following lines in the created file

  • ! No Caps Lock
    clear lock
    ! Caps Lock as Win key
    add mod4 = Caps_Lock

  • Run xmodmap to enable the settings

  • $ xmodmap ~/.Xmodmap

Edit (2010/06/01):

After changing Caps Lock key to Windows key, wmii cannot move windows to desktop#2.

[SW] Change modifier key for wmii

I have adopted wmii as my main WM for months and it has given pretty good experience in my daily usage. There has been one thing, however, bothering me a bit. The default modifier key of wmii is Alt, which is presented as Mod1 in wmiirc. Because Alt is a frequently used key for tools such as BASH, this default setting could cause some inconveniences. For example, when you want to move forward in BASH commands, Alt+F won't give you the expected moving but will make the working window run in full screen. Fortunately, wmii has been featured as its configurability.

In my system, which is Ubuntu 8.04, the confiuration files are located in

There are two files look like something to be the configureation file: rc.wmii and wmiirc. To make sure which one is used, use the following commands
ps aux | grep wmii | grep rc

In my case, it is the wmiirc file.

In the beginning of wmiirc, there are several lines which set the keys.

I set MODKEY from Mod1 to Mod4 which is the Windows key. Re-login and you can use wmii without the ``Alt conflict'' with many other programs.

Wednesday, May 26, 2010

[SW] Internet radio for Ubuntu

Rhythmbox was the software I used to listen music and internet radios. Due to reasons I don't understand, Rhythmbox does not work properly for the internet radios anymore, and I've tired to find out the solution. I started to search possible alternatives for me to listen internet radios. Firstly I found Exaile and it looked good, but I didn't get its plugin (shoutcast radio) work.

Finally, I found Tunapie. I installed it and Stremripper via Synaptic. After the installation, I set the audio player as VLC in Tunapie's preference, then everything goes well. :-)

(But Hot 108 Jamz station cannot be played... Orz)

Saturday, May 22, 2010

[Py] Use ``list comprehensions'' to avoid nesting ``for loops'' too deeply

As I have mentioned in the previous post, I am trying to analyze some data using Python as the programming language. The data sets are from 4 sensor nodes, and each nodes give accelerations in 3 axes. Furthermore, I want to process these data sets in sequential mode. So, the original structure of my program looked like this:

data = zeros((n_nodes,3))

for i in range( len(databuffer) ):
for nodes in range(4):
for xyz in range(3):
data[nodes][xyz] = databuffer[nodes][xyz][i]
if (some conditions):
do something

That's crazy! These nested for loops are too deep to be followed. Also, I remember once I read an article written by an experienced programmer, who said if your for loops nested too deep, then maybe you need to redesign you program.

I had no idea about how to redesign the structure of my program to fit my original requirements. Fortunately, the list comprehensions could resolve this difficulty. Here is the new version using the list comprehensions:

for i in range( len(databuffer[0][0]) ):
data = array([databuffer[nodes][xyz][i]\
for nodes in range(n_nodes) for xyz in range(3)]).reshape(n_nodes,3)
if(some conditions):
do something
The list comprehensions remove two loops and make a conciser new structure.

Thursday, May 20, 2010

[Py] Multi-dimensional list

So far, the list in Python has bothered me a lot. I think it's because I do not understand it enough. These days I've been writing a little program to analyze some data, and encountered unexpected situations which almost got me down.

One unexpected situation was the multi-dimensional list, or the list of lists. The following page describes exactly what had troubled me:

(An Unofficial) Python FAQ Wiki (old link)
How do I create a multidimensional list?

This surprised me and made me thought again: ``Do I really know how to program in Python?'' The answer is definitely no. The low threshold to begin Python programming made me overestimate my understanding of it. Therefore, I told myself to learn more before stepping further.

Another situation surprised me is also about the list creation. The following test shows it:

>>> a = b = [[]]*3
>>> a[1] = 1
>>> b
[[], 1, []]

To assign values to list a also affects list b. To avoid this situation, you should create the lists separately.

>>> a = [[]]*3
>>> b = [[]]*3
>>> a[1] = 1
>>> b
[[], [], []]

Monday, May 17, 2010

[Py] PyODE installation and test

I read about ODE (no, not the ODE in math) in a thesis last week, and searched it to see what it is. ODE is the abbreviation of Open Dynamic Engine, an library for simulating rigid body dynamics. As a Python fan, it's reasonable for me to search related module of ODE written in Python. The keywords ``python ode'' brought me the PyODE, a set of Python bindings for ODE.

There are three examples on the PyODE page. I tried to test it, and installed what my system lacked accordingly.

The installation in Ubuntu is quite easy as usual. My procedures are listed as the follows.

First, get the PyODE module, which is the basic one to run the 1st example:
$ sudo apt-get install python-pyode

Then if you want to run the 2nd example, you need Pygame:
$ sudo apt-get install python-pygame

Finally, the 3rd example demands PyOpenGL:
$ sudo apt-get install python-opengl

After these steps, I found the best way to get all these examples is to install the documents of PyODE:
$ sudo apt-get install python-pyode-doc

You could find the source code of all the three examples in

There are two more examples in the folder, but they needs more libraries. To run the ``'' example, the error message showed there was no module named ``cgtypes.'' It seems to be in the cgkit package. This package cannot be found in Ubuntu repository, so I downloaded the source and read the README. The SCons and Boost are necessary:
$ sudo apt-get install scons
$ sudo apt-get install libboost-dev

But I couldn't install the package and still get no luck so far.

I decide not to bother with the Scons and Boost by now. If I have some time, I would like to play with the original 3 examples to see whether I can learn something fun and useful from them.

When I ran the to install the package, there came lots of error messages. With some efforts, I noticed one of the error message read there was no file named ``boost/python.hpp.'' And with some more efforts, it came to me that maybe something like ``libboost-dev'' is needed. Therefore, I typed libboost in the terminal and used the Tab key to check available packages. Yes, there was a library named ``libboost-python-dev'' which looked like what I needed, so I installed it by typing:
$ sudo apt-get install libboost-python-dev

Then, everything was ready to install the cgkit in the downloaded and extracted folder:
$ sudo python install

The cgkit has been installed, though, the example cannot be executed correctly. According to the error message (ImportError: No module named cgtypes), I edited the line in the from
from cgtypes import *
from cgkit.cgtypes import *

After the modification, new problem emerged. The window showed up and then closed, with the eorror message given in the terminal:
freeglut ERROR: Function called without first calling 'glutInit'.

Then I found the page talking about this issue. So what I had to do was to find somewhere to put the glutInit function call. I tested for several times but totally had no idea where to add the glutInit, then I noticed the keyword in the error message: Function . It took me to the right location of the code to add a line as follows:
glutInit(argc, argv)

It didn't work and threw back a name error:
NameError: global name 'argc' is not defined

I thought there might be no argument for this function call in the code, so I deleted the argc and argv to make the glutInit be called as the following:

Bingo! Although I am still not sure whether the runs properly, at least the window showed up with several moving cubes inside.

By far, the problem to run the is solved. However, there is still an example code named cannot be run properly in my system. I have to do other works. Maybe I will come back to find out the solution for the