View Single Post
Posts: 5 | Thanked: 0 times | Joined on Jul 2010
#77
Originally Posted by b666m View Post
here you go:

Code:
#!/usr/bin/env python

def showconv_cb (n, action):
	assert action == "showconv"
	print "Click :D"
	n.close()

def my_func(account, sender, message, conversation, flags):

	if bus.pidginbus.PurpleConversationHasFocus(conversation) == 0:

		name = str(sender.split("@")[0])
		buddy = bus.pidginbus.PurpleFindBuddy(account,name)
		alias = bus.pidginbus.PurpleBuddyGetAlias(buddy)
		#icon = bus.pidginbus.PurpleBuddyGetIcon(buddy)
		#icon_path = bus.pidginbus.PurpleBuddyIconGetFullPath(icon)
		proto = bus.pidginbus.PurpleAccountGetProtocolName(account)
		#proid = bus.pidginbus.PurpleAccountGetProtocolId(account)
		conv = str(conversation)

		if alias == "":
			alias = name

		msg = message

		if proto == "XMPP":
			msg = msg[6:-7]
		
		elif proto == "MSN":
			col = msg.find("COLOR")
			if col > -1:
				msg = msg[col+16:-14]

		msg = msg.replace("\n"," ")
		msg = "\""+msg
		if len(msg) > 32:
			msg = msg[:33]+"...\""
		else:
			msg = msg+"\""			

		print alias, "("+sender+") said \""+message+"\" in proto", proto
		#with icon at", icon_path, "in conv", conv

        # it's only commented out for test-reasons because i only try it on ubuntu and console with print
        pynotify.init(os.path.splitext(os.path.basename(sys.argv[0]))[0])
        n = pynotify.Notification(alias+" ("+proto+")",msg,"pidgin")
        # -------------------------
        # maybe the next two lines can be used for bringing the conversation window to the foreground 
        # when the notification is being clicked by the user
        # if that is not possible: comment them out or delete them (no use for them)
        n.set_hint_string("dbus-callback-default","im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject        im.pidgin.purple.PurpleInterface purple_conversation_present int32:"+conv)
        # n.set_hint_string("dbus-callback-default","com.nokia.osso_browser /com/nokia/osso_browser com.nokia.osso_browser      open_new_window string:\"callto://666\"")
        n.add_action("showconv", "ShowConv Action", showconv_cb)
        n.set_timeout(3000)
        # or do i have to make an "add_action" for the notification?
        # maybe i can just put three NULL arguments there ^^
        # ------------------------
        n.show()

        bus.mcebus.ReqVibratorPatternActivate("PatternChatAndEmail")

import os
import sys
import gobject, dbus
import pynotify

from dbus.mainloop.glib import DBusGMainLoop

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
bus.pidginbus = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

objv = bus.get_object("com.nokia.mce.request", "/com/nokia/mce/request")
bus.mcebus = dbus.Interface(objv, "com.nokia.mce" )

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

loop = gobject.MainLoop()
loop.run()
ty for postin but some reason it doesnt work... the other 1 you posted before this worked..