What kind of signature for this special method?
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Oct 13 05:43:45 PDT 2006
On Fri, 13 Oct 2006 at 10:32:45 +0200, Luigi Paioro wrote:
> class Hello(dbus.service.Object):
> def __init__(self, bus_name, object_path = '/my/example/Hello'):
> dbus.service.Object.__init__(self, bus_name, object_path)
>
> @dbus.service.method("my.example.Hello")
> def mySpecialMethod(self, **args):
> # something here with args dictionary
That's not something you can express in a D-Bus signature. Instead, use
a dict:
class Hello(dbus.service.Object):
def __init__(self, bus_name, object_path = '/my/example/Hello'):
dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.method("my.example.Hello", in_signature='a{sv}',
out_signature='')
def mySpecialMethod(self, args):
# something here with args dictionary
If you particularly need to have the "kwargs" style available from
Python, you could implement one version intended to be called from
Python and one version exported onto the bus, and have one call the
other:
class Hello(dbus.service.Object):
def __init__(self, bus_name, object_path = '/my/example/Hello'):
dbus.service.Object.__init__(self, bus_name, object_path)
def my_special_method(self, **kwargs):
# something here with args dictionary
@dbus.service.method("my.example.Hello", in_signature='a{sv}',
out_signature='')
def MySpecialMethod(self, args):
self.my_special_method(**args)
> Ah, another question...
>
> I was trying to have the object attributes accessible via a D-Bus proxy
> (we already had a discussion on this topic) exporting __getattr__ and
> __setattr__ as normal service methods, but it doesn't work (maybe for
> you it is obvious but for me it wasn't and I did an attempt). Do you
> have an idea on how to obtain the object attributes exported with a trick?
There is a standard D-Bus interface for objects with properties. If
Python code is exporting objects, you could implement that interface in
terms of __getattr__ and __setattr__. I'll bear this use case in mind
when improving the dbus-python API.
Regards,
Simon
More information about the dbus
mailing list