Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to listen to the key press of lets say Ctrl+W in Rhythmbox, and call a functions if that happens. How can I do that in Python ?

share|improve this question
up vote 3 down vote accepted

I assume that you are creating some sort of plugin. Plugins can be written in C or Python. I don't know how to do this but I know where you could possibly find out this information:

  1. The documentation for creating plugins.
  2. The API documentation.
  3. Asking on the rhythmbox-devel mailing list (
  4. Asking on the IRC channel (#rhythmbox on
share|improve this answer

Here's a base to get started:

import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
def on_visibility_changed(visible): if visible: print "Rhythmbox Shown" else: print "Rhythmbox Hidden"
bus = dbus.SessionBus() rhythmbox = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell') rhythmbox = dbus.Interface(rhythmbox, 'org.gnome.Rhythmbox.Shell')
rhythmbox.connect_to_signal("visibilityChanged", on_visibility_changed)
loop = gobject.MainLoop()

The two important bits are defining the function, see the API docs for what arguments it should accept, and connecting the signal to it. Again, the API lists those signals.

If you want to catch a signal defined in RBPlayer, for example, you'd connect yoru session bus to Player, instead of Shell. Unfortunately, the API is rather complex and not easily explained here. Have a good rummage through the Documentation, and you'll probably find what you need.

share|improve this answer
Perhaps I should rather be using glib for the main loop, but I think everything that goes beyond the scope of this and @dv3500ea's answer belongs on – Stefano Palazzo Jan 2 '11 at 12:31
i wansn't looking for connection to the dbus , seems like it can be done by from within thte rhythmbox , – Bunny Rabbit Jan 5 '11 at 17:30
oops, it doesn't work for me - Have you any ideas why? – Копать_Шо_я_нашел Aug 27 '13 at 15:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.