dbus.types: add __all__
[dbus-python-phuang.git] / dbus / examples / example-signal-recipient.py
bloba06d4943429de28850cb15c888a3fe46878f695e
1 #!/usr/bin/env python
3 import dbus
4 import dbus.decorators
5 import dbus.glib
6 import gobject
8 def handle_reply(msg):
9 print msg
11 def handle_error(e):
12 print str(e)
14 def emit_signal():
15 #call the emitHelloSignal method
16 object.emitHelloSignal(dbus_interface="org.designfu.TestService")
17 #reply_handler = handle_reply, error_handler = handle_error)
18 return True
20 bus = dbus.SessionBus()
21 object = bus.get_object("org.designfu.TestService","/org/designfu/TestService/object")
23 def hello_signal_handler(hello_string):
24 print ("Received signal and it says: " + hello_string)
26 @dbus.decorators.explicitly_pass_message
27 def catchall_signal_handler(*args, **keywords):
28 #The dbus.handler directive passes in the special __dbus_message__ variable
29 dbus_message = keywords["dbus_message"]
30 print "Caught signal " + dbus_message.get_member()
31 for arg in args:
32 print " " + str(arg)
34 def catchall_hello_signals_handler(hello_string):
35 print ("Received a hello signal and it says ") + hello_string
37 @dbus.decorators.explicitly_pass_message
38 def catchall_testservice_interface_handler(hello_string, dbus_message):
39 print "org.designfu.TestService interface says " + hello_string + " when it sent signal " + dbus_message.get_member()
41 object.connect_to_signal("HelloSignal", hello_signal_handler, dbus_interface="org.designfu.TestService", arg0="Hello")
43 #lets make a catchall
44 bus.add_signal_receiver(catchall_signal_handler)
45 bus.add_signal_receiver(catchall_hello_signals_handler, dbus_interface = "org.designfu.TestService", signal_name = "HelloSignal")
46 bus.add_signal_receiver(catchall_testservice_interface_handler, dbus_interface = "org.designfu.TestService")
49 gobject.timeout_add(2000, emit_signal)
51 # Tell the remote object to emit the signal
53 loop = gobject.MainLoop()
54 loop.run()