By notifications you mean the "OSD bubbles" that some software sends, like changing volume, IM chat, etc? You want to create a python program to capture those?
Well, Ask Ubuntu is not a programmer's QA, and software development is a bit beyond the scope, but here is a little code I did do capture notification bubbles:
import glib
import dbus
from dbus.mainloop.glib import DBusGMainLoop
def notifications(bus, message):
if message.get_member() == "Notify":
print [arg for arg in message.get_args_list()]
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("interface='org.freedesktop.Notifications'")
bus.add_message_filter(notifications)
mainloop = glib.MainLoop()
mainloop.run()
Leave this running in a terminal, then open another terminal window and test it:
notify-send --icon=/usr/share/pixmaps/debian-logo.png "My Title" "Some text body"
And the program will output this:
[dbus.String(u'notify-send'), dbus.UInt32(0L), dbus.String(u'/usr/share/pixmaps/debian-logo.png'), dbus.String(u'My Title'), dbus.String(u'Some text body'),...
As you may have guessed, message.get_args_list()[0]
is the sender, [2] for icon, [3] for summary and [4] for body text.
For the meaning of the other fields, check the official specification docs
dbus-monitor "type='signal',interface='org.freedesktop.Notifications'"
shows nothing butdbus-monitor "interface='org.freedesktop.Notifications'"
shows notifications (type is 'method_call' not 'signal').