#!/usr/bin/python

import pyatspi

def listener(e):
    try:
        if e.source.getRole() != pyatspi.ROLE_DOCUMENT_FRAME:
            return
    except:
        return

    try:
        text = e.source.queryText()
    except:
        print("Exception querying text interface")
        return

    print(text.getTextAtOffset(e.detail1, pyatspi.TEXT_BOUNDARY_LINE_START))

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