Controlling vagalume client using python

I've recently been playing with the docky python bindings, and started by writing a helper to interact with Vagalume, a lightweight client (I later added it to a project on launchpad). The vagalume DBus methods and signals are mostly undocumented, but they can be found lurking around after a quick look at some of the source code.

import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop

class Vagalume(object):
    def __init__(self):
        self.bus = dbus.SessionBus()

        self.player = self.bus.get_object('com.igalia.vagalume',


    def song_changed(self, *args):
        state = args[0]
        if state == 'stopped':
            #do something when the player is stopped
        elif state == 'playing':
            artist = args [1]
            title = args [2]
            album = args [3]
            #do something with the data here...
            self.playing(artist, title, album)

    def stopped(self):
        '''Run when music is stopped'''

    def playing(self, artist, title, album):
        '''Run when new song is played'''

if __name__ == "__main__":
    app = Vagalume()

    # gtk mainloop can be used if you're using this as part of a gtk app
    mainloop = gobject.MainLoop(is_running=True)

You'll probably notice the method song_changed. This is a method which is registered with DBus and run each time the 'notify' signal is emitted from vagalume. This checks whether the notification is due to vagalume starting a new song or stopping the current one and runs either self.stopped or self.playing. These two methods by default do nothing, so subclassing Vagalume to make them do something useful is good:

class MyFancyVagalume(Vagalume):
    def stopped(self):
        print 'just stopped the beat'

    def playing(self, artist, title, album):
        print 'now playing "%s" by %s' % (title, artist)

To interact with vagalume do something like:

vagalume = Vagalume()

# do anything you want with dbus

take a look at the source ( for all of the functions available

© Louis Taylor. Index ¦ Archives ¦ Pelican ¦ Theme.