#!/usr/bin/python
import pyatspi

def isFocused(obj):
    if not obj:
        return False

    return obj.getState().contains(pyatspi.STATE_FOCUSED)

def listener(e):
    obj = e.source
    print "\n%s" % e.type 
    print "source (%s) is focused: %s" % (obj, isFocused(obj))

pyatspi.Registry.registerEventListener(listener, "object:active-descendant-changed")
pyatspi.Registry.start()
