1
我试图让一个python应用程序读取通过DBus的消息,给出相同输出的bash dbus-monitor。据我从我的搜索代码应该是很清楚和明白了,是这样的:通过python监控dbus消息
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
def msg_cb(bus, msg):
args = msg.get_args_list()
print "Notification from '%s'" % args[0]
print "Summary: %s" % args[3]
print "Body: %s", args[4]
if __name__ == '__main__':
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
string = "interface='org.freedesktop.Notifications',member='Notify'"
bus.add_match_string(string)
bus.add_message_filter(msg_cb)
mainloop = gobject.MainLoop()
mainloop.run()
但不同于我所得到的,如果启动它,我只能得到消息后的DBus回话说的应用程序连接,我执行bash命令:
dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify'
在这种情况下,我可以看到所有与过滤条件匹配的消息。 有人请帮我理解我失败的地方吗? 感谢
这可能不会回答你的问题,但安装qt4-dev-tools并启动qtdbusviewer可能值得检查。我用它来调试我的dbus代码相当多。我认为如果你在命令行上运行它,它可能会在其输出中显示dbus消息。干杯。 – NuclearPeon 2013-07-19 18:37:50
看来,语法在短短2年内发生了很大的变化。至少在我的python 2.7.8中,我不会再用那种“printf-C-style”语法得到任何* print输出,尽管如何得到这些消息似乎对我来说是正确的。 – syntaxerror 2014-10-11 18:01:36