Reputation: 125
I'm trying to make a python application which reads the messages going through DBus, something giving the same output of the bash dbus-monitor. According to what I got from my searching the code should be quite plain and clear, something like:
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 ()
But launching it I only get the message returned by DBus saying the application is connected, differently from what I get if I execute the bash command:
dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify'
In this case I can watch all the messages matching the filter condition. Does anybody please help me to understand where I fail? Thanks
Upvotes: 3
Views: 6770
Reputation: 2337
Notify
is a method, not a signal, so you need to add eavesdrop='true'
as part of the match rule, to receive messages which are not intended for you. If you run dbus-monitor, you will notice the eavesdrop
key in the rules dbus-monitor sets up.
This is a change in behavior, I believe since dbus-1.5.6 where bug 39450 was fixed.
Upvotes: 10