0

im having trouble with Gobject Introspection in Python. Im trying to access Rhythmbox via DBUS and i can access the methods inside of org.mpris.MediaPlayer2.Player, but i am trying to set values for the attributes of org.mpris.MediaPlayer2.Player, which is not working for me.

from gi.repository import Gio
connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
player = Gio.DBusProxy.new_sync(connection, 0, None, 'org.gnome.Rhythmbox3', '/org/mpris/MediaPlayer2', 'org.mpris.MediaPlayer2.Player', None)

properties = Gio.DBusProxy.new_sync(connection, 0, None, 'org.gnome.Rhythmbox3', '/org/mpris/MediaPlayer2', 'org.freedesktop.DBus.Properties', None)

I can use methods like player.PlayPause(). When i am trying

       properties.Set('org.mpris.MediaPlayer2.Player.rhythmbox', 'Volume', data)

I receive an error message:

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
  File "/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 626, in _doReadOrWrite
    why = selectable.doRead()
--- <exception caught here> ---
  File "/usr/lib/python2.7/site-packages/twisted/internet/udp.py", line 147, in doRead
    self.protocol.datagramReceived(data, addr)
  File "RhythmboxDbus.py", line 27, in datagramReceived
    properties.Set('org.mpris.MediaPlayer2.Player.rhythmbox', 'Volume', data)
  File "/usr/lib/python2.7/site-packages/gi/overrides/Gio.py", line 156, in __call__
    arg_variant = GLib.Variant(signature, tuple(args))
  File "/usr/lib/python2.7/site-packages/gi/overrides/GLib.py", line 185, in __new__
    (v, rest_format, _) = creator._create(format_string, [value])
  File "/usr/lib/python2.7/site-packages/gi/overrides/GLib.py", line 68, in _create
    v = constructor(args[0])
  File "/usr/lib/python2.7/site-packages/gi/types.py", line 76, in constructor
    return info.invoke(cls, *args, **kwargs)
exceptions.TypeError: Must be string, not tuple
Small Zane
  • 33
  • 4
  • Data is a String containing numbers between 0 and 100 – Small Zane Nov 13 '12 at 20:10
  • The question [MPRIS + Python (dbus): reading and writing properties](http://stackoverflow.com/questions/9493494/mpris-python-dbus-reading-and-writing-properties) is similar to your problem and has a solution using the `dbus` package. It may be helpful in that you may be able to port the solution there to a `gi` based solution. – Pedro Romano Nov 13 '12 at 20:32
  • @Small Zane - It looks like you're using DBus from within a Twisted application. There's an alternative to python-dbus for Twisted that you might want to consider: http://pypi.python.org/pypi/txdbus/1.0 – Rakis Nov 16 '12 at 15:45

0 Answers0