Update NEWS
[dbus-python-phuang.git] / examples / example-client.py
blob5d881fde798169113c76280cc6b8b7dc0f462e70
1 #!/usr/bin/env python
3 usage = """Usage:
4 python example-service.py &
5 python example-client.py
6 python example-client.py --exit-service
7 """
9 import sys
10 from traceback import print_exc
12 import dbus
14 def main():
15 bus = dbus.SessionBus()
17 try:
18 remote_object = bus.get_object("com.example.SampleService",
19 "/SomeObject")
21 # you can either specify the dbus_interface in each call...
22 hello_reply_list = remote_object.HelloWorld("Hello from example-client.py!",
23 dbus_interface = "com.example.SampleInterface")
24 except dbus.DBusException:
25 print_exc()
26 print usage
27 sys.exit(1)
29 print (hello_reply_list)
31 # ... or create an Interface wrapper for the remote object
32 iface = dbus.Interface(remote_object, "com.example.SampleInterface")
34 hello_reply_tuple = iface.GetTuple()
36 print hello_reply_tuple
38 hello_reply_dict = iface.GetDict()
40 print hello_reply_dict
42 # D-Bus exceptions are mapped to Python exceptions
43 try:
44 iface.RaiseException()
45 except dbus.DBusException, e:
46 print str(e)
48 # introspection is automatically supported
49 print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
51 if sys.argv[1:] == ['--exit-service']:
52 iface.Exit()
54 if __name__ == '__main__':
55 main()