diff options
Diffstat (limited to 'python/examples')
-rw-r--r-- | python/examples/example-client.py | 12 | ||||
-rw-r--r-- | python/examples/example-service.py | 12 | ||||
-rw-r--r-- | python/examples/example-signal-emitter.py | 17 | ||||
-rw-r--r-- | python/examples/example-signal-recipient.py | 25 | ||||
-rw-r--r-- | python/examples/list-system-services.py | 13 |
5 files changed, 49 insertions, 30 deletions
diff --git a/python/examples/example-client.py b/python/examples/example-client.py index 0270ed6c..7439e6bd 100644 --- a/python/examples/example-client.py +++ b/python/examples/example-client.py @@ -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_tuple) print str(hello_reply_dict) +print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable") diff --git a/python/examples/example-service.py b/python/examples/example-service.py index e9f407f9..2209ff9f 100644 --- a/python/examples/example-service.py +++ b/python/examples/example-service.py @@ -5,17 +5,19 @@ import gtk 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() diff --git a/python/examples/example-signal-emitter.py b/python/examples/example-signal-emitter.py index bcd5ad6f..8797e5f6 100644 --- a/python/examples/example-signal-emitter.py +++ b/python/examples/example-signal-emitter.py @@ -3,13 +3,20 @@ import gtk 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) diff --git a/python/examples/example-signal-recipient.py b/python/examples/example-signal-recipient.py index b5306070..2da65ecb 100644 --- a/python/examples/example-signal-recipient.py +++ b/python/examples/example-signal-recipient.py @@ -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() diff --git a/python/examples/list-system-services.py b/python/examples/list-system-services.py index 9b114da9..80f63f98 100644 --- a/python/examples/list-system-services.py +++ b/python/examples/list-system-services.py @@ -5,15 +5,14 @@ import dbus # 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. |