I have a Ubuntu program that displays a complex Gtk Menu with up to 4 nesting levels and a total of well over 100 menu items (not elegant, I know). The menu items represent items in the database, and when this data changes, the menu needs to be rebuilt.
So I have a function that takes care of this:
def rebuild_asset_menu(self):
self.asset_menu.set_submenu(self._menu_bases())
GLib.idle_add(self.asset_menu.show_all)
self.asset_menu
is the menu item to which the massive submenu is attached. self._menu_bases()
builds the submenu structure and returns it.
The building of the menu structure runs really lovely when the program starts. But when the above code is called to update the submenu (essentially replacing it with a new submenu), the GUI becomes really slow and often the menu remains empty.
Is it simply because I have too many menu elements, or am I doing something wrong? Or is it Unity?
If I modify your code to this:
def rebuild_asset_menu(self):
print ("rebuild")
self.asset_menu.set_submenu(self._menu_bases())
print ("rebuild1")
self.asset_menu.show_all()
print ("rebuild2")
The program rebuilds the menu multiple times. This is your problem. I did not dig into the problem any further.