mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-06 01:20:22 +01:00
add examples
This commit is contained in:
parent
42019c9625
commit
0469cdb2c7
3 changed files with 57 additions and 0 deletions
12
python/examples/example-client.py
Normal file
12
python/examples/example-client.py
Normal file
|
|
@ -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)
|
||||
18
python/examples/example-service.py
Normal file
18
python/examples/example-service.py
Normal file
|
|
@ -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()
|
||||
27
python/examples/example-signals.py
Normal file
27
python/examples/example-signals.py
Normal file
|
|
@ -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()
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue