Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install z3c.menu.simple

How to install z3c.menu.simple

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3c.menu.simple
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.6.0 Available View build log
Windows (64-bit)
0.6.0 Available View build log
Mac OS X (10.5+)
0.6.0 Available View build log
Linux (32-bit)
0.6.0 Available View build log
Linux (64-bit)
0.6.0 Available View build log
ZPL 2.1
Depended by
Lastest release
version 0.6.0 on Jan 5th, 2011

This package provides a simple menu implementation based on viewlets.

Simple Menu

The z3c.menu.simple package provides a simple menu implementation which allows you to implement simply menus based on content providers and viewlets.

Right now there are some SimpleMenuItem menu item implementations and a tabbed menu with tab/tab-item and action/action-item located in this package.

Let's see what this means.

>>> from zope.viewlet.interfaces import IViewlet
>>> from zope.viewlet.interfaces import IViewletManager

Let's create a menu which means we define a viewlet manager interface:

>>> class IMenu(IViewletManager):
...     """Menu viewlet manager."""

You can then create a viewlet manager using this interface now:

>>> from zope.viewlet import manager
>>> Menu = manager.ViewletManager('left', IMenu)

Now we have to define a context:

>>> import zope.interface
>>> from zope.app.container import contained
>>> from zope.app.container.interfaces import IContained
>>> class Content(contained.Contained):
...     zope.interface.implements(IContained)
>>> root['content'] = Content()
>>> content = root['content']
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> from zope.publisher.interfaces.browser import IBrowserView
>>> class View(contained.Contained):
...     zope.interface.implements(IBrowserView)
...     def __init__(self, context, request):
...         self.__parent__ = context
...         self.context = context
...         self.request = request
>>> view = View(content, request)
>>> menu = Menu(content, request, view)

So initially no menu get rendered:

>>> menu.update()
>>> menu.render()

But now we register a context menu item for the IMenu:

>>> import zope.component
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from z3c.menu.simple.menu import ContextMenuItem
>>> class MyLocalLink(ContextMenuItem):
...     __name__ = u'MyLocalLink'
...     urlEndings = 'myLocal.html'
...     viewURL = 'myLocal.html'
>>> # Create a security checker for viewlets.
>>> from zope.security.checker import NamesChecker, defineChecker
>>> viewletChecker = NamesChecker(('update', 'render'))
>>> defineChecker(MyLocalLink, viewletChecker)
>>> zope.component.provideAdapter(
...     MyLocalLink,
...     (zope.interface.Interface, IDefaultBrowserLayer,
...     IBrowserView, IMenu),
...     IViewlet, name='MyLocalLink')

Now see what we get if the IMenu viewlet manager get used:

>>> menu.update()
>>> print menu.render()
<a href=""

Now we create a tabbed menu called MasterMenu:

>>> class IMasterMenu(IViewletManager):
...     """Master menu viewlet manager."""

Let's create a viewlet manager using this interface and the TabMenu as base class:

>>> from z3c.menu.simple.menu import TabMenu
>>> MasterMenu = manager.ViewletManager('masterMenu', IMasterMenu,
...                                     bases=(TabMenu,))

We use the same context, request and view like before:

>>> masterMenu = MasterMenu(content, request, view)

So initially no menu get rendered:

>>> masterMenu.update()
>>> masterMenu.render()

Now we register a menu tab which is also a viewlet manager:

>>> from zope.browserpage import viewpagetemplatefile
>>> from z3c.menu.simple import ITab
>>> from z3c.menu.simple.menu import Tab
>>> class MyTabs(Tab):
...     template = viewpagetemplatefile.ViewPageTemplateFile('tab.pt')
>>> myTabs = MyTabs(content, request, view)

Also here, initially no tab get rendered:

>>> myTabs.update()
>>> myTabs.render()

Now we register a menu action which is also a viewlet manager:

>>> from z3c.menu.simple import IAction
>>> from z3c.menu.simple.menu import Action
>>> class MyActions(Action):
...     template = viewpagetemplatefile.ViewPageTemplateFile('action.pt')
>>> myActions = MyActions(content, request, view)

Also here, initially no tab get rendered:

>>> myActions.update()
>>> myActions.render()

After setup the TabMenu, Tab and Action viewlet managers, we start to register a tab menu item:

>>> from z3c.menu.simple.menu import TabItem
>>> class MyTab(TabItem):
...     __name__ = u'MyTab'
...     url = 'myTab.html'
...     selectedViewNames = ['myTab.html']
>>> tabChecker = NamesChecker(('update', 'render', 'css', 'selected'))
>>> defineChecker(MyTab, tabChecker)
>>> zope.component.provideAdapter(
...     MyTab,
...     (zope.interface.Interface, IDefaultBrowserLayer,
...     IBrowserView, ITab),
...     IViewlet, name='MyTab')

Now see what we get if the tab viewlet manager get rendered:

>>> myTabs.update()
>>> print myTabs.render()
<div class="tabMenu">
<span class="inactive-menu-item">
<a href="myTab.html">MyTab</a>

After showing how a tab menu item get used, we will register a menu action item.

>>> from z3c.menu.simple.menu import ActionItem
>>> class MyAction(ActionItem):
...     __name__ = u'MyAction'
...     title = 'myAction'
>>> actionChecker = NamesChecker(('update', 'render', 'title'))
>>> defineChecker(MyAction, actionChecker)
>>> zope.component.provideAdapter(
...     MyAction,
...     (zope.interface.Interface, IDefaultBrowserLayer,
...     IBrowserView, IAction),
...     IViewlet, name='MyAction')

Now see what we get if the action viewlet manager get used:

>>> myActions.update()
>>> print myActions.render()
<div class="actionMenuWrapper">
<ul class="actionMenu">
<li class="inactive-menu-item">
<a href="">
<div class="clearActionMenu" />


0.6.0 (2010-07-14)
  • Depend on zope.browserpage instead of zope.app.pagetemplate as

System Message: WARNING/2 (<string>, line 250)

Bullet list ends without a blank line; unexpected unindent.

needed code has been moved there.

  • No longer use deprecated zope.testing.doc[unit]test, use python's

System Message: WARNING/2 (<string>, line 253)

Bullet list ends without a blank line; unexpected unindent.

doctest instead.

0.5.2 (2009-11-19)
  • Removed zope.app.zapi dependency.
0.5.1 (2008-01-25)
  • Bug: Updated meta-data and documentation.
0.5.0 (2008-01-21)
  • Initial Release.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.