wmii python dbus and rhythmbox
I have been playing with wmii and the python binding for wmii pywmii. It's going to allow me to do some funky things with my window manager. All a little too geeky really but a bit of a challange.
Pywmii is a set of classes for accessing the controls of the wmii using python rather than the usual shell script. This allows you to add functionallity to your window manager by simple python scripting.
I have installed the pywmii stuff by just copying 'wmii.py' and 'P9.py' to my $HOME/.wmii-3.5 dir along with the example 'wmiirc' and 'keybindings.pywmii' files and after some fiddling so that it did not use the Windows key as I don't have one on my laptop, I have it all working okay. It's good enough I can get going with other stuff.
Next was to add some keyboard short cuts to pause rhythmbox and put the track on the status bar.
First to the status bar. Replacing the example status function with my one did the trick as shown below
def myStatusFunc(w):
load = commands.getoutput("uptime")
load = load.split(":")[-1].strip().replace(",","")
rbp = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
rbs = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell')
uri = rbp.getPlayingUri()
song = rbs.getSongProperties(uri)
songstr = "%s - %s (%s)" % (song[u'artist'],song[u'title'],song[u'album'])
return songstr + " || " + load + " || " + time.asctime()
This assumes that you have done an 'import dbus' and a 'bus = dbus.SessionBus()' some point before that. Now you should see the currently playing track in the status bar at the bottom along with some other info. It uses dbus to communicate with the running rhythbox and grab the releven info.
Now to the pause and play shortcut. I added the following functions to the WMII class that is defined in my wmiirc:
def rhythmbox_playPause(self):
rbp = self.dbus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
rbp.playPause(True)
def rhythmbox_increaceVolume(self):
rbp = self.dbus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
rbp.setVolumeRelative(0.1)
def rhythmbox_decreaceVolume(self):
rbp = self.dbus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
rbp.setVolumeRelative(-0.1)
I also added an init function to setup the dbus functions:
def __init__(self):
self.dbus=dbus.SessionBus()
WMII.__init__(self)
Now when you call 'wmii.playPause()' rhythmbox will stop and start. So just add that to your 'keybindings.pywmii' and you are good to go:
Mod1-q = wmii.playPause
Now you can do the same with the volume commands as well.
To find out what dbus functions are available you have to look at the source xml file from rhythbox available from svn as http://svn.gnome.org/viewcvs/rhythmbox/trunk/shell/rb-shell-player.xml?view=markup and http://svn.gnome.org/viewcvs/rhythmbox/trunk/shell/rb-shell.xml?view=markup.