Package muntjac :: Package ui :: Module menu_bar :: Class MenuItem
[hide private]
[frames] | no frames]

Class MenuItem

source code

object --+
         |
        MenuItem

A composite class for menu items and sub-menus. You can set commands to be fired on user click by implementing the menu_bar.ICommand interface. You can also add multiple MenuItems to a MenuItem and create a sub-menu.

Instance Methods [hide private]
 
__init__(self, caption, icon, command, menu)
Constructs a new menu item that can optionally have an icon and a command associated with it.
source code
 
hasChildren(self)
Checks if the item has children (if it is a sub-menu).
source code
 
addSeparator(self)
Adds a separator to this menu.
source code
 
addSeparatorBefore(self, itemToAddBefore) source code
 
addItem(self, *args)
Add a new item inside this item, thus creating a sub-menu.
source code
 
addItemBefore(self, caption, icon, command, itemToAddBefore)
Add an item before some item.
source code
 
getCommand(self)
For the associated command.
source code
 
getIcon(self)
Gets the objects icon.
source code
 
getParent(self)
For the containing item.
source code
 
getChildren(self)
This will return the children of this item or null if there are none.
source code
 
getText(self)
Gets the objects text
source code
 
getSize(self)
Returns the number of children.
source code
 
getId(self)
Get the unique identifier for this item.
source code
 
setCommand(self, command)
Set the command for this item.
source code
 
setIcon(self, icon)
Sets the icon.
source code
 
setText(self, text)
Set the text of this object.
source code
 
removeChild(self, item)
Remove the first occurrence of the item.
source code
 
removeChildren(self)
Empty the list of children items.
source code
 
setParent(self, parent)
Set the parent of this item.
source code
 
setEnabled(self, enabled) source code
 
isEnabled(self) source code
 
setVisible(self, visible) source code
 
isVisible(self) source code
 
setSeparator(self, isSeparator) source code
 
isSeparator(self) source code
 
setStyleName(self, styleName) source code
 
getStyleName(self) source code
 
setDescription(self, description)
Sets the items's description.
source code
 
getDescription(self)
Gets the items's description.
source code
 
isCheckable(self)
Gets the checkable state of the item - whether the item has checked and unchecked states.
source code
 
setCheckable(self, checkable)
Sets the checkable state of the item.
source code
 
isChecked(self)
Gets the checked state of the item (checked or unchecked).
source code
 
setChecked(self, checked)
Sets the checked state of the item.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, caption, icon, command, menu)
(Constructor)

source code 

Constructs a new menu item that can optionally have an icon and a command associated with it. Icon and command can be null, but a caption must be given.

Parameters:
  • caption - The text associated with the command
  • command - The command to be fired
Raises:
  • ValueError
Overrides: object.__init__

hasChildren(self)

source code 

Checks if the item has children (if it is a sub-menu).

Returns:
True if this item has children

addSeparator(self)

source code 

Adds a separator to this menu. A separator is a way to visually group items in a menu, to make it easier for users to find what they are looking for in the menu.

Author: Jouni Koivuviita / Vaadin Ltd.

addItem(self, *args)

source code 

Add a new item inside this item, thus creating a sub-menu. Icon and command can be null, but a caption must be given.

Parameters:
  • args - tuple of the form
    • (caption, command)
      1. the text for the menu item
      2. the command for the menu item
    • (caption, icon, command)
      1. the text for the menu item
      2. the icon for the menu item
      3. the command for the menu item
Raises:
  • ValueError - If the item is checkable and thus cannot have children.

addItemBefore(self, caption, icon, command, itemToAddBefore)

source code 

Add an item before some item. If the given item does not exist the item is added at the end of the menu. Icon and command can be null, but a caption must be given.

Parameters:
  • caption - the text for the menu item
  • icon - the icon for the menu item
  • command - the command for the menu item
  • itemToAddBefore - the item that will be after the new item
Raises:
  • ValueError - If the item is checkable and thus cannot have children.

getCommand(self)

source code 

For the associated command.

Returns:
The associated command, or null if there is none

getIcon(self)

source code 

Gets the objects icon.

Returns:
The icon of the item, null if the item doesn't have an icon

getParent(self)

source code 

For the containing item. This will return null if the item is in the top-level menu bar.

Returns:
The containing menu_bar.MenuItem , or null if there is none

getChildren(self)

source code 

This will return the children of this item or null if there are none.

Returns:
List of children items, or null if there are none

getText(self)

source code 

Gets the objects text

Returns:
The text

getSize(self)

source code 

Returns the number of children.

Returns:
The number of child items

getId(self)

source code 

Get the unique identifier for this item.

Returns:
The id of this item

setCommand(self, command)

source code 

Set the command for this item. Set null to remove.

Parameters:
  • command - The MenuCommand of this item

setIcon(self, icon)

source code 

Sets the icon. Set null to remove.

Parameters:
  • icon - The icon for this item

setText(self, text)

source code 

Set the text of this object.

Parameters:
  • text - Text for this object

removeChild(self, item)

source code 

Remove the first occurrence of the item.

Parameters:
  • item - The item to be removed

setParent(self, parent)

source code 

Set the parent of this item. This is called by the addItem method.

Parameters:
  • parent - The parent item

setDescription(self, description)

source code 

Sets the items's description. See getDescription for more information on what the description is. This method will trigger a RepaintRequestEvent.

Parameters:
  • description - the new description string for the component.

getDescription(self)

source code 

Gets the items's description. The description can be used to briefly describe the state of the item to the user. The description string may contain certain XML tags:

<table border=1> <tr> <td width=120><b>Tag</b></td> <td width=120><b>Description</b></td> <td width=120><b>Example</b></td> </tr> <tr> <td>&lt;b></td> <td>bold</td> <td><b>bold text</b></td> </tr> <tr> <td>&lt;i></td> <td>italic</td> <td><i>italic text</i></td> </tr> <tr> <td>&lt;u></td> <td>underlined</td> <td><u>underlined text</u></td> </tr> <tr> <td>&lt;br></td> <td>linebreak</td> <td>N/A</td> </tr> <tr> <td>&lt;ul><br> &lt;li>item1<br> &lt;li>item1<br> &lt;/ul></td> <td>item list</td> <td> <ul> <li>item1 <li>item2 </ul> </td> </tr> </table>

These tags may be nested.

Returns:
item's description string

isCheckable(self)

source code 

Gets the checkable state of the item - whether the item has checked and unchecked states. If an item is checkable its checked state (as returned by isChecked) is indicated in the UI.

An item is not checkable by default.

Returns:
true if the item is checkable, false otherwise

setCheckable(self, checkable)

source code 

Sets the checkable state of the item. If an item is checkable its checked state (as returned by isChecked) is indicated in the UI.

An item is not checkable by default.

Items with sub items cannot be checkable.

Parameters:
  • checkable - true if the item should be checkable, false otherwise
Raises:
  • ValueError - If the item has children

isChecked(self)

source code 

Gets the checked state of the item (checked or unchecked). Only used if the item is checkable (as indicated by isCheckable). The checked state is indicated in the UI with the item, if the item is checkable.

An item is not checked by default.

The CSS style corresponding to the checked state is "-checked".

Returns:
true if the item is checked, false otherwise

setChecked(self, checked)

source code 

Sets the checked state of the item. Only used if the item is checkable (indicated by isCheckable). The checked state is indicated in the UI with the item, if the item is checkable.

An item is not checked by default.

The CSS style corresponding to the checked state is "-checked".

Returns:
true if the item is checked, false otherwise