Pythonとdbusに問題があります。開発者向けのドキュメントと仕様を確認しましたが、メインループの設定方法がわかりません。通知イベントを聞きたい。見る
http://dbus.freedesktop.org/doc/dbus-python/doc/
と
http://www.galago-project.org/specs/notification/0.9/index.html
私のサンプルスクリプト:
import dbus
from dbus.mainloop.glib import DBusGMainLoop
class MessageListener:
def __init__(self):
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SessionBus()
self.proxy = self.bus.get_object('org.freedesktop.Notifications',
'/org/freedesktop/Notifications')
self.proxy.connect_to_signal('NotificationClosed',
self.handle_notification)
def handle_notification(self, *args, **kwargs):
print args, kwargs
if __name__ == '__main__':
MessageListener()
DBusGMainLoopには、run()のようなメソッドはありません。gobjectからのループを使用してソースコードを変更した場合:
import gobject
loop = gobject.MainLoop()
dbus.set_default_main_loop(loop)
...
loop.run()
次のエラーメッセージが表示されます。
Traceback (most recent call last):
File "dbus_example.py", line 40, in <module>
MessageListener()
File "dbus_example.py", line 9, in __init__
dbus.set_default_main_loop(loop)
TypeError: A dbus.mainloop.NativeMainLoop instance is required
それについて何をすべきか考えていますか?前もって感謝します。フィニアス