[PyQt] PyKDE4, KApplication and DBus

Wilbert Berendsen wbsoft at xs4all.nl
Fri Oct 31 18:29:24 GMT 2008


Op vrijdag 31 oktober 2008, schreef Adeodato Simó:
> * Wilbert Berendsen [Tue, 28 Oct 2008 16:45:41 +0100]:
> > Hi,
> >
> > I am writing a kde application in PyKDE4 that embeds katepart and okular.
> > That works fine, but I also want to export my own DBus object to
> > implement a simple general methods (like openUrl) for my app.
> >
> > Currently KApplication, KatePart etc. all register their objects under
> > the bus-name "org.myapplication-$pid". where 'myapplication' is set from
> > the homepage URL in the aboutData.
> >
> > But it seems I can't get my own object (created using dbus-python) under
> > the same bus name.
> >
> > Is there  a way to add my own (dbus-python) object to the existing
> > busname that is registered by KApplication?
>
> AFAICS that's not going to be possible because the dbus-python bindings
> forbid the '-' character in interface names:
>   >>> import dbus
>   >>> dbus.validate_interface_name('foo.bar.org-1')
>
>   Traceback (most recent call last):
>     File "<stdin>", line 1, in <module>
>   ValueError: Invalid interface or error name 'foo.bar.org-1': contains
> invalid character '-'

No, that's not the problem, it's not the interface name, it's the bus name!
I can perfectly register my app under a bus name like 'org.myapp-bla-14345'.
But Qt already opens a named dbus connection like 'org.myapp-14345' and I
want to use the same connection to register my own D-Bus objects via dbus-python.

class App(dbus.service.Object):
    def __init__(self):
        bus_name = dbus.service.BusName("org.myapp-%s" % os.getpid() , bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/MyApp")

    @dbus.service.method("HelloInterface", in_signature='', out_signature='')
    def sayHello(self):
        print "Hello!"

But using this approach it seems not to be possible to add my /MyApp object 
under the bus name KApplication already opens. As soon as I open a dbus
connection using dbus-python under the same name as the KDE app already
itself has opened, It will remain nameless and I can't register my own objects
under the bus name opened by KApplication.

So currently the users of my app can call methods on the embedded KParts 
via org.myapp-1234 and for my own Python D-Bus objects I have to use another 
bus name. It's not a big deal but it would be nice if my app just opened one 
named dbus connection.

with best regards,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
        -- Mahatma Gandhi


More information about the PyQt mailing list