pycocoa.menus.Menu

Package pycocoa :: Module menus :: Class Menu |
[frames] | no frames]

# Class Menu

      object --+
               |
    bases._Type0 --+
                   |
        bases._Type1 --+
                       |
            bases._Type2 --+
                           |
                 _Menu_Type2 --+
                               |
                              Menu

Python Menu Type, wrapping ObjC `NSMenu`.

Instance Methods
__init__(self, title) New Menu. |
append(self, *items) Add one or more items or separators to this menu. |
click(self, item, highlight=False) Mimick clicking a menu item. |
clickKey(self, key, highlight=False, **modifiers) Mimick clicking a menu item by the shortcut key, see `Item.__init__`. |
find(self, item) Return the index of a menu item in this menu. |
__getitem__(self, index) Return the item at index or with title or several by slice. |
highlight(self, item) Highlight a menu item. |
index(self, item) Return the index of an item in this menu. |
insert(self, index, *items) Insert one or more items or separators into this menu. |
item(self, title='', action=None, tag=None, dflt=missing, key='', **modifiers) Find an item by title, by action, by tag or by key. |
items(self, separators=False) Yield the items in this menu. |
pop(self, index=-1) Remove an item by index. |
popUp(self, fraction=0.1) Show this menu on the screen. |
remove(self, *items) Remove one or more items from this menu. |
separator(self, index=missing) Add or insert an item separator. |
Inherited from `_Menu_Type2`: `__contains__`, `__len__`, `removeAll` Inherited from `bases._Type2`: `__str__` Inherited from `bases._Type0`: `__repr__`, `type2strepr` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Properties
| highlightedItem Get the menu's `highlightedItem` property (`Item` or `None`).
| isVisible Get the menu's `isVisible` property (`bool`) or `None`.
| isEnabled Get the menu's `Enabled` property (`bool`).
| isHidden Get the menu's `Hidden` property (`bool`).
| isHighlighted Get the menu's `isHighlighted` property (`bool`).
| nsMenuItem Get the menu's intermediate (`NSMenuItem`) or `None` if the menu hasn't been added or inserted into a MenuBar.
| tag Get the Menu tag (`int`).
Inherited from `_Menu_Type2`: `action`, `autoEnables`, `isAttached`, `isTornOff`, `minWidth`, `parent`, `showsState`, `size`, `tags` Inherited from `bases._Type2`: `title` Inherited from `bases._Type1`: `NSdelegate`, `app` Inherited from `bases._Type0`: `NS`, `NSDelegate` Inherited from `object`: `__class__`

Method Details

### __init__(self, title) (Constructor) |
New Menu. Parameters: `title` - The menu title (`str`). Overrides: object.__init__

### append(self, *items) |
Add one or more items or separators to this menu. Parameters: `items` - The items (Item or ItemSeparator) to add. Raises: `TypeError` - An item is not Item nor ItemSeparator.

### click(self, item, highlight=False) |
Mimick clicking a menu item. Parameters: `item` - The item to click (Item). `highlight` - Highlight the clicked item (`bool`). Raises: `ValueError` - No item in this menu.

### clickKey(self, key, highlight=False, **modifiers) |
Mimick clicking a menu item by the shortcut key, see `Item.__init__`. Parameters: `key` - The shortcut key (`str`). `modifiers` - Optional, key modifier=`bool` pairs. `highlight` - Highlight the clicked item (`bool`). Raises: `KeyError` - If key with modifiers is not a shortcut of this menu.

### find(self, item) |
Return the index of a menu item in this menu. Parameters: `item` - The item to locate (Item). Returns: The index (`int`) or `-1` if not found.

### __getitem__(self, index) (Indexing operator) |
Return the item at index or with title or several by slice. Parameters: `index` - The index (`int`, `str` or `slice`). Returns: The item (Item or ItemSeparator) or items. Raises: `IndexError` - If index out of range or if no item titled index exists.

### highlight(self, item) |
Highlight a menu item. Parameters: `item` - The item to hightlight (Item). Raises: `ValueError` - No item in this menu.

### index(self, item) |
Return the index of an item in this menu. Parameters: `item` - The item to locate (Item or ItemSeparator). Returns: Index (`int`). Raises: `ValueError` - If item not found.

### insert(self, index, *items) |
Insert one or more items or separators into this menu. Parameters: `index` - Insert items before this index (`int`). `items` - The items (Item or ItemSeparator) to insert. Raises: `IndexError` - If index out of range. `TypeError` - If index not `int` or an item not Item nor ItemSeparator.

### item(self, title='', action=None, tag=None, dflt=missing, key='', **modifiers) |
Find an item by title, by action, by tag or by key. Parameters: `title` - The item title to match (`str`). `action` - The item action to match (`str` or `callable`). `tag` - The item tag to match (`unsigned int`). `dflt` - Optional, default return value. `key` - The item shortcut key to match (`str`). `modifiers` - Optional, key modifier=`bool` pairs, see `Item.__init__`. Returns: The first matching item (Item) or dflt if no title, action, key or tag match found. Raises: `ValueError` - No dflt provided and no title, action nor tag match.

### items(self, separators=False) |
Yield the items in this menu. Parameters: `separators` - Yield ItemSeparators (`bool`), skip otherwise. Returns: Each Item or ItemSeparator.

### pop(self, index=-1) |
Remove an item by index. Parameters: `index` - The item's index (`int`) or default, the last item. Returns: The removed item (Item). Raises: `IndexError` - Invalid index. `TypeError` - Invalid index.

### popUp(self, fraction=0.1) |
Show this menu on the screen. Parameters: `fraction` - Cascade off the upper left corner (`float`). Returns: `True` if an item was selected, `False` otherwise.

### remove(self, *items) |
Remove one or more items from this menu. Parameters: `items` - The items to remove (`Item`). Raises: `TypeError` - Invalid item. `ValueError` - If item not present.

### separator(self, index=missing) |
Add or insert an item separator. Parameters: `index` - Insert separator before this index (`int`) or default, append separator.

Property Details

### highlightedItem Get the menu's `highlightedItem` property (`Item` or `None`). Get Method: highlightedItem(self) - Get the menu's `highlightedItem` property (`Item` or `None`). Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.

### isVisible Get the menu's `isVisible` property (`bool`) or `None`. Get Method: isVisible(self) - Get the menu's `isVisible` property (`bool`) or `None`. Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.

### isEnabled Get the menu's `Enabled` property (`bool`). Get Method: isEnabled(self) - Get the menu's `Enabled` property (`bool`). Set Method: isEnabled(self, enable) - Set the menu's `Enabled` property (`bool`).

### isHidden Get the menu's `Hidden` property (`bool`). Get Method: isHidden(self) - Get the menu's `Hidden` property (`bool`). Set Method: isHidden(self, hidden) - Set the menu's `Hidden` property (`bool`).

### isHighlighted Get the menu's `isHighlighted` property (`bool`). Get Method: isHighlighted(self) - Get the menu's `isHighlighted` property (`bool`). Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.

### nsMenuItem Get the menu's intermediate (`NSMenuItem`) or `None` if the menu hasn't been added or inserted into a MenuBar. Get Method: nsMenuItem(self) - Get the menu's intermediate (`NSMenuItem`) or `None` if the menu hasn't been added or inserted into a MenuBar. Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.

### tag Get the Menu tag (`int`). Get Method: tag(self) - Get the Menu tag (`int`). Set Method: tag(self, tag) - Set the Menu tag (`int`).