Connecting Tech Pros Worldwide Forums | Help | Site Map

Pygtk: dynamic menu

micmast's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Belgium
Posts: 137
#1: Mar 25 '09
Hey everybody,

I have a question, I'm building an application in which a popup menu has to be generated on the fly depending of the data being read from an xml file.

The first part is very simple and I have the items in an array and now I want to add them to an existing menu.


Some variables I use just so it all makes sense.
popup_left_menu_plugin: menuitem in a popup in which the other items should be placed
popup_menu_plugins: is an array that will hold the menuitems
tool_command: is a dictionary with the items to be added
Expand|Select|Wrap|Line Numbers
  1. for tool in tool_command.keys():
  2.             if str(len(tool)) != "0":
  3.                 self.popup_menu_plugins.append(gtk.MenuItem(tool))
  4.  
  5. for tools in self.popup_menu_plugins:
  6.             self.popup_left_menu_plugin.set_submenu(tools)
  7.  
  8.  
But that doesn't work, hence my question: how to fix this?

Thx in advance

micmast's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Belgium
Posts: 137
#2: Mar 25 '09

re: Pygtk: dynamic menu


I always seem to be fixing my own threads :)

Anyway here is the fix that solves the problem
I used the .append to append the menuitem to the menu instead of another menuitem, and then I used the .show to actually show the item...

*Sigh*
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,566
#3: Mar 25 '09

re: Pygtk: dynamic menu


micmast,

Sometimes describing a problem to others is enough to make a solution clearer. Thanks for the update.

-BV
Reply