예제 #1
0
class App(BaseApp):
    def __init__(self, config_path=None, **kwargs):
        BaseApp.__init__(self, **kwargs)
        if config_path:
            self.user_config = sxmain.load_user_config(config_path)
        else:
            self.user_config = None

    def init(self):
        BaseApp.init(self)

        self.bus = SessionBus()
        self.add_fd_handler("read", self.bus, self.process_dbus)
        self.bus.request_name("org.yahiko.status_bar")
        screen = self.conn.setup.roots[self.conn.pref_screen]
        self.status_bar = StatusBar(self, screen, self.user_config)

    def run(self):
        self.status_bar.ui.recreate_surface()
        self.status_bar.ui.layout()
        self.status_bar.ui.dirty()

        BaseApp.run(self)

    def process_dbus(self):
        self.bus.receive_one()

        BaseApp.run(self)
예제 #2
0
    def init(self):
        BaseApp.init(self)

        self.bus = SessionBus()
        self.add_fd_handler("read", self.bus, self.process_dbus)
        self.bus.request_name("org.yahiko.status_bar")
        screen = self.conn.setup.roots[self.conn.pref_screen]
        self.status_bar = StatusBar(self, screen, self.user_config)
예제 #3
0
    def __init__(self, app):
        self.objects = {}
        if YAYDBUS:
            self.session_bus = SessionBus()
            app.add_fd_handler('read', self.session_bus, self.process_dbus)
        else:
            dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

            self.session_bus = dbus.SessionBus()
            self.name = service.BusName(DEFAULT_BUS_NAME, self.session_bus)

        if YAYDBUS:
            self.session_bus.request_name(DEFAULT_BUS_NAME)
            self.session_bus.request_name(DEFAULT_BUS_NAME+'.DBusService')
        self.register('dbus', functools.partial(DBusObject, app))
예제 #4
0
class SXDBus(Plugin):
    key = 'dbus'

    def __init__(self, app):
        self.objects = {}
        if YAYDBUS:
            self.session_bus = SessionBus()
            app.add_fd_handler('read', self.session_bus, self.process_dbus)
        else:
            dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

            self.session_bus = dbus.SessionBus()
            self.name = service.BusName(DEFAULT_BUS_NAME, self.session_bus)

        if YAYDBUS:
            self.session_bus.request_name(DEFAULT_BUS_NAME)
            self.session_bus.request_name(DEFAULT_BUS_NAME+'.DBusService')
        self.register('dbus', functools.partial(DBusObject, app))

    def process_dbus(self):
        self.session_bus.receive_one()

    def register(self, name, cls, path=None):
        """ register a new dbus object """
        log.info('registering %s: %s', name, cls)
        
        if path is None:
            path = "/%s" % name

        if YAYDBUS:
            self.objects[name] = self.session_bus.add_object(
                    cls(self.session_bus, path),
            )
        else:
            self.objects[name] = cls(
                    conn=self.session_bus, 
                    object_path=path,
                    bus_name=self.name,
            )
예제 #5
0
import sys
sys.path.append('..')

from yaydbus.bus import SessionBus
from yaydbus.dbus_types import Array

bus = SessionBus()

obj = bus.get_object('/com/example/SimpleService/Test', 'com.example.SimpleService')
proxy = obj.get_bound('com.example.SimpleService')

print 'That should be 1000:', proxy.ExpensiveCalculation(1)
proxy.PrintSomething(33)
print proxy.Repr(Array(str)(['one', 'two', 'three']))

proxy.PushItem('Hello')
proxy.PushItem('World!')
proxy.PushItem(Array(int)([1, 2, 3, 4, 5, 6]))

proxy.PrintItems()
print 'Popped:', proxy.PopItem()
proxy.PrintItems()

print proxy.GetItem({'one': 'value1', 'two': 'value2'}, 'two')
예제 #6
0
        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()

예제 #7
0
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()
예제 #8
0
import sys

from yaydbus.bus import SessionBus
from yaydbus.dbus_types import Array

bus = SessionBus()

obj = bus.get_object('/org/yahiko/status_bar/'+sys.argv[1], 'org.yahiko.status_bar')
proxy = obj.get_bound('org.yahiko.status_bar')

proxy.set_text(sys.argv[2])
예제 #9
0
파일: test.py 프로젝트: samurai-x/samurai-x
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()