Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

2 Answers 2

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 (rhythmbox-devel@lists.gnome.org)
  4. Asking on the IRC channel (#rhythmbox on irc.gimp.net)
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"
DBusGMainLoop(set_as_default=True)
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() loop.run()

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
1  
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 StackOverflow.com –  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 - s019.radikal.ru/i637/1308/de/7755eda77ba3.png Have you any ideas why? –  gekannt Aug 27 '13 at 15:32

Your Answer

 
discard

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.