Python – Ubuntu App Indicator

Python yet again

Well, yesterday was a really interesting day. So interesting that I only left my place to get some food. It was all research, programming and testing. Well, not all, but most of it. At the end of the day, I didn’t achieve what I was looking for, but did come up with a temporary solution. And as a result, I had only about 3 hours of sleep until now. I’m going to crash just after writing this blog post.

UPDATE : The post is no longer relevant since the issue mentioned in this post has been fixed in a kernel upgrade (i think 3.8.0-27), but still can be used as a reference on how to write a simple app indicator

Okay, flash back! I had installed Ubuntu 13.04 a while back, just after 2 days of it’s release on April 25th of this year. Anyways, the install went well, but many things that used to work on my 12.04 had broken in this release. Of course, this is a new release and I hoped that upcoming (kernel) updates would fix the problems, but after two months, my problems persisted. The most nagging of these problems were the “Dummy Output” sound problem and the lack of control over brightness. I had to use alsa force-reload every time on boot and it wasn’t nice. Funnily enough, the solution was very simple. I had never noticed this during my search for an answer to fix this problem, but I did yesterday. I just had to disable the Speech Dispatcher from running. /etc/defult/speech-dispatcher file and change RUN=yes to RUN=no .

Alright, so since the sound is fixed, we can come to the second problem, which is the lack of brightness control. I had encountered this problem before in 10.04 release years ago, but 12.04 worked perfectly out of the box. I never cared about it until now. I had to save my battery from draining out. And my eyes from getting blown up too. So, I started searching. And this continued for a few hours, trying to find if there’s some PPA or some work around that someone has already posted. I visited the Ubuntu IRC channel, and I must say hat they have been very helpful. Anyway, at the end of the day, the only thing I had in my hand was a command

So, anyway, I knew what I had to do to get it working. Ubuntu for some reason was using dell_backlight instead of intel_backlight. The first thing that came to my mind was writing an app in C++ and I did. I opened my QT Creator and made a small app that uses a slider and modifies the above said file. I set the values as said in this answer at Askubuntu. But that isn’t enough. I had to edit a file owned by root. So, either I had to change the group for the backlight file or make my app run as root. I had to search for different methods. Some said that setting the SUID bit does the trick, but unfortunately, it didn’t. Then I read about PAM (Pluggable Authentication Module), and got it running, but again, I encountered some problems. Finally, I had to opt for a very simple solution. Frankly, I didn’t like this much, but it was the simplest. Allow write access to the backlight file for all users. Yes. That’s right. I added the command

to the /etc/rc.local file, since the permissions are reset on every boot. So, now, my little app worked. And by little, I mean, really little. The interface has nothing but a slider. Here’s a screenshot.

Simple QT C++ Brightness SliderSee, I wasn’t kidding when I said it’s really small. But then again, that’s all I wanted. But using this app was difficult. I would have to open it every time I needed to adjust brightness. So what’s the solution? An app indicator sounds good right. The best thing is that it is accessible. So I rushed to the Ubuntu Developers page for App Indicators which contains some nice examples. I borrowed the PyGTK example and built my indicator on top of it. Unfortunately, I couldn’t add a slider or a spinner widget as a menu item. I’m still searching for ways to do this. So the next best thing I could do was to add steps 1-10. I had to pre-define the brightness values for each step in a list. Anyways, once it was done, it looked like this.

Brightness Indicator

I’m also thinking of making a configuration file to put the maximum and minimum values retrieved from the backlight file. But that is for another day. For now, here’s the source if you want. It’s pretty self explanatory and if it is not, it’s commented to give a little description.

Now, if you want this to work, you will have to do some things first. The first and foremost thing is to make the backlight file writable for regular users at every reboot. So add the the following line just above the  exit 0  in the /etc/rc.local file.

The next thing I did was to move my python source file to /usr/bin so that I don’t have to use the entire path to run it. Also, don’t forget to make the file executable.

Finally, I added the file to my start-up applications (Just type “startup” in dash to get the Startup Applications window). Click Add and fill in the details. Screenshot

Add to startupAnd there we have it! The next reboot, a new brightness indicator in your panel as shown in one of the images above. That’s it for now.


Seriously Crazy.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">