python dbus objects problem

John (J5) Palmieri johnp at redhat.com
Mon Mar 17 19:36:52 PDT 2008


On Fri, 2008-03-14 at 11:13 -0700, Mr misha volk wrote:
> As context, im a c coder.  This is my first program in
> python, and my
> first time using dbus.  Hopefully that means that my
> problem is
> braindead simple.  Personally, i've been hacking away
> at it for a day
> with no luck.
> 
> That said, how do i fix the failure notice in the
> following:
> 
> Is there a way to fix it, or does dbus limit you to
> only those methods
> explicitly defined in exported objects?
> 
> tia,
> michael
> 
> --- consumer program ---
> 
> #!/usr/bin/env python
> 
> import dbus
> 
> bus = dbus.SessionBus()
> 
> helloservice = bus.get_object('org.test.helloservice',
> '/org/test/helloservice')
> hello_interface = dbus.Interface(helloservice,
> dbus_interface='org.test.helloservice')
> 
> print hello_interface.hello ()  # prints
> "Hello,World!" successfully 
> print hello_interface.ac.Hi ()  # fails with:
> AttributeError:
> _ProxyMethod instance has no attribute 'Hi'
> 

You can't do this with the bindings.  hello_interface.ac is translated
by the proxy as saying give me the callable object for the D-Bus method
ac (methods in Python are all callable objects).  So then you take a
callable object and try to call the method Hi which it doesn't have.

When you call get_object in the bindings it isn't really returning you a
remote object.  It is returning you a proxy into that object.  In other
words it is an object that knows how to send messages to the remote
object.  It has little knowledge of the remote objects internals so you
can't actually attach an object as the property of another object and
you can't directly access member variables.  Properties are supported in
D-Bus but only through getter and setter methods and not yet implemented
in the Python bindings as far as I know.  Even then you couldn't send a
proxy over (though you could send an object path and construct a proxy
from that).

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list