2014-03-26 4 views
0

왜 개체 내보내기가 실행되지 않습니까?Dbus 개체 내보내기

from dbus.mainloop.glib import DBusGMainLoop as glib_main 
from gi.repository import GLib 
import dbus.service as Service 
import dbus as DBus 
import pymongo as Mgo 

class Emitter(object): 
    __signals__ = {} 

    def sig(self, sig, *args): 
     self.__signals__[sig](*args) 

    def on(self, sig, f): 
     self.__signals__[sig] = f 

class Notifier(Service.Object, Emitter): 
    __signals__ = {"notified" : None, "update" : None} 
    def __init__(self, conn, bus): 
     Service.Object.__init__(self, object_path = "/org/freedesktop/Notifications", bus_name = Service.BusName(bus, conn)) 
     Emitter.__init__(self) 
     self.client = Mgo.MongoClient() 
     self.lot = self.client["metroid"]["notifications"] 
     self.server_info = {"name" : "bang-notifier/metroid", "vendor" : "[email protected]", "version" : "v0.1", "spec-version" : "v1.2"} 
     self.connect = self.on 
     self.emit = self.sig 
     self.connect("update", self.update) 

    def update(self): 
     self.emit("notified", None, self.lot.find()) 

    def delete(self, id): 
     self.CloseNotification(id) 

    @Service.method("org.freedesktop.Notifications", out_signature="as") 
    def GetCapabilities(self): 
     return ["actions", "action-icons", "body", "body-markup", "icon-static", "persistence"] 

    @Service.method("org.freedesktop.Notifications", in_signature="susssasa{sv}i", out_signature="u") 
    def Notify(self, appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout): 
     message = {"id" : replacesId, "icon" : appIcon, "summary" : summary, "body" : body, "actions" : actions, "hints" : hints, "expires" : expireTimeout} 
     if message["id"] == 0: 
      message["id"] = self.lot.count() 
      if message["id"] == 0: message["id"] = 1 
      self.lot.insert(message) 
     else: 
      self.lot.update({"id" : replacesId}, {"$set", message}) 
     self.emit("notified", message, None) 
     return message["id"] 

    @Service.method("org.freedesktop.Notifications", in_signature="u") 
    def CloseNotification(self, id): 
     self.lot.remove({"id" : id}) 
     self.NotificationClosed(id) 

    @Service.method("org.freedesktop.Notifications", out_signature="ssss") 
    def GetServerInformation(self): 
     return self.server_info.values() 

    @Service.signal("org.freedesktop.Notifications", signature="u") 
    def NotificationClosed(self, id): 
     pass 

    @Service.signal("org.freedesktop.Notifications", signature="us") 
    def ActionInvoked(self, id, actionKey): 
     pass 

    def close(self): 
     self.client.close() 


if __name__ == '__main__': 
    from gi.repository import GLib 
    loop = GLib.MainLoop() 
    glib_main(set_as_default = True) 
    conn = DBus.SessionBus(mainloop = loop) 
    Notifier(conn, "org.freedesktop.Notifications") 
    loop.run() 

답변

2

오류가 메인 루프를 설정하는 중입니다. 방금 GLib.MainLoop 전달하는 동안

if __name__ == '__main__': 
    from gi.repository import GLib 
    loop = GLib.MainLoop() 
    glib_main(set_as_default = True) 
    conn = DBus.SessionBus(mainloop = loop) # <**offending line**> 
    Notifier(conn, "org.freedesktop.Notifications") 
    loop.run() 

가 대신 DBusGMainLoop 필요 :

여기
if __name__ == '__main__': 
    from gi.repository import GLib 
    loop = GLib.MainLoop() 
    glib_main(set_as_default = True) 
    conn = DBus.SessionBus(mainloop=DBusGMainLoop()) <-- change to --> 
    # conn = DBus.SessionBus(mainloop = glib_main()) <-- as you have it imported --> 
    Notifier(conn, "org.freedesktop.Notifications") 
    loop.run() 

setting up the event loop에 대한 링크입니다 당신은 작업 주회 돌이로 DBusGMainLoop와 버스 연결을 작성해야합니다.

또한 오류 메시지에 대해 확신 할 수는 없지만 수행하려고 시도하는 것에 대한 이해에 대한 설명을 조금 더 제공하면 더 많은 답변을 얻을 수 있습니다. 가능하다면 오류 메시지가 표시됩니다.