Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:26:27+00:00 2026-05-15T19:26:27+00:00

I have an little script which logs users that login to my Pidgin/MSN account

  • 0

I have an little script which logs users that login to my Pidgin/MSN account

#!/usr/bin/env python

def log_names(buddy):
    name = str(purple.PurpleBuddyGetName(buddy))
    account = purple.PurpleAccountGetUsername(purple.PurpleBuddyGetAccount(buddy))

    if account == u'dummy_account@hotmail.com':

        try: log[name] += 1
        except KeyError: log[name] = 1
        log.sync()


import dbus, gobject, shelve
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

log = shelve.open('pidgin.log')

obj = bus.get_object('im.pidgin.purple.PurpleService',
                     '/im/pidgin/purple/PurpleObject')
purple = dbus.Interface(obj, 'im.pidgin.purple.PurpleInterface')
bus.add_signal_receiver(log_names,
                       dbus_interface='im.pidgin.purple.PurpleInterface',
                       signal_name='BuddySignedOn')

loop = gobject.MainLoop()
loop.run()

I wanna add a simple interactive console to this which allows me to query the data from the log object, but I’m stuck at how I would implement it

Do I use threads of some kind or am I able to use some sort of call back within gobject.MainLoop()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:26:27+00:00Added an answer on May 15, 2026 at 7:26 pm

    You should look in the direction of general GObject/GLib programming (this is where gobject.MainLoop() is coming from). You could use threads, you could use event callbacks, whatever. For example, this is a simple ‘console’ using event callbacks. Add this just before the loop.run():

    import glib, sys, os, fcntl
    
    class IODriver(object):
        def __init__(self, line_callback):
            self.buffer = ''
            self.line_callback = line_callback
            flags = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
            flags |= os.O_NONBLOCK
            fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, flags)
            glib.io_add_watch(sys.stdin, glib.IO_IN, self.io_callback)
    
        def io_callback(self, fd, condition):
            chunk = fd.read()
            for char in chunk:
                self.buffer += char
                if char == '\n':
                    self.line_callback(self.buffer)
                    self.buffer = ''
    
            return True
    
    def line_entered(line):
        print "You have typed:", line.strip()
    
    d = IODriver(line_entered)
    

    If you are building a PyGTK application, you don’t have to call the mainloop specially for the dbus, because it will use the main application’s mainloop. There also other mainloops for other libraries available, for example dbus.mainloop.qt for PyQt4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this python script which is supposed to wrap all that look like
I have a Python script which uses Tkinter for the GUI. My little script
I have a little python script that I am using to download a whole
I have a little script that checks for cookies and I was wondering how
I have this little script that shows one wisdom each day. so I have
i have a little script which fetches the likes and tweets count about a
I have wrote this little script which generates a nice random password. The problem
I have a problem with a little C script which should run as a
I have this little script, which should ping the IPs in the $hosts_to_ping array.
I have the following script which I need to modify a little. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.