Jump to content

Pidgin, Dbus And Python Help Please


gnounc

Recommended Posts

[uPDATED]

Almost all of this code has been tested as working in chunks.

anything that doesnt work is likely down to bad syntax, and so far the only thing

I can peg as not working is the callbacks at the bottom.

I think this has something to do with me trying to call a class, because I had it working

with regular functions.

also if anyone knows how to retrieve buddy icons over dbus in pidgin, thats the last thing I dont have working.

any help would be greatly appreciated.

 
#!/usr/bin/env python
import os, gtk, pygtk, dbus, gobject
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")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")


def quit_cb(widget, data = None):
    if data:
        data.set_visible(False)
    gtk.main_quit()

def popup_menu_cb(widget, button, time, data = None):
    if button == 3:
        if data:
            data.show_all()
            data.popup(None, None, None, 3, time)




class buddy:
        def __init__(self, buddy, icon='offline.png'):
                self.buddy = buddy
                self.icon = icon
                statusIcon = gtk.StatusIcon()
                menu = gtk.Menu()
                menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
                menu.append(menuItem)  
                statusIcon.connect('popup-menu', popup_menu_cb, menu)
                statusIcon.set_visible(True)
                menuItem.connect('activate', quit_cb, statusIcon)



        def online(icon):
                statusIcon.set_from_file(icon)
                statusIcon.set_tooltip('Online')


        def offline():

                statusIcon.set_from_file('offline.png')
                statusIcon.set_tooltip('Offline')

        setIcon(icon)




try:
        f = open('buddies.cfg')
        try:
                for line in f.readlines():
                        buddy(line)
        finally:
                f.close()

### right now it doesnt grab buddy icon from anywhere...connect the proper callback to the class buddy
## to make it grab buddy icon from pidgin properly
### not sure if buddy.online/buddy.offline is the proper way to use those callbacks, but i think it is.
### also not sure if callbacks will trample over the icons made by the buddy list, or if they will run twice..
## not sure how to make it cooperate if not

##### and lastly, ffs; remember to drop the hardcoded filepaths!!!

bus.add_signal_receiver(buddy.online, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="BuddySignedOn")
bus.add_signal_receiver(buddy.offline, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="BuddySignedOff")
bus.add_signal_receiver(quit_cb, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="AccountSignedOff")


gtk.main()

Edited by gnounc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...