dbus/python/examples example-client.py, 1.5, 1.6 example-service.py, 1.8, 1.9 example-signal-emitter.py, 1.2, 1.3 example-signal-recipient.py, 1.2, 1.3 list-system-services.py, 1.3, 1.4

John Palmieri johnp at freedesktop.org
Mon Apr 25 15:54:30 PDT 2005


Update of /cvs/dbus/dbus/python/examples
In directory gabe:/tmp/cvs-serv29428/python/examples

Modified Files:
	example-client.py example-service.py example-signal-emitter.py 
	example-signal-recipient.py list-system-services.py 
Log Message:
* python/dbus_bindings.pyx.in (send_with_reply_handlers): New send
method for doing async calls
(_pending_call_notification): New C function for handling pendning call
callbacks
(set_notify): New method for setting pending call notification

* python/dbus.py: new version tuple "version" is set at (0, 40, 0)
Async capabilities added to remote method calls
(Sender): class removed
(RemoteService): class removed
(ObjectTree): class removed for now
(RemoteObject): Renamed to ProxyObject
(RemoteMethod): Renamed to ProxyMethod
(method): Decorator added for decorating python methods as dbus methods
(signal): Decorator added for decorating python methods as signal emitters
(ObjectType): Metaclass added for generating introspection data and the
method callback vtable
(Interface): Wrapper class added to wrap objects in a dbus interface
(Object): Uses ObjectType as its metaclass and exports Introspect
of the org.freedesktop.DBus.Introspectable interface
(ValidationException, UnknownMethodException): new exceptions

* python/examples/*: Modified to fit with the new bindings



Index: example-client.py
===================================================================
RCS file: /cvs/dbus/dbus/python/examples/example-client.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- example-client.py	11 Feb 2005 19:51:18 -0000	1.5
+++ example-client.py	25 Apr 2005 22:54:28 -0000	1.6
@@ -3,15 +3,14 @@
 import dbus
 
 bus = dbus.SessionBus()
-remote_service = bus.get_service("org.designfu.SampleService")
-remote_object = remote_service.get_object("/SomeObject",
-                                          "org.designfu.SampleInterface")
+remote_object = bus.get_object("org.designfu.SampleService", "/SomeObject")
+iface = dbus.Interface(remote_object, "org.designfu.SampleInterface")
 
-hello_reply_list = remote_object.HelloWorld("Hello from example-client.py!")
+hello_reply_list = remote_object.HelloWorld("Hello from example-client.py!", dbus_interface = "org.designfu.SampleInterface")
 
-hello_reply_tuple = remote_object.GetTuple()
+hello_reply_tuple = iface.GetTuple()
 
-hello_reply_dict = remote_object.GetDict()
+hello_reply_dict = iface.GetDict()
 
 print (hello_reply_list)
 
@@ -19,3 +18,4 @@
 
 print str(hello_reply_dict)
 
+print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")

Index: example-service.py
===================================================================
RCS file: /cvs/dbus/dbus/python/examples/example-service.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- example-service.py	11 Feb 2005 19:51:18 -0000	1.8
+++ example-service.py	25 Apr 2005 22:54:28 -0000	1.9
@@ -5,17 +5,19 @@
 
 class SomeObject(dbus.Object):
     def __init__(self, service):
-        export = [self.HelloWorld, self.GetTuple, self.GetDict]
-        dbus.Object.__init__(self, "/SomeObject", service, export)
+        dbus.Object.__init__(self, "/SomeObject", service)
 
-    def HelloWorld(self, message, hello_message):
+    @dbus.method("org.designfu.SampleInterface")
+    def HelloWorld(self, hello_message):
         print (str(hello_message))
         return ["Hello", " from example-service.py"]
 
-    def GetTuple(self, message):
+    @dbus.method("org.designfu.SampleInterface")
+    def GetTuple(self):
         return ("Hello Tuple", " from example-service.py")
 
-    def GetDict(self, message):
+    @dbus.method("org.designfu.SampleInterface")
+    def GetDict(self):
         return {"first": "Hello Dict", "second": " from example-service.py"}
 
 session_bus = dbus.SessionBus()

Index: example-signal-emitter.py
===================================================================
RCS file: /cvs/dbus/dbus/python/examples/example-signal-emitter.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- example-signal-emitter.py	28 Jan 2005 19:09:55 -0000	1.2
+++ example-signal-emitter.py	25 Apr 2005 22:54:28 -0000	1.3
@@ -3,13 +3,20 @@
 
 class TestObject(dbus.Object):
     def __init__(self, service):
-        dbus.Object.__init__(self, "/org/designfu/TestService/object", service, [self.emitHelloSignal])
+        dbus.Object.__init__(self, "/org/designfu/TestService/object", service)
 
-    def emitHelloSignal(self, message):
-        # Emit the signal
-        self.emit_signal(interface="org.designfu.TestService",
-                              signal_name="hello")
+    @dbus.signal('org.designfu.TestService')
+    def HelloSignal(self, message):
+        # The signal is emitted when this method exits
+	# You can have code here if you wish
+        pass
 
+    @dbus.method('org.designfu.TestService')
+    def emitHelloSignal(self):
+        #you emit signals by calling the signal's skeleton method
+	self.HelloSignal("Hello")
+	return "Signal emitted"
+	
 session_bus = dbus.SessionBus()
 service = dbus.Service("org.designfu.TestService", bus=session_bus)
 object = TestObject(service)

Index: example-signal-recipient.py
===================================================================
RCS file: /cvs/dbus/dbus/python/examples/example-signal-recipient.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- example-signal-recipient.py	11 Feb 2005 19:51:18 -0000	1.2
+++ example-signal-recipient.py	25 Apr 2005 22:54:28 -0000	1.3
@@ -1,19 +1,30 @@
 import gtk
 import dbus
+import gobject
+
+def handle_reply(msg):
+    print msg
+
+def handle_error(e):
+    print str(e)
+
+def emit_signal():
+   #call the emitHelloSignal method async
+   object.emitHelloSignal(dbus_interface="org.designfu.TestService", 
+                          reply_handler = handle_reply, error_handler = handle_error)
+   return True
 
 bus = dbus.SessionBus()
-service = bus.get_service("org.designfu.TestService")
-object  = service.get_object("/org/designfu/TestService/object", "org.designfu.TestService")
+object  = bus.get_object("org.designfu.TestService","/org/designfu/TestService/object")
 
-def hello_signal_handler(sender):
-        print ("Received signal '%s.%s' from object '%s%s'"
-               % (sender.interface, sender.signal_name, sender.service, sender.path))
+def hello_signal_handler(hello_string):
+        print ("Received signal and it says: " + hello_string)
 
+object.connect_to_signal("HelloSignal", hello_signal_handler, dbus_interface="org.designfu.TestService")
 
-object.connect_to_signal("hello", hello_signal_handler)
+gobject.timeout_add(2000, emit_signal)
 
 # Tell the remote object to emit the signal
-object.emitHelloSignal()
 
 gtk.main()
 

Index: list-system-services.py
===================================================================
RCS file: /cvs/dbus/dbus/python/examples/list-system-services.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- list-system-services.py	28 Jan 2005 19:09:55 -0000	1.3
+++ list-system-services.py	25 Apr 2005 22:54:28 -0000	1.4
@@ -5,15 +5,14 @@
 # Get a connection to the SYSTEM bus
 bus = dbus.SystemBus()
 
-# Get the service provided by the dbus-daemon named org.freedesktop.DBus
-dbus_service = bus.get_service('org.freedesktop.DBus')
-    
 # Get a reference to the desktop bus' standard object, denoted
-# by the path /org/freedesktop/DBus. The object /org/freedesktop/DBus
+# by the path /org/freedesktop/DBus. 
+dbus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
+
+# The object /org/freedesktop/DBus
 # implements the 'org.freedesktop.DBus' interface
-dbus_object = dbus_service.get_object('/org/freedesktop/DBus',
-                                      'org.freedesktop.DBus')
-            
+dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
+
 # One of the member functions in the org.freedesktop.DBus interface
 # is ListServices(), which provides a list of all the other services
 # registered on this bus. Call it, and print the list.



More information about the dbus-commit mailing list