#!/usr/bin/python

import pyatspi

def findByRole(root, role):
    pred = lambda x: x.getRole() == role
    rv = pyatspi.findAllDescendants(root, pred)
    return rv

def onWindowActivate(event):
    root = event.source
    app = event.host_application

    treetables = findByRole(root, pyatspi.ROLE_TREE_TABLE)
    if not treetables:
        print "Tree table not found"
        return

    treetable = treetables[0]
    print "==================="
    print "treetable", treetable
    print "state set", treetable.getState()
    print "relation set", treetable.getRelationSet()

pyatspi.Registry.registerEventListener(onWindowActivate, 'window:activate')
pyatspi.Registry.start()

