Friday, February 4, 2011

Python Sound Menu Integration or GDBUS Can't Come Soon Enough

So I'm still digging Pithos. Having native access to my Pandora channel on my desktop is a blast. I thought a great enhancement would be Sound Menu integration. So I figured I would spend an hour or two implementing an the mpris2 dbus interface to make this work for Pithos.

Well, the platform had this to say to me: "Ha ha ha ha ha"

It seems simple enough, if you implement the Impres2 interface, you get Sound Menu integration, along with other benefits. Well, it turns out that implementing such an interface in Python is an exercise in frustration.
  1. There is little documentation on how to implement a dbus interface in Python.
  2. So far as I can tell, there is no way to decorate a property to make it a dbus property, and there is not documentation on how to work around this.
  3. After working around how to make properties, one is exposed to all kinds of weird dbus internals. For example, you can't just return a dictionary, you have to send a dbus.Dictionary object.
Fortunately, I know people who could help and get me unstuck. So, as of today, I have some stub code that makes something useful show up in the Sound Menu.

So what's next? Well, I intend to turn this code into a Python API for the Sound Menu. I'm not going to try to handle the whole mpris2 integration at this point, just implement what is needed for the sound menu to work. The API should not expose any DBUS or MPRIS concepts.

Then I'll see if I can use my API to add Sound Menu integration to Pithos. Also, I should be able to use simple-player as a demo for it.

So, if you are a Python hacker, and you want to get something into the Sound Menu, stay tuned, I should be able to help you out soonish. The code is still all stub code, but if you absolutely must look, I pushed a branch.

7 comments:

  1. Actually, you can return python dicts, no need to wrap them into dbus.Dictionary. All you have to do is to use the 'out_signature' argument of the dbus.service.method decorator, like

    @dbus.service.method("some.iface", out_signature="a{ss}")
    def return_dict(self): return {"Hallo": "world"}

    ReplyDelete
  2. @thekorn -
    mrpis2 requies the use of dbus properties in addition to functions. For example, Metadata is a dbus property, not a dbus method, so it gets returned from the get function which implements dbus.PROPERTIES_IFACE.

    If there is a way to decorate properties in Python so they become dbus properties, please let me know, but I sure couldn't find it, and neither could several folks trying to help me.

    ReplyDelete
  3. Check out how I'm doing it in lp:ubuntuone-music ;)

    ReplyDelete
  4. So nice and great blog post about rain it's also helpful information all of us so thanks a lot for sharing this tips with us
    clipping path service

    ReplyDelete
  5. Your explanation about Dbus to turn inti API for a sound system is in detail. Thanks for the informative blog.

    ReplyDelete