#!/usr/bin/python3

import pyatspi

def listener(e):
    if not e.detail1:
        return

    menuRoles = [pyatspi.ROLE_MENU,
                 pyatspi.ROLE_MENU_ITEM,
                 pyatspi.ROLE_CHECK_MENU_ITEM,
                 pyatspi.ROLE_RADIO_MENU_ITEM]

    if not e.source.getRole() in menuRoles:
        return

    print(e)

pyatspi.Registry.registerEventListener(
    listener,
    "object:state-changed:focused",
    "object:state-changed:selected")
pyatspi.Registry.start()
