menu¶
Here are functions and classes for tasks related to menu creation in maya
- class jukeboxmaya.menu.Menu(name, parent=None, nolabel=False, **kwargs)[source]¶
Bases: weakref.WeakValueDictionary
This represents a maya menu or menuitem that was created with cmds.menu/cmds.menuitem
Important
Note that you should use the MenuManager for Menu creation! For creation, it is better to use jukebox.menu.MenuManager.create_menu().
Menu features several attributes that can be accesed via getters:
menustring: The string that is used in maya to identify the menu parent: A reference to the parent Menu if the menuitem has one. A menu does not have a parent. name: The name of the Menu. The name is used to identify the Menu. The children of one parent should have unique names. kwargs: a dict with arguments used during creation. Menu is a subclass of WeakValueDictionary. Its values are the children menuitems. The keys are the name attributes of the Menu instance. If you set the parent of a child to None, it will also be deleted from Menu if there are no further references. We have to do this, to prevent circular references.
Example:
topm = Menu('topm', label='topm') sub1 = Menu('submenu1', parent=topm, label='submenu1', subMenu=True) sub2 = Menu('Divider', parent=sub1, divider=1, nolabel=1) # Divider should not have a label # evaluates to True sub2 is sub1['Divider'] sub2.kwargs()['divider'] == 1 # delete a submenu sub2._delete() sub2 = None # delete reference to sub2 sub1.has_key('Divider') == False # sub2 is garbage collected and not part of sub1 anymore
Creates a maya menu or menu item
Parameters: - name (str) – Used to access a menu via its parent. Unless the nolabel flag is set to True, the name will also become the label of the menu.
- parent (Menu|None) – Optional - The parent menu. If None, this will create a toplevel menu. If parent menu is a Menu instance, this will create a menu item. Default is None.
- nolabel (bool) – Optional - If nolabel=True, the label flag for the maya command will not be overwritten by name
- kwargs (named arguments) – all keyword arguments used for the cmds.menu/cmds.menuitem command
Returns: None
Return type: None
Raises: errors.MenuExistsError
- menustring()[source]¶
Return the string that is used by maya to identify the ui
Returns: the string that is used by maya to identify the ui Return type: st Raises: None
- parent()[source]¶
Return the parent of the menu or None if this is a toplevel menu
Returns: the parent menu or None Return type: Menu|None Raises: None
- class jukeboxmaya.menu.MenuManager[source]¶
Bases: object
A Manager for menus in maya.
The toplevel menus are stored inside self.menus. All child menus are stored in those.
Important
Use MenuManager.get() to obtain the menumanager!
Constructs a Menu Manager
Returns: None Return type: None Raises: None - menumanager = None¶
MenuManger instance when using MenuManager.get()
- classmethod get()[source]¶
Return a MenuManager Instance.
This will always return the same instance. If the instance is not available it will be created and returned.
Returns: always the same MenuManager Return type: MenuManager Raises: None
- create_menu(name, parent=None, **kwargs)[source]¶
Creates a maya menu or menu item
Parameters: - name (str) – Used to access a menu via its parent. Unless the nolabel flag is set to True, the name will also become the label of the menu.
- parent (Menu|None) – Optional - The parent menu. If None, this will create a toplevel menu. If parent menu is a Menu instance, this will create a menu item. Default is None.
- nolabel (bool) – Optional - If nolabel=True, the label flag for the maya command will not be overwritten by name
- kwargs (named arguments) – all keyword arguments used for the cmds.menu/cmds.menuitem command
Returns: None
Return type: None
Raises: errors.MenuExistsError