#!/usr/bin/python
import pyatspi

def listener(e):
    obj = e.source
    if obj.getRole() != pyatspi.ROLE_LABEL:
        return

    msg = "%s detail1: %s detail2: %s" % (e.type, e.detail1, e.detail2)
    if e.type == "object:text-caret-moved":
        msg = "\n%s" % msg
    print msg

pyatspi.Registry.registerEventListener(listener, "object:text-selection-changed", "object:text-caret-moved")
pyatspi.Registry.start()
