Skip to content

Instantly share code, notes, and snippets.

@takeshixx
Created November 3, 2015 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeshixx/da42c1a63207ceb068c7 to your computer and use it in GitHub Desktop.
Save takeshixx/da42c1a63207ceb068c7 to your computer and use it in GitHub Desktop.
Python D-Bus example for Pidgin
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
DEBUG = True
import dbus, gobject,re,pynotify
from dbus.mainloop.glib import DBusGMainLoop
dingregex = re.compile(r'(ding)',re.IGNORECASE)
def check_ding(account, sender, message, conv, flags):
sender = sender.encode('utf-8')
message = message.encode('utf-8')
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
title = purple.PurpleConversationGetTitle(conv).encode('utf-8')
if not title:
title = conv
if len(dingregex.findall(message)) > 0:
pynotify.init("Basics")
notify = pynotify.Notification("DING DING DING","{} called for DING DING DING in {}".format(sender,title),"emblem-danger")
notify.set_timeout(pynotify.EXPIRES_NEVER)
notify.show()
if DEBUG:
print "sender: {} message: {}, account: {}, conversation: {}, flags: {}, title: {}".format(sender,message,account,conv,flags,title)
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(check_ding,
dbus_interface="im.pidgin.purple.PurpleInterface",
signal_name="ReceivedChatMsg")
loop = gobject.MainLoop()
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment