Introducing Pyia

Last week I was doing my best to dive into the wonderful world of Windows accessibility. So to flatten the curve, I decided to take shot at making a lightweight Python MSAA client library, Pyia.

It is heavily inspired by pyatspi‘s class mixins. pyOrbit made it very easy to do this in pyatspi, making CORBA friendly and Pythonic. Comtypes, does the same in Windows, making COM cool as a cucumber.

Accessible objects emulate containers for easy access to children nodes. Also notice a few convienient methods, like getDesktop which returns the desktop client. Also getStateName will return a human readable list of states rather than a bitmask.

>>> import pyia
>>> desktop = pyia.getDesktop()
>>> for window in desktop:
        if not window.accState(0) & 
          print window

[window | ]
[window | Python Shell]
[window | Mozilla Firefox Start Page - Mozilla Firefox]
[window | Program Manager]

>>> desktop[14].accStateName()
u'unavailable invisible'

This might be a bad idea, but I added some AT-SPI concepts, for example a registry, where you connect event callbacks. Also, events are wrapped in structures with a “source” field that is a reference to the accessible that is responsible for the event. There is no extra wire traffic because the reference is not retrieved until the source field is either explicitly called, or the event is printed (converted to a string).

>>> import pyia
>>> def event_cb(event):
        print event

>>> pyia.Registry.registerEventListener(
        event_cb, pyia.EVENT_OBJECT_FOCUS)
>>> pyia.Registry.start()
        source: [client | Mozilla Firefox Start Page - Mozilla Firefox]
        window: 524618
        thread: 568
        tstamp: 14692927
        source: [client | Python Shell]
        window: 1573178
        thread: 352
        tstamp: 14694599

You could try this stuff out by checking it out from Github.
If that is too much overhead, here is a binary Windows installer.

You will need the comtypes Python module.

Introducing Pyia