#!/usr/bin/python import pyatspi import sys def magnifyAccessible(event, obj=None, extents=None): if event.source and event.source.getRole() == pyatspi.ROLE_TERMINAL: # protection against parasite events from terminals return if event.type.startswith("object:state-changed") and not event.detail1: # This object just became unselected or unfocused, and we're not # big on nostalgia. return obj = obj or event.source x, y, width, height = -1,-1,-1,-1 if event and event.type.startswith("object:text-caret-moved"): try: text = obj.queryText() if text and (text.caretOffset >= 0): offset = text.caretOffset if offset == text.characterCount: offset -= 1 [x, y, width, height] = text.getCharacterExtents(offset, 0) except: pass print "position: %i,%i size %i:%s" %(x, y, width, height) def startTracking(): pyatspi.Registry.registerEventListener(magnifyAccessible, "object:text-caret-moved") def stopTracking(): pyatspi.Registry.deregisterEventListener(magnifyAccessible, "object:text-caret-moved") def main(): startTracking() pyatspi.Registry.start() return 0 if __name__ == "__main__": sys.exit(main())