Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GTK 3 - Popup menu to expand after adding items to it

I'm using GTK 3.4 with python (with GObject introspection).

I have pop-up menu build with Gtk.UIManager, some menu items are not active/visible when menu is instantiated. Later they are activated and they became visible in the menu.

However there is one small issue - the size one pop-up menu (height) seems to remain same - and I have to scroll though menu items now - on top and bottom of menu area there are ^ v arrows to show that items do not fit area and that it is possible to scroll up and down. However I would very much prefer if size of pop-up just changes when it is shown.

Popup is instantiated once on app. object like this:

menu_manager=Gtk.UIManager()
menu_manager.insert_action_group(self.core_actions)
menu_manager.insert_action_group(self.power_type_actions)
menu_manager.add_ui_from_file(os.path.join(_curr_dir, 'ui', 'menus.xml'))
self.menu_manager=menu_manager
self.popup=menu_manager.get_widget('/popup')

and the shown on tray icon with this signal handler:

def show_menu(self, tray_icon, button, activate_time, user_data=None):  
    def pos(menu, icon): 
        p= Gtk.StatusIcon.position_menu(menu, icon)
        return p
    log.debug( 'Menu button=%s, time=%s', button, activate_time)
    self.popup.popup(None, None, pos, tray_icon, button, activate_time )

Is there any way how to force menu on pop-up to resize to show all of its items without need to scroll?

like image 680
Ivan Avatar asked Nov 23 '12 21:11

Ivan


1 Answers

By your request, I'm assuming you want the menu to be big enough to avoid scrolling. According to the GTK+ 3 documentation, GtkMenu is a subclass of GtkWidget. So, logically, you should be able to request the size of the menu. Try various sizes until one is big enough. That documentation is for C, but it should still apply to Python. https://developer.gnome.org/gtk3/stable/GtkWidget.html https://developer.gnome.org/gtk3/3.1/GtkMenu.html

like image 77
kirbyfan64sos Avatar answered Nov 10 '22 10:11

kirbyfan64sos