Exemplo n.º 1
0
 def __init__(self):
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     self._loop = gobject.MainLoop()
     bus = dbus.SessionBus()
     self._timeout_id = 0
     self._bus_name = dbus.service.BusName(BUS_NAME, bus) # preserve well known bus name
     self._player = Player(self.idle_callback)
     self._player.add_to_connection(bus, OBJECT_PATH)
Exemplo n.º 2
0
class Application(object):
    
    def __init__(self):
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self._loop = gobject.MainLoop()
        bus = dbus.SessionBus()
        self._timeout_id = 0
        self._bus_name = dbus.service.BusName(BUS_NAME, bus) # preserve well known bus name
        self._player = Player(self.idle_callback)
        self._player.add_to_connection(bus, OBJECT_PATH)
    
    def idle_callback(self, player, idle):
        if not idle and self._timeout_id:
            gobject.source_remove(self._timeout_id)
            self._timeout_id = 0
        elif idle and not self._timeout_id:
            self._timeout_id = gobject.timeout_add_seconds(IDLE_TIMEOUT, self.quit)
    
    def run(self):
        self._loop.run()
    
    def quit(self):
        self._player.remove_from_connection()
        self._loop.quit()