PDA

View Full Version : Python dbus



matmatmat
March 13th, 2009, 05:25 PM
Does anyone know how to use dbus in python? I'm trying to do this:


dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Pause

only in python.
Thanks in advanced.

imdano
March 13th, 2009, 06:18 PM
It'll look something like this
import dbus
bus = dbus.SessionBus()
proxy_obj = bus.get_object("org.kde.amarok", "/org/freedesktop/MediaPlayer")
player = dbus.Interface(proxy_obj, "org.freedesktop.MediaPlayer")
player.Pause()This is untested, and there's a decent chance I mixed up object name vs well-known name or something like that, so it may give you an error.

See the python-dbus tutorial: http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html

matmatmat
March 14th, 2009, 11:28 AM
Thanks for the reply, I ran it & it gave this error:


dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/freedesktop/MediaPlayer'

?

imdano
March 14th, 2009, 06:05 PM
Like I said, it's untested. Try using /Player instead.

eightmillion
March 15th, 2009, 12:42 AM
This code will work:



import dbus
bus = dbus.SessionBus()
player = bus.get_object("org.kde.amarok", "/Player")
player.Pause()

matmatmat
March 15th, 2009, 09:30 AM
Thanks, it worked!