python dbus objects problem

Mr misha volk anath3ma at yahoo.com
Fri Mar 14 11:13:14 PDT 2008


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'

--- producer program ---

#!/usr/bin/env python

import gtk
import dbus
import dbus.service
import dbus.glib

class AnotherClass ():
  @dbus.service.method('org.test.helloservice')
  def Hi (self):
    return "hi"

class MyDBUSService(dbus.service.Object):
        def __init__(self):
                bus_name =
dbus.service.BusName('org.test.helloservice',
bus=dbus.SessionBus())
                dbus.service.Object.__init__(self,
bus_name,
'/org/test/helloservice')
                self.ac = AnotherClass ()

        @dbus.service.method('org.test.helloservice')
        def hello(self):
                return "Hello,World!"

myservice = MyDBUSService()

print myservice.hello () # prints "Hello,World!"
successfully 
print myservice.ac.Hi () # prints "hi" successfully 

gtk.main()



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping


More information about the dbus mailing list