Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kind request: getMenu() tutorial #9

Closed
macdeport opened this issue Mar 29, 2022 · 1 comment
Closed

Kind request: getMenu() tutorial #9

macdeport opened this issue Mar 29, 2022 · 1 comment

Comments

@macdeport
Copy link

Please provide a tutorial for calling GetMenu() and displaying the resultant sub-menu tree or something like that ;-)
Thanks.

@Kalmat
Copy link
Owner

Kalmat commented Mar 30, 2022

Hi again!

My apologies since I thought it would be clear enough because format and content of getMenu() output is documented on the README file. Besides, you can print it in a legible format just using json.dumps, like this:

npw = getActiveWindow()
menu = npw.menu.getMenu()
print(json.dumps(menu, indent=4, ensure_ascii=False))

This would produce this output for "Terminal" app (I'm cutting it off since it's extremely large. I'm attaching the complete file anyway):

{
    "Apple": {
        ...
}
{
    "Terminal": {
        "hSubMenu": 3,
        "wID": 64,
        "entries": {
            "Acerca de Terminal": {
                "parent": 3,
                "wID": 65,
                "rect": [0, 0, 225, 19],
                "hSubMenu": 0
            },
            "separator": {},
            "Preferencias…": {
                "parent": 3,
                "wID": 66,
                "rect": [0, 31, 225, 50],
                "hSubMenu": 0
            },
            "Entrada de teclado segura": {
                "parent": 3,
                "wID": 67,
                "rect": [0, 50, 225, 69],
                "hSubMenu": 0
            },
            "Servicios": {
                "parent": 3,
                "wID": 68,
                "rect": [0, 81, 225, 100],
                "hSubMenu": 4,
                "entries": {
                    "Ningún servicio aplicable": {
                        "parent": 3,
                        "wID": 69,
                        "rect": [0, 0, 251, 19]
                    },
                    "Preferencias de los servicios…": {
                        "parent": 3,
                        "wID": 70,
                        "rect": [0, 19, 251, 38]
                    }
                }
            },
            "Ocultar Terminal": {
                "parent": 3,
                "wID": 71,
                "rect": [0, 112, 225, 131],
                "hSubMenu": 0
            },
            "Ocultar otros": {
                "parent": 3,
                "wID": 72,
                "rect": [
                    0,
                    131,
                    225,
                    150
                ],
                "hSubMenu": 0
            },
            "Mostrar todo": {
                "parent": 3,
                "wID": 73,
                "rect": [0, 150, 225, 169],
                "hSubMenu": 0
            },
            "Salir de Terminal": {
                "parent": 3,
                "wID": 74,
                "rect": [0, 181, 225, 200],
                "hSubMenu": 0
            },
            "Salir y mantener ventanas": {
                "parent": 3,
                "wID": 75,
                "hSubMenu": 0
            }
        }
    },
    "Shell": {
        "hSubMenu": 5,
        "wID": 76,
        "entries": {
            "Nueva ventana": {
                "parent": 5,
                "wID": 77,
                "rect": [0, 0, 319, 19],
                "hSubMenu": 6,
                "entries": {
                    "Nueva ventana con perfil - Basic": {
                        "parent": 5,
                        "wID": 78,
                        "rect": [0, 0, 333, 19]
                    },
                    "Nueva ventana con el mismo comando": {
                        "parent": 5,
                        "wID": 79,
                        "rect": [0, 19, 333, 38]
                    },
    ...
}

As you can see, every menu item is represented by a dictionary key, which has all information key/values inside.
The result is a nested struct since every sub-menu will have all its sub-items inside, within "entries" key (or none in case it is not a sub-menu, but a "final" menu item).

test.zip

@Kalmat Kalmat closed this as completed Apr 5, 2022
Repository owner deleted a comment from macdeport Apr 7, 2022
Repository owner deleted a comment from macdeport Apr 7, 2022
@Kalmat Kalmat pinned this issue Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants