NEWS: Describe new DBusException 'args' support
[dbus-python-phuang.git] / examples / example-signal-emitter.py
blob24384c16d0bdc4e4e67344b237c92316fae05e98
1 #!/usr/bin/env python
3 usage = """Usage:
4 python example-signal-emitter.py &
5 python example-signal-recipient.py
6 python example-signal-recipient.py --exit-service
7 """
9 import gobject
11 import dbus
12 import dbus.service
13 import dbus.mainloop.glib
15 class TestObject(dbus.service.Object):
16 def __init__(self, conn, object_path='/com/example/TestService/object'):
17 dbus.service.Object.__init__(self, conn, object_path)
19 @dbus.service.signal('com.example.TestService')
20 def HelloSignal(self, message):
21 # The signal is emitted when this method exits
22 # You can have code here if you wish
23 pass
25 @dbus.service.method('com.example.TestService')
26 def emitHelloSignal(self):
27 #you emit signals by calling the signal's skeleton method
28 self.HelloSignal('Hello')
29 return 'Signal emitted'
31 @dbus.service.method("com.example.TestService",
32 in_signature='', out_signature='')
33 def Exit(self):
34 loop.quit()
36 if __name__ == '__main__':
37 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
39 session_bus = dbus.SessionBus()
40 name = dbus.service.BusName('com.example.TestService', session_bus)
41 object = TestObject(session_bus)
43 loop = gobject.MainLoop()
44 print "Running example signal emitter service."
45 print usage
46 loop.run()