[Grok-dev] How to create an interface providing another interface

Simon Elbaz simon.elbaz at free.fr
Thu Feb 5 08:32:29 EST 2009


Hi,
In the menu.txt file 
(zope.app.publisher/trunk/src/zope/app/publisher/browser/,  line n°260), 
menu item are implemented with MenuItemFactory:
 >>> from zope.app.testing import ztapi
 >>> from zope.publisher.interfaces.browser import IBrowserRequest

 >>> undo = menumeta.MenuItemFactory(menu.BrowserMenuItem, title="Undo",
... action="undo.html")

Then an adapter called 'undo' adapts (IContent,IBrowserRequest) to the 
interface EditMenu is registered with the factory undo (which will be 
the result of a future lookup)

 >>> ztapi.provideAdapter((IContent, IBrowserRequest), EditMenu, undo, 
'undo')

The interface EditMenu provides IMenuItemType (menu.txt, line n°23).

To display menu items, the menu.getMenu function is called.

 >>> pprint(menu.getMenu('edit', Content(), TestRequest()))

Looking in menu.py, the function getMenu gets the utility providing 
IBrowserMenu under the name 'edit'. The utility was implemented in 
menu.txt whith the id 'edit' (line n°31):
 >>> from zope.app.publisher.interfaces.browser import IBrowserMenu
 >>> ztapi.provideUtility(
... IBrowserMenu, menu.BrowserMenu('edit', u'Edit', u'Edit Menu'), 'edit')

Then it calls getMenuItems which in turn calls :

 >>> zope.component.getAdapters((object, request), self.getMenuItemType())

The getMenuItemType function gets the utility providing IMenuItemType 
under the name 'edit':the result is the EditMenu interface defined at 
line n°23. The getAdapters function returns the factory stored for all 
the adapters of (object, request) implementing EditMenu interface. These 
factories are the menu items.

If you followed me till here, thank you :)
This is what I have understood from menu.py and menu.txt. I need to 
create an interface like EditMenu, providing IMenuItemType interface.

Thanks for your help
Simon Elbaz


Lennart Regebro wrote:
> On Wed, Feb 4, 2009 at 19:02,  <simon.elbaz at free.fr> wrote:
>   
>> Hi,
>> I try to create an interface providing another interface.
>>     
>
> I have no idea what that would mean. How does an interface provide an
> interface? What's the usecase?
>
>   



More information about the Grok-dev mailing list