Programatically activate menu like a mouse click



I am trying to write a small test app using Python and Gtk+3

It's basically a bar across the top of the display that contains a menu
implemented as a Gtk.Window containing a Gtk.Bar containing a menu bar
populated using UIManager. Essentially this (where 'self' is an object
derived from `Gtk.Window`):

        box = Gtk.Box();
        menubar =  uimanager.get_widget("/MenuBar")
        self.menu = menubar
        box.pack_start(menubar, False, False, 0)
        self.add(box)

The UIManager provides the menu bar, a few items in the bar each leading
to menus containing a few items. The user can click operate the menu
with a mouse and selecting a menu item triggers a callback that prints
the name of the selected item. Nothing special thus far, but it works.

Once the user has clicked on a menu bar item with the mouse, she can
then navigate the menu with the keyboard (or continue using the mouse).

I have wired up a global key binding using the 'keybinder' module and
receive a callback when a mapped key is pressed. I want to activate the
menu in the same way as that initial mouse click. I can't work out how
to do that, despite reading and searching for days!

Here's my keybinder callback (it is called when the key is hit but it
does not activate the menu):

    def keybinder_callback(self, keystr, user_data):
        print("Handling", keystr, user_data)
        print("Event time:", Keybinder.get_current_event_time())
        self.menu.popup(None,None,None,None,1,
                                  Keybinder.get_current_event_time())


How can I trigger the menu activation (like a mouse click does) ?



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