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) &
[window | ]
[window | Python Shell]
[window | Mozilla Firefox Start Page - Mozilla Firefox]
[window | Program Manager]
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):
source: [client | Mozilla Firefox Start Page - Mozilla Firefox]
source: [client | Python Shell]
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.