summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-09-30 02:41:13 +0000
committerHavoc Pennington <hp@redhat.com>2003-09-30 02:41:13 +0000
commit0469cdb2c7a504f4d47a08cc3c482f26babb2cc4 (patch)
treeb2dce5ab044645f5febd7f712ab63781b80ddaaf /python
parent42019c962537b940311573b1ec62495b973b5bfd (diff)
downloaddbus-0469cdb2c7a504f4d47a08cc3c482f26babb2cc4.tar.gz
add examples
Diffstat (limited to 'python')
-rw-r--r--python/examples/example-client.py12
-rw-r--r--python/examples/example-service.py18
-rw-r--r--python/examples/example-signals.py27
3 files changed, 57 insertions, 0 deletions
diff --git a/python/examples/example-client.py b/python/examples/example-client.py
new file mode 100644
index 00000000..0038b2db
--- /dev/null
+++ b/python/examples/example-client.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+
+import dbus
+
+bus = dbus.Bus()
+remote_service = bus.get_service("org.designfu.SampleService")
+remote_object = remote_service.get_object("/SomeObject",
+ "org.designfu.SampleInterface")
+
+hello_reply = remote_object.HelloWorld("Hello from example-client.py!")
+
+print (hello_reply)
diff --git a/python/examples/example-service.py b/python/examples/example-service.py
new file mode 100644
index 00000000..79fb009d
--- /dev/null
+++ b/python/examples/example-service.py
@@ -0,0 +1,18 @@
+import dbus
+
+import pygtk
+import gtk
+
+class SomeObject(dbus.Object):
+ def __init__(self, service):
+ dbus.Object.__init__(self, "/SomeObject", [self.HelloWorld], service)
+
+ def HelloWorld(self, hello_message):
+ print (hello_message)
+ return "Hello from example-service.py"
+
+
+service = dbus.Service("org.designfu.SampleService")
+object = SomeObject(service)
+
+gtk.main()
diff --git a/python/examples/example-signals.py b/python/examples/example-signals.py
new file mode 100644
index 00000000..8e319569
--- /dev/null
+++ b/python/examples/example-signals.py
@@ -0,0 +1,27 @@
+import pygtk
+import gtk
+
+import dbus
+
+class SignalFrom(dbus.Object):
+ def __init__(self, service):
+ dbus.Object.__init__(self, "/", [], service)
+
+def signal_to(interface, signal_name, service, path):
+ print ("Received signal '%s.%s' from '%s%s'" % (interface, signal_name, service, path))
+
+bus = dbus.Bus()
+bus.add_signal_receiver(signal_to,
+ "org.designfu.SignalInterface",
+ "org.designfu.SignalService",
+ "/")
+
+
+service = dbus.Service("org.designfu.SignalService", bus)
+signal_from = SignalFrom(service)
+
+signal_from.broadcast_signal("org.designfu.SignalInterface", "HelloWorld")
+
+gtk.main()
+
+