开发者

Triggering a Gtk+ menu bar on hover

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 th开发者_开发技巧e 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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜