Archive

Posts Tagged ‘Python’

Nautilus enqueuer plugin for Rhythmbox - new and improved!

April 25th, 2010

It has been almost a year since I created my plugin to enqueue files into the Rhythmbox play queue from within Nautilus. I got feedback from several people across the globe regarding the plugin and the most common complaint that came across was that the plugin could not enqueue folders recursively. Also, when some files had embedded special characters, the plugin did not work as expected.

So, finally after a busy year, I sat down one evening and made the requested modifications to the plugin. Now it can handle folders recursively and also embedded special characters within file names. It is also intelligent enough to detect if a folder has zero music files and in that case the option to enqueue the folder itself would not come up. Another good  friend of mine gave a very good suggestion that the plugin should automatically detect the default player in Gnome and enqueue the files to that player. I think I shall take that up as an enhancement in the next version ;-)

So, here it is. Download and enjoy! Install instructions are same as before, which you can find in the original post. If you are already using the older version, then you just need to download this version, and replace the old one in your $HOME/.nautilus/python-extensions folder.

Last but not the least, I must thank all of you to have downloaded and tried my original plugin. But more thanks are due because of the fact that you took out time to give feedback. I know a year is late of me to have got back to you with the enhanced plugin, but things were quite hectic on my personal life as a result of which I got very little time for such activities.

admin Linux, Ubuntu , , , ,

A desktop notifier for new emails in your Gmail inbox for Ubuntu

June 11th, 2009

I have been fiddling with the Python programming language over the past few days.  And even though it has just been few weeks and I hardly have covered every aspect of the language in detail, I am already producing working code in python. In short, I am flying! Python really rocks!

So yesterday I thought it would be nice to be able to check my Gmail inbox for new incoming mails from the command line. So a little searching gave me this link.

This is a python script that does exactly what I wanted. But it runs from the command line and is interactive in that it asks for the user name and password from the user interactively. I went a step ahead and thought what if I can make this process automated and for every new mail, show up a notification. Speaking of notifications, you must be aware of the new OSD notification that is creating much buzz these days, especially in Ubuntu circles. This new notification system is designed to replace the existing notification system with a cooler UI and better usability. At least that’s what the canonical folks claim.

Anyway, I set out to create this cool notifier and in a few hours it was ready. Being a first timer to Python, it took some time as every now and then I would stop to see some documentation and then once I understood the concept, carried on hacking. Once complete, the next few minutes I spent in fine tuning the notifier, like add an image (the gmail logo of course!!).

Eureka!! It worked, Yippee !! That’s what I like most about Python. Even a complete newbie like me can create working code in such a short time! Having written the it, now I wanted to make it more user friendly. So the next day, I ended up writing a setup.py script to provide ease of installation. Believe me, writing this setup was far more difficult than the original notification script ! But because of this script, installation is super-easy. Just run the setup.py file, that’s it!

So finally, it was done. I did some minimal testing but it should work well. You may download this from here.

Steps to install:

0. First make sure you have the python bindings for notify-osd, the new notification system for Ubuntu. If not, then install it with the below command:

$ sudo apt-get install python-notify

1. Download, gunzip and untar the gmailnotifier.tar.gz file from the above link.
2. Go to the gmailnotifier folder so created and run the setup.py file.

$ ./setup.py

It will ask a few questions, like your gmail username, password, where you want to install the script and what should be the time interval in seconds to periodically check your mailbox for new mails. Make sure you answer those questions carefully and correctly. I have not added error checking for those questions yet :-|.

But if you feel anything is not correct, you may simply press Ctrl-C, abort the script and then run it from the beginning.

3. Now simply log off from gnome and then log back in. You are all set! That’s it. And don’t worry my setup script makes sure that the configuration file is not world-readable, since your Gmail password is there in plain text.

Enjoy ! In the event that you want to uninstall my script, you can do it manually(since uninstall option is not present in the setup.py script yet). Just open the file ~/.config/autostart/gmailnotifier.desktop in your favorite text editor. Note down the line which has an ‘Exec’ in it as the first word. That line would be something like:

Exec=/path/given/while/running/setup.py/gmailnotifier/gmailnotifier.py

Note down the path, excluding the gmailnotifier part. Here it would be

/path/given/while/running/setup.py

Go to that path and delete the gmailnotifier folder altogether. After that, close the ~/.config/autostart/gmailnotifier.desktop file and delete that also. That’s it.

And in case you are wondering how this looks like, here is a screenshot of it in my Ubuntu Jaunty installation. Look at the top right hand corner. It says I have 3 new mails.

gmailnotifier_in_action

Also, if you have not noticed by now, once installed my notifier script installs itself as a gnome startup program. If you go to ‘System->Preferences->Startup Applications’ you can see a new entry named ‘gmailnotifier’. Here is a screenshot of that too, just so that you don’t get surprised later when you see this new thing there all by itself.

gmailnotifier_installs_itself_as_a_startup_program

Read on if you want to know the technical details of my notifier. Basically my notifier depends on chiefly two main libraries - glib and pynotify. Glib is a general purpose library that is the foundation for GTK+ but more than that, it is a very high quality general purpose library that you can use freely in your other programs. Pynotify, on the other hand gives python bindings to the libnotify library.

In my script I first create a glib main loop. A main loop is an event loop that waits for events waiting indefinitely. Yeah, you guessed it, a glib main loop is at the heart of all GTK+ GUI applications which are fundamentally event driven and respond to mouse clicks, drags/drops and key events. But before I start the loop, I register for a timer callback every n seconds. This n is the interval the script would check your inbox for new mails.

This is one of the values you supply while running the setup script. Anyway, whenever this timer expires, the timer callback is called and this callback logs in, checks the Gmail RSS feed and informs you if there are any new mails. The point to be noted here is that new mails here mean mails that are ‘new’ to the script not to your inbox. Since this script does not mark new mails as read after displaying them, it maintains its own 2 buffers of old mails and new mails respectively. Any mail that is present in the new mail buffer but not in the old mail buffer is flagged as new and this count is what is shown in the the pop up.

As usual, comments/suggestions/bug reports are welcome if you liked my gmailnotifier!

admin Linux, Ubuntu , , ,

A nice little Nautilus plugin to enqueue audio files into Rhythmbox

May 19th, 2009

Nautilus is the default file manager in Gnome for Linux. And Rhythmbox is the official Gnome music player.  Rhythmbox supports many advanced features like Internet Radio, Library management, support for Apple iPod, DAAP shares and MTP to name a few.

So the other day, I had an idea to find a way to directly enqueue an audio file into the rhythmbox play queue. If you have used Winamp over windows, it is akin to the ‘Enqueue in Winamp’ option that windows explorer provides for audio files if you have installed Winamp in your machine and right clicked over any audio file.

So first I searched if such a Nautilus plugin was really already available. To my happiness I found one plugin, written in python for a similar use but for enqueueing into the playlist of the Audacious, another music player on Linux. So, I downloaded it, and after a few minutes of hacking, it was ready for rhythmbox. So I can’t take entire credit for creating this plugin ;-).

The only trouble I had was to find out which option to use with rhythmbox from the command line to import the audio file into the library AND enqueue it into tha play queue. The man page did not mention anything. Then I downloaded the entire rhythmbox source code and finally from the code was able to know how to achieve what I wanted.

So here it is. Click here to download the plugin, add-to-rhythmbox.py. Installing this plugin is really easy. Just follow the following steps:

1. First, install python-nautilus package which gives the python bindings for Nautilus:

sudo apt-get install python-nautilus

2. Create a folder called ‘python-extensions’ within .nautilus within your home folder. i.e if your home folder is /home/foobar then create /home/foobar/.nautilus/python-extensions.

3. Copy the downloaded script, `add-to-rhythmbox.py` into this python-extensions folder.


4. Restart nautilus with the command:

killall nautilus

That’s it. Now you can right click over any audio file and see the new option to enqueue that file into the rhythmbox play queue. Here is a screenshot of how it looks like:

Screenshot of my Nautilus plugin.

Screenshot of my Nautilus plugin to enqueue an audio file into Rhythmbox.

Hope this plugin would prove useful to all you Linux/Gnome users. Ideally I should have written this using dbus but was too lazy to do so. Maybe next time I would do that and post version 0.2. ;-)

Until my next post, g’bye and take care!

admin Linux, Ubuntu , , , ,