#!/usr/bin/python

import pyatspi

def onCaretMoved(event):
    try:
        text = event.source.queryText()
    except NotImplementedError:
        return

    line = text.getTextAtOffset(text.caretOffset, pyatspi.TEXT_BOUNDARY_LINE_START)
    print "\nCurrent line: %s\nstartOffset: %s endOffset: %s caretOffset: %s" % \
        (line[0], line[1], line[2], text.caretOffset)

pyatspi.Registry.registerEventListener(onCaretMoved, "object:text-caret-moved")
pyatspi.Registry.start()
