我需要阅读使用Python的Linux桌面通知。我的头没用了,我想不出办法。
这是我使用dbus可以做的最好的事情:
import gi.repository.GLib
import dbus
from dbus.mainloop.glib import DBusGMainLoop
def notifications(bus, message):
print(str(message))
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
bus.add_message_filter(notifications)
mainloop = gi.repository.GLib.MainLoop()
mainloop.run()
似乎此代码只是从GLib返回对象
答案 0 :(得分:0)
您在message
中拥有的notification
是不同的dbus.**.*Message
实例,因此这就是打印出来的内容。
尝试for arg in message.get_args_list(): print(arg)
,您可能会找到想要的东西。