#!/usr/bin/python

import pyatspi

def onFocus(event):
    if event.source.getRole() != pyatspi.ROLE_TEXT:
        return

    isFocused = event.source.getState().contains(pyatspi.STATE_FOCUSED)
    print event.type, isFocused

pyatspi.Registry.registerEventListener(onFocus, "focus:")
pyatspi.Registry.start()
