tags:

views:

25

answers:

2

I've writing a Gnome window-switcher applet in PyGtk+ using menu items to represent the different applications running on the desktop. One thing I'd like to do is to activate the menu item under the cursor when I hover over the menubar. I can connect to the 'enter-notify-event' on the menu bar, but I don't know what to when it is triggered.

So that's my question, how can I make the submenus of the menu bar open when I hover over their parent items?

A: 

You can emulate the click event in the location of entering.

buratinas
Do you know how to do that? I've been looking and I can't figure it out (I'm reasonably new to Gtk+).
Kazade
+1  A: 

This should do the trick:

event = gtk.gdk.Event(gtk.gdk.BUTTON_RELEASE)
event.window = enter_event.window
event.x = enter_event.x
event.y = enter_event.y
event.button = 1
menu.emit('button_release_event', event)

It will create a new event object, set it up using the enter_event from your enter-notify-event and then emit it on your menu.

You can read more on events here:
http://www.pygtk.org/docs/pygtk/class-gdkevent.html

Ivo Wetzel
This *almost* works. I'm not sure whether I should be watching for enter/leave events on the gtk.MenuBar, gtk.MenuItem or gtk.Menu . Using the above code with the MenuBar doesn't do anything, replacing with BUTTON_PRESS and button-press-event works, but it causes a segfault after moving the cursor off and on the menu a few times. Commenting out the creation of the button press event stops the crash so it's the creation of the event causing the segfault.
Kazade
Ignore that, the crash is caused by me calling MenuBar.cancel() in the leave notify event. I'll try and work around that, thanks!
Kazade