Search code examples
gtkpygtk

gtk.StatusIcon and gtk.Menu on Windows


I have a crossplatform app that has a gtk.StatusIcon sitting in the tray, and a right click context menu. The problem is: on Windows machines the placement of the menu is awful. The top of the menu starts at the mouse pointer and so most of the menu extends below the bottom of the screen. This can then be scrolled up and is usable, but it is a bit of a pain for the user.

Another related question, is it possible to make the menu disappear if the user clicks somewhere else on the screen?


Solution

  • To avoid this "scrolling menu" problem on Windows you need to replace gtk.status_icon_position_menu with None in "popup-menu" signal callback.

    def popup_menu_cb(status_icon, button, activate_time, menu):
        menu.popup(None, None, None, button, activate_time)
    

    The menu will show on the mouse cursor but that's how all windows programs do it.

    Don't know how to hide it though... the only thing I found to work is pressing a mouse button on the menu and releasing it outside. :P