Last page update: November 23, 2011
Note
menu features:
- Type: Dojo-improved widget
- Common attributes: check the common attributes section
Menu creation:
You can create a menu:
appending it to a DropDownButton:
ddb = pane.dropdownbutton('NameOfTheMenu') menu = ddb.menu() # other lines...
appending it to a div:
menudiv = pane.div('-MENU-', height='20px', width='50px', background='teal') menu = menudiv.menu() # other lines...Menu features:
A menu has a hierarchic structure:
you can set lines through the menuline attribute:
- GnrDomSrc_dojo_11.menuline(label=None, **kwargs)¶
A line of a menu
Parameters:
- label – the menuline label. Set it to “-” to create a dividing line in the menu: menuline('-')
- kwargs –
- action: allow to execute a javascript callback. For more information, check the action page
- checked: boolean (by default is False). If True, allow to set a “V” mark on the left side of the menuline
In the image: the third menuline contains the “checked” attribute set to True (highlighted in yellow)
Below the “Load” menuline there’s a dividing line
![]()
You can set submenus creating a menu inside a menu:
ddb = pane.dropdownbutton('NameOfTheMenu') menu = ddb.menu() menu.menuline('First Line') submenu = menu.menuline('I have submenues').menu() # With this line you create a submenu submenu.menuline('First Line')You can use the action attribute (both on menu or on menulines) to create a javascript callback after mouse click. Check the action example
Note
example elements’ list:
- classes: GnrCustomWebPage
- components: TestHandlerFull
- webpage variables: py_requires
- widgets: DropDownButton, formbuilder
Code:
# -*- coding: UTF-8 -*- """menu_simple""" class GnrCustomWebPage(object): py_requires = 'gnrcomponents/testhandler:TestHandlerFull' def test_1_basic(self,pane): """simple menu""" fb = pane.formbuilder(cols=3) ddb = fb.dropdownbutton(iconClass='iconbox print', showLabel=False) dmenu = ddb.menu() dmenu.menuline('Print...', action="alert('Printing...')") dmenu.menuline('-') submenu = dmenu.menuline('Advanced options').menu() # With this line you create a submenu submenu.menuline('Preview', action="alert('Creating preview...')") submenu.menuline('PDF', action="alert('Making PDF...')") dmenu.menuline('-') dmenu.menuline('Cancel', action="alert('Abort print...')") ddb = fb.dropdownbutton('Save', iconClass='iconbox save') dmenu = ddb.menu() dmenu.menuline('Save', action="alert('Saved')") dmenu.menuline('Save as...', action="alert('Saved as...')") ddb = fb.dropdownbutton('Load', height='22px') dmenu = ddb.menu() dmenu.menuline('Load template', action="alert('Loaded')") dmenu.menuline('Load from file', action="alert('Loaded')")
Description: an example of the action attribute; it is set both on menu and on its menulines; the third menuline (labelled “menuline n.3”) contains an action, so this action prevails on the menu action (action='alert($1.foo)')
Note
example elements’ list:
- classes: GnrCustomWebPage
- components: TestHandlerFull
- webpage variables: py_requires
- widgets: DropDownButton
Code:
# -*- coding: UTF-8 -*- """menu_action""" class GnrCustomWebPage(object): py_requires = 'gnrcomponents/testhandler:TestHandlerFull' def test_2_alert(self, pane): """menu with alert attribute""" menudiv = pane.dropdownbutton('Menu') menu = menudiv.menu(action='alert($1.foo)') menu.menuline('menuline n.1', foo=36) menu.menuline('I\'m disabled', foo=60, disabled=True) menu.menuline('menuline n.3', action='alert("I\'m different")',checked=True) menu.menuline('-') submenu = menu.menuline('Sub').menu(action='alert("sub "+$1.bar)') submenu.menuline('submenuline n.1', bar=36) submenu.menuline('submenuline n.2', bar=60)
Enter search terms or a module, class or function name.