summaryrefslogtreecommitdiff
path: root/examples/example-client.py
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2006-12-13 14:40:32 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2006-12-13 14:40:32 +0000
commitb70364f2a37e64585c53a72e36481407e375808c (patch)
tree41e1004014cc54995bebb7c647232c5319aec60d /examples/example-client.py
parentc874bb37093c39e3dcc974c7bff39a36e4f7202a (diff)
downloaddbus-python-b70364f2a37e64585c53a72e36481407e375808c.tar.gz
dbus/examples: Move to examples/ (it's not part of the library and isn't installed)
Diffstat (limited to 'examples/example-client.py')
-rw-r--r--examples/example-client.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/example-client.py b/examples/example-client.py
new file mode 100644
index 0000000..aae4c3f
--- /dev/null
+++ b/examples/example-client.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+usage = """Usage:
+python example-service.py &
+python example-client.py
+python example-client.py --exit-service
+"""
+
+import sys
+from traceback import print_exc
+
+import dbus
+import dbus.mainloop.glib
+
+def main():
+ bus = dbus.SessionBus()
+
+ try:
+ remote_object = bus.get_object("com.example.SampleService",
+ "/SomeObject")
+
+ # you can either specify the dbus_interface in each call...
+ hello_reply_list = remote_object.HelloWorld("Hello from example-client.py!",
+ dbus_interface = "com.example.SampleInterface")
+ except dbus.DBusException:
+ print_exc()
+ print usage
+ sys.exit(1)
+
+ print (hello_reply_list)
+
+ # ... or create an Interface wrapper for the remote object
+ iface = dbus.Interface(remote_object, "com.example.SampleInterface")
+
+ hello_reply_tuple = iface.GetTuple()
+
+ print hello_reply_tuple
+
+ hello_reply_dict = iface.GetDict()
+
+ print hello_reply_dict
+
+ # introspection is automatically supported
+ print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
+
+ if sys.argv[1:] == ['--exit-service']:
+ iface.Exit()
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ main()