New to D-BUS; signals in Python bindings

John (J5) Palmieri johnp at redhat.com
Mon Apr 17 16:19:10 PDT 2006


Hmm, perhaps we should be able to take an interface as the interface
name but in your case you don't need to send the interface name in since
you are using the same interface name as the interface itself:

class Interface:
    def connect_to_signal(self, signal_name, handler_function, dbus_interface = None, **keywords):
        if not dbus_interface:
            dbus_interface = self._dbus_interface

so 

iface1.connect_to_signal("HelloSignal", print_message)

would suffice. Of course you could also do

iface1.connect_to_signal("HelloSignal", print_message, 'org.freedesktop.HelloWorldIFace')

but that would be redundant. 

On Thu, 2006-03-30 at 11:24 +0200, Luigi Paioro wrote:
> Hello!
> 
> I'm brand-new to DBUS developping and for the time being I'm only doing some 
> tests. I have SuSE Linux 10.0 with the default DBUS installed (0.42 I think), 
> and I'm trying to make a simple HelloWorldObject program (with Python 
> bindings) that puts on the bus this object and emits a signal. Another 
> program named HelloWorldCall, listen for this signal and, once it receives 
> the notification, prints the signal argument (just a message). Basing on the 
> Tutorial, I've written this simple code:
> 
> ### HelloWorldObject.py ###
> 
> import gobject
> import dbus
> import dbus.service
> 
> if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
>     import dbus.glib
> 
> class HelloWorldObject(dbus.service.Object):
>     def __init__(self, bus_name, 	
>                         object_path='/org/freedesktop/HelloWorldObject'):
>         dbus.service.Object.__init__(self, bus_name, object_path)
> 
>     @dbus.service.signal('org.freedesktop.HelloWorldIFace')
>     def HelloSignal(self, message):
>         pass
> 
> session_bus = dbus.SessionBus()
> bus_name = dbus.service.BusName('org.freedesktop.HelloWorld', bus=session_bus)
> object = HelloWorldObject(bus_name)
> 
> global i
> i=0
> 
> def emit():
>     global i
>     i+=1
>     object.HelloSignal("Seconds: %d" % i)
> 
> gobject.timeout_add(1000, emit)
> 
> mainloop = gobject.MainLoop()
> mainloop.run()
> 
> 
> ### HelloWorldCall.py ###
> 
> import dbus
> import gobject
> 
> bus = dbus.SessionBus()
> 
> proxy_obj1 = 
> bus.get_object('org.freedesktop.HelloWorld','/org/freedesktop/HelloWorldObject')
> iface1 = dbus.Interface(proxy_obj1, 'org.freedesktop.HelloWorldIFace')
> 
> def print_message(message):
>     print message
> 
> iface1.connect_to_signal("HelloSignal", print_message, iface1)
> 
> mainloop = gobject.MainLoop()
> mainloop.run()
> 
> ##########
> 
> When I run this code, HelloWorldCall.py returns this error:
> 
> Traceback (most recent call last):
>   File "HelloWorldCall.py", line 27, in ?
>     iface1.connect_to_signal("HelloSignal", print_message, iface1)
>   File "/usr/lib/python2.4/site-packages/dbus/_dbus.py", line 191, in 
> connect_to_signal
>     self._obj.connect_to_signal(signal_name, handler_function, dbus_interface)
>   File "/usr/lib/python2.4/site-packages/dbus/proxies.py", line 77, in 
> connect_to_signal
>     path=self._object_path)
>   File "/usr/lib/python2.4/site-packages/dbus/_dbus.py", line 120, in 
> add_signal_receiver
>     dbus_bindings.bus_add_match(self._connection, str(match_rule))
>   File "dbus_bindings.pyx", line 1476, in dbus_bindings.bus_add_match
> dbus_bindings.DBusException: Interface name '<Interface <ProxyObject wrapping 
> <dbus._dbus.SessionBus instance at 0x403e366c> 
> org.freedesktop.HelloWorld /org/freedesktop/HelloWorldObject at 403e37ac> 
> implementing org.freedesktop.HelloWorldIFace at 403e3bcc>' is invalid
> 
> 
> Well, of course I'm mistaking something, but I don't understand what!
> 
> Can you help me, please?
> 
> Excuse me for this elementary question...
> 
> 
> Thank you in advance.
> 
> Luigi
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list