pigdin好友上线的提示 七拼八凑的脚本

上网、浏览、聊天、下载等
回复
zarra
帖子: 89
注册时间: 2006-10-30 20:01

pigdin好友上线的提示 七拼八凑的脚本

#1

帖子 zarra » 2008-06-14 19:48

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) 查看 631 次
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2008-06-14 20:09

记得有提示的啊。libnotify或者gnome-osd安装了后。
● 鸣学
zarra
帖子: 89
注册时间: 2006-10-30 20:01

#3

帖子 zarra » 2008-06-14 20:43

那个插件功能少 在我的arch上还有不少bug
懒的去改那个插件的代码了 所以自己作了个
回复