The new message notification for Pidgin with Pytho


                                These days, i am studying the Python and DBus interface of Pidgin. After a few hours , a notification tool was done. The following is the code in Python.

               
               
                #!/usr/bin/env python
#
# This is a Python script for new-msg-notification in Pidgin
# Copyright 2007-2008 (c) Zhang Shunchang freebsd13@gmail.com>
#
import dbus
import gobject
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
    import dbus.glib
def strip_ml_tags(in_text):
    """Description: Removes all HTML/XML-like tags from the input text.
    """
    # convert in_text to a mutable object (e.g. list)
    s_list = list(in_text)
    i,j = 0,0
   
    while i  len(s_list):
        # iterate until a left-angle bracket is found
        if s_list == ':
            while s_list != '>':
                # pop everything from the the left-angle bracket until the right-angle bracket
                s_list.pop(i)
               
            # pops the right-angle bracket, too
            s_list.pop(i)
        else:
            i=i+1
            
    # convert the list back into text
    join_char=''
    return join_char.join(s_list)
def send_notification(notify_title, notify_text):
    notify_iface.Notify("New Pidgin Msg Notification", 0, "", notify_title, notify_text, [], {}, 0)
def received_im_msg(account, sender, message, conv, flags):
    text = ""
    text +=sender
    text +=" said:"
    text +=strip_ml_tags(message)
    send_notification("You got a new IM msg!", text)
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# get the notify interface
bus = dbus.SessionBus()
bus.add_signal_receiver(received_im_msg, \
                dbus_interface = "im.pidgin.purple.PurpleInterface", \
                signal_name = "ReceivedImMsg")
notify_object = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
notify_iface=dbus.Interface(notify_object, "org.freedesktop.Notifications")
loop = gobject.MainLoop()
loop.run()
There are some things need to do, such as display the sender's local nickname, the smile face supported, change the Pidgin's tray status after click the notification.
References:
http://developer.pidgin.im/wiki/DbusHowto
http://developer.pidgin.im/doxygen/dev/html/conversation-signals.html#received-im-msg
http://ubuntuforums.org/showthread.php?p=4471648
The snapshot:

you can save the script as new_msg_notify.py and type:
               
                $python new_msg_notify.py
in your SHELL prompt and enjoy it! :)