Thanks. This seems to work well.
Don
Toshio Kuratomi wrote:
On Tue, 2005-08-09 at 22:29 -0600, Don Allingham wrote:
I've started using UIManager to handle my toolbar and menubar. The
action groups and ui merging have proven to be very powerful.
However, there are a few cases where I would like to have dynamic menus
attached to the menubar. Examples include a history mechanism and a
bookmark list.
Any ideas on how I would dynamically add menu items to a menu that is
generated by UIManager?
I've started experimenting with this as I wanted to be able to load
different menus into qa-assistant depending on what checklist was loaded
by the user. The basic recipe for adding the dynamic menu is like this:
1) Create the uimanager definition for the static-menus with a place for
the dynamic menu to exist.
2) When something happens that modifies the dynamic menu (startup,
adding a bookmark, loading a new page, etc):
A) unmerge the old uimanager xml definition using the mergeID
B) remove the old dynamic menu actiongroup
C) Create the new actiongroup and add it to the uimanager, saving a
reference to it so you can remove it later.
i) Use a generic callback (ex: goto_bookmark_cb()) in the
actiongroup definition. Add it to the actiongroup with userdata
to differentiate. ex:
self.bookmarkAG = gtk.ActionGroup()
for URL in bookmarks:
actions = ((URL, None, URL, None, None, goto_bookmark_cb),)
self.bookmarkAG.add_actions(actions, URL)
D) create or modify the new uimanager xml definition
E) merge the new definition, saving the mergeID to remove later.
I think this leverages the power of uimanager and the actiongroups as
far as possible. If you spot something more to the problem I'd like to
know as it could quite possibly help my code as well.
-Toshio
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/