summaryrefslogtreecommitdiffstats
path: root/python/examples
diff options
context:
space:
mode:
authorSeth Nickell <seth@gnome.org>2004-07-11 03:02:14 +0000
committerSeth Nickell <seth@gnome.org>2004-07-11 03:02:14 +0000
commit233f8d0e33c3417c4c9abe2790fc949df19b879d (patch)
tree5904dbc2314c7635dea745e0a999550c320cd9b5 /python/examples
parent3d0f1fb1b62a3ee9a897f3ca7422e5f5be4716a0 (diff)
2004-07-10 Seth Nickell <seth@gnome.org>
* python/dbus.py: Add "message" argument to service-side dbus.Object methods. This will break existing services written using the python bindings, but will allow extraction of all the message information (e.g. who its from). Add improved "object oriented" signal handling/emission. * python/examples/example-service.py: Nix this example. * python/examples/example-signal-emitter.py: * python/examples/example-signal-recipient.py: Two new examples that show how to emit and receive signals using the new APIs. * python/examples/example-signals.py: * python/examples/gconf-proxy-service.py: * python/examples/gconf-proxy-service2.py: Add "message" argument to service methods.
Diffstat (limited to 'python/examples')
-rw-r--r--python/examples/example-service.py2
-rw-r--r--python/examples/example-signal-emitter.py18
-rw-r--r--python/examples/example-signal-recipient.py19
-rw-r--r--python/examples/example-signals.py27
-rw-r--r--python/examples/gconf-proxy-service.py8
-rw-r--r--python/examples/gconf-proxy-service2.py2
6 files changed, 43 insertions, 33 deletions
diff --git a/python/examples/example-service.py b/python/examples/example-service.py
index 974f8b1d..4f753cd8 100644
--- a/python/examples/example-service.py
+++ b/python/examples/example-service.py
@@ -7,7 +7,7 @@ class SomeObject(dbus.Object):
def __init__(self, service):
dbus.Object.__init__(self, "/SomeObject", service, [self.HelloWorld])
- def HelloWorld(self, hello_message):
+ def HelloWorld(self, message, hello_message):
print (hello_message)
return ["Hello", "from example-service.py"]
diff --git a/python/examples/example-signal-emitter.py b/python/examples/example-signal-emitter.py
new file mode 100644
index 00000000..edabfd70
--- /dev/null
+++ b/python/examples/example-signal-emitter.py
@@ -0,0 +1,18 @@
+import dbus
+import gtk
+
+class TestObject(dbus.Object):
+ def __init__(self, service):
+ dbus.Object.__init__(self, "/object", service, [self.HelloWorld])
+
+ def emitHelloSignal(self, message):
+ # Emit the signal
+ self.emit_signal(interface="org.designfu.TestService",
+ signal_name="hello")
+
+session_bus = dbus.SessionBus()
+service = dbus.Service("org.designfu.TestService", bus=session_bus)
+object = TestObject(service)
+
+gtk.main()
+A
diff --git a/python/examples/example-signal-recipient.py b/python/examples/example-signal-recipient.py
new file mode 100644
index 00000000..65e5933a
--- /dev/null
+++ b/python/examples/example-signal-recipient.py
@@ -0,0 +1,19 @@
+import gtk
+import dbus
+
+bus = dbus.SessionBus()
+service = bus.get_service("org.designfu.TestService")
+object = service.get_object("/org/designfu/TestService/object", "org.designfu.TestService")
+
+def hello_signal_handler(interface, signal_name, service, path, message):
+ print ("Received signal '%s.%s' from object '%s%s'"
+ % (interface, signal_name, service, path))
+
+
+object.connect_to_signal("hello", hello_signal_handler)
+
+# Tell the remote object to emit the signal
+object.emitHelloSignal()
+
+gtk.main()
+
diff --git a/python/examples/example-signals.py b/python/examples/example-signals.py
deleted file mode 100644
index 8e319569..00000000
--- a/python/examples/example-signals.py
+++ /dev/null
@@ -1,27 +0,0 @@
-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()
-
-
diff --git a/python/examples/gconf-proxy-service.py b/python/examples/gconf-proxy-service.py
index 76e43ce8..25ecbe9d 100644
--- a/python/examples/gconf-proxy-service.py
+++ b/python/examples/gconf-proxy-service.py
@@ -16,19 +16,19 @@ class GConfService(dbus.Service):
self.client = gconf.client_get_default()
- def getString(self, object_path):
+ def getString(self, message, object_path):
print ("getString called on GConf key %s" % (object_path))
return self.client.get_string(object_path)
- def setString(self, object_path, new_value):
+ def setString(self, message, object_path, new_value):
print ("setString called on GConf key %s" % (object_path))
self.client.set_string(object_path, new_value)
- def getInt(self, object_path):
+ def getInt(self, message, object_path):
print ("getInt called on GConf key %s" % (object_path))
return self.client.get_int(object_path)
- def setInt(self, object_path, new_value):
+ def setInt(self, message, object_path, new_value):
print ("setInt called on GConf key %s" % (object_path))
self.client.set_int(object_path, new_value)
diff --git a/python/examples/gconf-proxy-service2.py b/python/examples/gconf-proxy-service2.py
index 4cec8605..5ba77db7 100644
--- a/python/examples/gconf-proxy-service2.py
+++ b/python/examples/gconf-proxy-service2.py
@@ -16,7 +16,7 @@ class GConfService(dbus.Service):
self.client = gconf.client_get_default()
- def object_method_called(self, object_path, method_name, argument_list):
+ def object_method_called(self, message, object_path, method_name, argument_list):
print ("Method %s called on GConf key %s" % (method_name, object_path))
if "getString" == method_name: