from yaydbus.service import Object, signal, method from yaydbus.util import annotate class TestObject(Object): @signal('com.example.TestService') @annotate(message='s') def HelloSignal(self, message): # The signal is emitted when this method exits # You can have code here if you wish pass @method('com.example.TestService') @annotate(return_='s') def emitHelloSignal(self): #you emit signals by calling the signal's skeleton method self.HelloSignal('Hello') return 'Signal emitted' @method("com.example.TestService", out_signature='') def Exit(self): loop.quit() if __name__ == '__main__': bus = SessionBus() bus.request_name('com.example.TestService') object = bus.make_object('/com/example/TestService/object', TestObject) loop = Mainloop([bus]) loop.run()
print @method('com.example.SimpleService') @annotate(i=UInt32, return_=UInt32) def ExpensiveCalculation(self, i): while i < 1000: i += 1 return i @method('com.example.SimpleService') @annotate(something=Variant) def PrintSomething(self, something): print 'Something:', something @method('com.example.SimpleService', in_signature='v', out_signature='s') def Repr(self, value): return repr(value) @method('com.example.SimpleService') @annotate(dic=Dictionary(str, str), key=str, return_=str) def GetItem(self, dic, key): return dic[key] bus = SessionBus() bus.request_name('com.example.SimpleService') obj = bus.add_object(TestObject(bus)) mainloop = Mainloop([bus]) mainloop.run()
from yaydbus.bus import SessionBus from yaydbus.service import method, Object from yaydbus.mainloop import Mainloop class MyObject(Object): @method('com.example.SampleInterface', in_signature='s', out_signature='as') def HelloWorld(self, hello_message): print hello_message return ["Hi.", "There."] bus = SessionBus() assert bus.request_name('com.example.SampleService') obj = bus.make_object('/SomeObject', MyObject) m = Mainloop((bus,)) m.run()