hugosenari / mpris2

mpris2 python usable definition
26 stars 3 forks source link

D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor #1

Closed pat1 closed 9 years ago

pat1 commented 11 years ago

running this simple python coming from examples:

!/usr/bin/env python

from mpris2.player import Player from mpris2.interfaces import Interfaces from dbus.mainloop.glib import DBusGMainLoop import gobject

uri = Interfaces.MEDIA_PLAYER + '.' +'AutoPlayer' mp2 = Player(dbus_interface_info={'dbus_uri': uri})

Call methods

mp2.Next() # play next media

Get attributes

print mp2.Metadata #current media data

Wait signal

def handler(self, _args, *_kw): print args, kw

DBusGMainLoop(set_as_default=True) mloop = gobject.MainLoop() mp2.PropertiesChanged = handler mloop.run()

python cl.py

{dbus.String(u'mpris:trackid'): dbus.String(u'36')} Traceback (most recent call last): File "cl.py", line 29, in mp2.PropertiesChanged = handler File "/home/pat1/svn/autoradio/trunk/autoplayer/pydbusdecorator/dbus_signal.py", line 76, in set self._watch_dbus(obj, _args, _kw) File "/home/pat1/svn/autoradio/trunk/autoplayer/pydbusdecorator/dbus_signal.py", line 41, in _watch_dbus _args, _kw) File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 534, in connect_to_signal dbus_interface, _keywords) File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 362, in connect_to_signal _keywords) File "/usr/lib/python2.7/site-packages/dbus/bus.py", line 151, in add_signal_receiver path, **keywords) File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 384, in add_signal_receiver self._require_main_loop() RuntimeError: To make asynchronous calls, receive signals or export objects, D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor or calling dbus.set_default_main_loop(...)

pat1 commented 11 years ago

If I understand no access to dbus have to be done before setting main loop. This code works:

!/usr/bin/env python

from mpris2.player import Player from mpris2.interfaces import Interfaces from mpris2.some_players import Some_Players from mpris2.utils import get_players_uri from dbus.mainloop.glib import DBusGMainLoop from mpris2.utils import get_session

def handler(self, _args, *_kw): print args, kw

DBusGMainLoop(set_as_default=True) import gobject
mloop = gobject.MainLoop()

uris = get_players_uri(pattern=".")

if len(uris) >0 : uri=uris[0] print uri mp2 = Player(dbus_interface_info={'dbus_uri': uri})

mp2.PropertiesChanged = handler
mloop.run()

else: print "No players available"

hugosenari commented 11 years ago

Hi,

Thanks, I will look for this.

edit: You can access properties and methods but to set callback (mp2.PropertiesChanged = handler) you need set up dbus and mainloop first. :(

[]'s Hugo