#!/usr/bin/python3

import pyatspi

def listener(e):
    try:
        t = e.source.queryText()
    except:
        return

    [attrs, startOffset, endOffset] = t.getAttributeRun(0, True)
    for attr in attrs:
      if attr.startswith("family-name"):
        print ("queried getAttributeRun with includeDefaults=True: %s" % (attr))
        
    [attrs, startOffset, endOffset] = t.getAttributeRun(0, False)
    for attr in attrs:
      if attr.startswith("family-name"):
        print ("queried getAttributeRun with includeDefaults=False: %s" % (attr))

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