#!/usr/bin/python
import pyatspi

def findStatusBars(window):
    isStatusBar = lambda x: x.getRole() == pyatspi.ROLE_STATUS_BAR
    return pyatspi.utils.findAllDescendants(window, isStatusBar)

def listener(e):
    statusbars = findStatusBars(e.source)
    print '\n%s from %s has %i status bars' % (e.source, e.host_application, len(statusbars))
    for s in statusbars:
        try:
            text = s.queryText()
        except NotImplementedError:
            string = '(text iface not implemented)'
        else:
            string = text.getText(0, -1)

        print 'Name: %s\nText: %s\nChild count: %i' % (s.name, string, s.childCount)

pyatspi.Registry.registerEventListener(listener, "window:activate")
pyatspi.Registry.start()
