[pygtk] Dynamically menus with UIManager
toshio at tiki-lounge.com
Thu Aug 11 03:15:09 WST 2005
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),)
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://localhost.localdomain/pipermail/pygtk/attachments/20050810/9761b7ee/attachment.pgp
More information about the pygtk