免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2042 | 回复: 0
打印 上一主题 下一主题

The new message notification for Pidgin with Pytho [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-29 21:20 |只看该作者 |倒序浏览

                                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! :)
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20754/showart_511539.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP