当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 3 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : pigdin好友上线的提示 七拼八凑的脚本
帖子发表于 : 2008-06-14 19:48 

注册: 2006-10-30 20:01
帖子: 89
送出感谢: 0 次
接收感谢: 0 次
pidgin有个 好友千里眼的功能 能提示好友的上下线 但是设置起来麻烦。
google了一下 搜集了点脚本 拼凑出这个功能

代码:
#!/usr/bin/env python

import dbus, gobject, dbus.glib
import gtk.gdk
# Initiate a connection to the Session Bus
bus = dbus.SessionBus()

# Associate Pidgin's D-Bus interface with Python objects
obj = bus.get_object(
    "im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
pidgin = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

# Associate libnotify's D-Bus interface with Python objects

notify_obj = bus.get_object(
    "org.freedesktop.Notifications", "/org/freedesktop/Notifications")
notify = dbus.Interface(notify_obj, "org.freedesktop.Notifications")

# Create a global Pidgin buddy data cache
buddy_data_cache = {}
screen=gtk.gdk.screen_get_default()
hints={'x':screen.get_width(),'y':0}


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[i] == '<':
            while s_list[i] != '>':
                # 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 onReceivedImMsg(account, sender, message, conv, flags):
    bId=pidgin.PurpleFindBuddy(account,sender)
    buddyAlias = pidgin.PurpleBuddyGetAlias(bId)
    buddyName = pidgin.PurpleBuddyGetName(bId)
    buddy=(buddyAlias==None)and buddyName or buddyAlias
    text = ""

    text +=strip_ml_tags(message)
    nId=notify.Notify("New Pidgin Msg Notification", 0, "gtk-connect", "You got a new msg from %s!"%(buddy,), text, ["message", "Send Message"], hints, 9000)
    buddy_data_cache[nId] = (account, buddyName)

def onSignOn(bId):
  # Extract a Pidgin buddy's name and alias
  buddyAlias = pidgin.PurpleBuddyGetAlias(bId)
  buddyName = pidgin.PurpleBuddyGetName(bId)

  # Generate notification text based on the buddy's name and alias

  text = buddyAlias == buddyName and \
    "<b>%s</b> is now online." % buddyName or \
    "<b>%s</b> <i>(%s)</i> is now online." % (buddyAlias, buddyName)

  # Display a notification bubble with a button to launch a conversation
  nId = notify.Notify("DBus Test", 0, "gtk-connect", "Buddy Signed On",
      text, ["message", "Send Message"], hints, 9000)

  # Add the buddy ID and name to the global buddy data cache

  buddy_data_cache[nId] = (pidgin.PurpleBuddyGetAccount(bId), buddyName)
 
def onSignOff(bId):
  # Extract a Pidgin buddy's name and alias
  buddyAlias = pidgin.PurpleBuddyGetAlias(bId)
  buddyName = pidgin.PurpleBuddyGetName(bId)

  # Generate notification text based on the buddy's name and alias
  text = buddyAlias == buddyName and \
    "<b>%s</b> is now offline." % buddyName or \
    "<b>%s</b> <i>(%s)</i> is now offline." % (buddyAlias, buddyName)

  nId = notify.Notify("DBus Test", 0, "", "Buddy Signed Off",
      text, [], hints, 9000)


def onNotifyClose(nId):
  # Remove entry from the global buddy data cache when the bubble closes
  if nId in buddy_data_cache:
    del buddy_data_cache[nId]

def onNotifyAction(nId, actKey):
  # Launch a new conversation when user clicks the message button
  print 'onNotifyAction'
  if actKey == "message":
    pidgin.PurpleConversationNew(1, *buddy_data_cache[nId])

# Bind the onSignOn function with Pidgin's BuddySignedOn event
bus.add_signal_receiver(onSignOn,
  dbus_interface="im.pidgin.purple.PurpleInterface",
  signal_name="BuddySignedOn")

# Bind the onSignOff function with Pidgin's BuddySignedOff event
bus.add_signal_receiver(onSignOff,
  dbus_interface="im.pidgin.purple.PurpleInterface",
  signal_name="BuddySignedOff")

bus.add_signal_receiver(onReceivedImMsg,
    dbus_interface = "im.pidgin.purple.PurpleInterface",
    signal_name = "ReceivedImMsg")

# Bind the onNotifyAction function to libnotify's ActionInvoked event
bus.add_signal_receiver(onNotifyAction,
    dbus_interface="org.freedesktop.Notifications",
    signal_name="ActionInvoked")


# Bind the onNotifyClose function to libnotify's CloseNotification event
bus.add_signal_receiver(onNotifyClose,
    dbus_interface="org.freedesktop.Notifications",
    signal_name="NotificationClosed")

# Start the main loop
gobject.MainLoop().run()


附件:
screen.png
screen.png [ 11.59 KiB | 被浏览 556 次 ]
页首
 用户资料  
 
2 楼 
 文章标题 :
帖子发表于 : 2008-06-14 20:09 
头像

注册: 2005-08-14 21:55
帖子: 58428
地址: 长沙
送出感谢: 4
接收感谢: 272
记得有提示的啊。libnotify或者gnome-osd安装了后。


_________________
● 鸣学


页首
 用户资料  
 
3 楼 
 文章标题 :
帖子发表于 : 2008-06-14 20:43 

注册: 2006-10-30 20:01
帖子: 89
送出感谢: 0 次
接收感谢: 0 次
那个插件功能少 在我的arch上还有不少bug
懒的去改那个插件的代码了 所以自己作了个


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 3 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 5 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译