Re: Programatically activate menu like a mouse click




Give this a try. It might be close to what you are after.

Thanks Eric. That works, however it is slightly different to what I need.

Firstly, my app is a dock containing nothing but a menu bar, so it has
no "window" as such.

Secondly, its key binding only works when its window has the focus. I
need to globally bind a key so that it works regardless of the active
application and this is why I have used the keybinder module.

I have distilled an example and uploaded it as
https://gist.github.com/db6bf5247058e32ffa5d794af37b80a3

It's very similar to your example except I create a dock and have been
trying to use XML to generate menu items as well as doing it in code
like my example shows.

My example runs and the menus work as long as they are "activated" with
the mouse, after which the mouse or keyboard can be used to navigate the
menu.

The key binding works, it just doesn't activate the menu. You can see
the three things I tried in the code, two of them are commented out. The
bound key is "Menu" (right-hand bottom of keyboard near right-alt) and
the binding works when another application window is active.

I just need the keybinder_callback to also perform similar "activation"
of the menu. I don't even care whether it displays an initial submenu or
just keyboard-focusses the menubar - the aim is to be able to hit the
bound "Menu" key and then operate the menu with the keyboard (like I can
after activating it with the mouse).

I have also tried 'select_item' (as suggested by Colomban) which does
select the first item in the menu bar but after that the app locks up
and nothing responds, not even with the mouse.

Many thanks,
John




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]