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) & 
          pyia.STATE_SYSTEM_INVISIBLE:
          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()
gainFocus
        source: [client | Mozilla Firefox Start Page - Mozilla Firefox]
        window: 524618
        thread: 568
        tstamp: 14692927
gainFocus
        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

6 thoughts on “Introducing Pyia

  1. Now that’s what i’m talking about. Excellent Eitan.

    on the face of it I don’t the the events area bad idea. as it is you use win events and not COM event sinks which always seemed odd to me. The wrap and ref looks good. The closer to pyatspi the easier we can port a11y apps between platforms which I think can only be good news

  2. Eitan says:

    Michal,
    I fixed the link above, so the EXE should work.
    Also, if you follow the github link, you could download a snapshot tarball of the tree, don’t need to install git.

  3. Eitan says:

    David, probably not yet. But I have a lot of good caching ideas in pyatspi that could be ported.

Comments are closed.