[Grok-dev] Re: menus

Martin Aspeli optilude at gmx.net
Mon Apr 23 16:28:44 EDT 2007

Martijn Faassen wrote:
> Hi there,
> This is just to start off some investigation of menus, as I'm starting 
> to feel the need for them.
> Zope 3 has a menu infrastructure I've used though never fully 
> understood. I've been trying to digest this text about it:
> http://svn.zope.org/Zope3/trunk/src/zope/app/publisher/browser/menu.txt?rev=67630
> but I'm still trying to understand it.
> Hopefully we can reuse some of the infrastructure described there and 
> translate it into Grok terms. It needs some thought thrown at it first 
> though, as the patterns aren't entirely clear to me yet.

The Zope 3 browser infrastructure is quite powerful, but I found it 
rather convoluted to understand (not so hard to use when you're just 
registering new menu items). Basically, a menu is a named utility 
providing IBrowserMenu, and has a menu item type. This is an interface 
which you either give or, if you just give a menu name, Zope 3 generates 
an interface class on the fly for you (which is why, I learned the hard 
way, using dotted names for browser menus is a bad idea...).

Menu items are looked up by finding all named adapters to this menu item 
type, and are then ordered and inspected and turned into a dict. They 
can be recursive if you use submenu items.

We made use of some of this infrastructure in plone.app.contentmenu, 
which you can see here:


We ended up having to write custom menu implementations which construct 
the appropriate dicts themselves, because our needs were rather more 
complex than "allow people to register another menu item here".

There are ways in which Grok could simplify this, and definitely +1 for 
having the ability to define menus in Grok! It may perhaps look like this:

class CustomAddMenu(grok.Menu):

class AddMeunItem(grok.MenuItem):

     title = u"Add foo"
     action = u""

... actually, add menus may need special treatment if you dont' want to 
get into factories and IAdding views, but you get the idea.

I'd also make it possible to override the method in grok.Menu which 
returns the menu items, so that you can have more advanced 
implementations than "find all menu items registered for me".


More information about the Grok-dev mailing list