Markingmenu Extension

See Marking Creation for usages.

Markingmenuoverride

reset()
setup()

Installs modifications to the dagProcMenu script for the current session

Menu

Usage:

First define to location of your commands and marking menu classes. 
Next define the location of your layout files
Now apply these locations to the MM environment variables, ZOO_MM_COMMAND_PATH, 
    ZOO_MM_MENU_PATH, ZOO_MM_LAYOUT_PATH, before zootools starts up.
exception InvalidJsonFileFormat

Bases: Exception

Raised in case of invalid formatted json file(.mmlayout)

exception MissingMarkingMenu

Bases: Exception

findLayout(layoutId)

Finds the layout by Id(str) from the layout registry

Parameters:

layoutId (str) – the layout str id, “some.layout.id”

Returns:

If the registry has the id then a Layout object will be returned

Return type:

Layout or None

class Registry(*args, **kwargs)

Bases: object

This holds all currently available layout classes discovered in the environment use findLayout() to get the layout from this registry.

To setup the environment you need to set the environment variable :env:’ZOO_MM_LAYOUT_PATH’ to the directories of the layout, each path should be separated using os.pathsep

LAYOUT_ENV = 'ZOO_MM_LAYOUT_PATH'
MENU_ENV = 'ZOO_MM_MENU_PATH'
COMMAND_ENV = 'ZOO_MM_COMMAND_PATH'
STATIC_LAYOUT_TYPE = 0
DYNAMIC_TYPE = 1
hasMenu(menuId)
menuType(menuId)
env()
registerLayoutByEnv(env)

Recursively Registers all layout files with the extension .mmlayout and loads the json data with a layout instance then adds to the layouts cache

Parameters:

env (str) – the environment variable pointing to the parent directory

loadMMLayoutFile(path)
registerLayoutData(data)

Adds the layout data structure as a Layout using the data[“id”] as the key.

Parameters:

data (dict) – see :class`Layout`

class Layout(**kwargs)

Bases: dict

layoutData={"items":{"N": {},
                      "NW": {},
                      "W": {},
                      "SW": {},
                      "S": {},
                      "SE": {},
                      "E": {},
                      "NE": {},
                      "generic": [{"type": "menu",
                                  "name": "Testmenu",
                                  "children": [{"type": "command",
                                                "id": ""}
                                                ]
                                  ]

                      },
            "id": "some.layout.id"}
layoutObj = Layout(**layoutData)
items()

Returns the item dict for this layout in the form of

{"N": {},
"NW": {},
"W": {},
"SW": {},
"S": {},
"SE": {},
"E": {},
"NE": {},
"generic": [{"type": "menu",
            "name": "Testmenu",
            "children": [{"type": "command",
                          "id": ""}
                          ]]
}
Returns:

The layout items dict.

Return type:

dict

merge(layout)

Merges the layout items into this instance, only differences will be merged.

Parameters:

layout (Layout) – the layout to merge into the this class

validate(layout=None)

Recursively validates the layout, returning all failed items, if an item references another layout that layout will used be validated.

Parameters:

layout (Layout) – The layout instance to solve

Returns:

the failed items

Return type:

list

solve()

Recursively solves the layout by expanding any @layout.id references which will compose a single dict ready for use.

A layout can contain deeply nested layouts which is referenced by the syntax @layout.id, in the case where there is a reference then that layout will be solved first.

Returns:

Whether or not the layout was solved

Return type:

bool

class MarkingMenu(layout, name, parent, registry)

Bases: object

Maya MarkingMenu wrapper object to support zoocommands and python executable code. MM layouts are defined by the Layout instance class

static removeExistingMenu(menuName)

Removes the menuName from the registry and deletes the menu from maya

Parameters:

menuName (str) – The menu name to remove.

static removeAllActiveMenus()

Removes all current active zoo marking menus from the registry and deletes the Maya UI MM

classmethod buildFromLayout(layoutId, menuName, parent, options, globalArguments=None)

Build a menu directly from the menu registry based off of the layout Id.

Parameters:
  • layoutId (str) – The layout id defined in the registry

  • menuName (str) – The unique name for the menu

  • parent (str) – The maya widget path for the menu parent i.e viewPanes

  • options (dict) – The marking menu options, see MarkingMenu.__init__ for more details

  • globalArguments (dict) – The global Arguments to pass to all menu action commands.

Returns:

The new markingMenu instance

Return type:

MarkingMenu

Raise:

ValueError, in the case the layout can’t be found or already active.

classmethod buildFromLayoutData(layoutData, menuName, parent, options, arguments=None)

Create a new MarkingMenu instance from the layoutData, menuName, and options provided.

If the menu already exists and is active, raise a ValueError. If the parent menu exists, attach the new menu to it. Otherwise, create the new menu.

Parameters:
  • layoutData (Layout) – the data that defines the layout of the menu.

  • menuName (str) – the name of the menu.

  • parent (str) – the parent menu, if any.

  • options (dict) – additional options to be passed to the menu.

  • arguments (dict) – additional arguments to be passed to the attach() or create() method.

Returns:

the new menu instance.

Return type:

MarkingMenu

static buildDynamicMenu(clsId, menuName, parent, arguments, options=None, layout=None)

Builds a marking menu from the clsId which should exist with our marking menu registry.

Parameters:
  • clsId (str) – the classId string

  • parent (str) – The parent menu or widget fullPath ie. viewPanes for mayas viewport.

  • arguments (dict) – The arguments to pass to the custom menu class

  • options (dict) – additional options to be passed to the menu.

  • layout (Layout or None) – the base Layout data that defines the layout this will be modified by the dynamic class.

Returns:

If the classid exists then the newly created marking menu class will be returned

Return type:

MarkingMenu or None

asQObject()

Returns this markingMenu as a PYQT object

Returns:

Return this MarkingMenu as a qt.QMenu instance

Return type:

QMenu

attach(**arguments)

Generates the marking menu using the parent marking menu.

The arguments passed will be passed to ech and every menuItem command, for example if the menu item command is a zoocommand then the zoocommand will have the arguments passed to it.

Parameters:

arguments (dict) – A Dict of arguments to pass to each menuItem command.

Returns:

if the parent menu doesn’t exist then False will be returned, True if successfully attached

Return type:

bool

create(**arguments)

Creates a new popup markingMenu parented to self.parent instance, use :func: MarkingMenu:attach if you need to add to existing markingmenu.

Returns:

current instance

Return type:

MarkingMenu

kill()

Destroys the pop menu from maya.

addCommand(item, parent, radialPosition=None)

Adds the specified command item to the parent menu.

Parameters:
  • item (dict) – {“type”: “command”, “id”: “myCustomCommand”}

  • parent (str) – The parent menu string

  • radialPosition (str or None) – The radial position i.e “N”

addSeparator(menu, item=None)

Adds separator to menu

Parameters:

menu

show(layout, menu, parent)

Main Method that converts the layout to a maya marking menu.

If implementing a subclass then super must be called.

Parameters:
  • layout (Layout) – The layout class to convert

  • menu (str) – The menu fullPath which commands will be attached too.

  • parent (str) – The Parent full Path name.

allowOptionBoxes()

Returns a boolean indicating if option boxes are enabled on the popupMenu.

Return type:

bool

altModifier()

Returns a boolean indicating if the alt modifier is enabled on the popupMenu.

Return type:

bool

button()

Returns the button number that is associated with the popupMenu.

Return type:

int

ctrlModifier()

returns a boolean indicating if the ctrl modifier is enabled on the popupMenu.

Return type:

bool

deleteAllItems()

deletes all items in the popupMenu and returns True if successful.

Return type:

bool

exists()

returns a boolean indicating if the popupMenu exists in the Maya UI.

Return type:

bool

itemArray()

Return string array of the menu item names.

Return type:

list[str]

markingMenu()

Returns a boolean indicating if the popupMenu is a marking menu.

Return type:

bool

numberOfItems()

Returns the number of items in the popupMenu.

Return type:

int

postMenuCommand(command)

Posts the given command to be executed after the popupMenu is created.

postMenuCommandOnce(state)

Sets the state of postMenuCommandOnce on the popupMenu.

shiftModifier()

Returns a boolean indicating if the shift modifier is enabled on the popupMenu.

setShiftModifier(value)

Sets the state of the shift modifier on the popupMenu.

setParent(parent)

Sets the parent of the popupMenu to the given parent.

setCtrlModifier(value)

Sets the state of the ctrl modifier on the popupMenu.

setAltModifier(state)

Sets the state of the alt modifier on the popupMenu.

setUseLeftMouseButton()

Sets the popupMenu to use the left mouse button.

setUseRightMouseButton()

Sets the popupMenu to use the right mouse button.

setUseMiddleMouseButton()

Sets the popupMenu to use the middle mouse button.

class MarkingMenuDynamic(manager=None)

Bases: Plugin

Marking Menu Dynamic allows for subclasses to dynamic generate the marking menu layout.

documentation = 'Marking Menu Dynamic allows for subclasses to dynamic generate the marking menu layout.'
id = ''
execute(layout, arguments)
class MarkingMenuCommand(manager=None)

Bases: Plugin

Marking menu plugin which is used to define a single Marking menu action.

Client code should subclass from this command class.

Override the MarkingMenuCommand.execute() method to customize standard left click execution.

Override the MarkingMenuCommand.executeUI() method to customize the option box on the action if the uiData[“optionBox”] is True

documentation = 'Marking menu plugin which is used to define a single Marking menu action.\n\n    Client code should subclass from this command class.\n\n    Override the :meth:`MarkingMenuCommand.execute` method to customize standard\n    left click execution.\n\n    Override the :meth:`MarkingMenuCommand.executeUI` method to customize the option\n    box on the action if the uiData["optionBox"] is True\n\n    '
id = ''
creator = 'Zootools'
static uiData(arguments)

UiData defines the visuals of the command action.

Parameters:

arguments (dict) – The global arguments passed to the command from the parent menu.

Returns:

Return type:

dict

execute(arguments)

The execute method is called when triggering the action item. use executeUI() for a optionBox.

executeUI(arguments)

The executeUI method is called when the user triggering the box icon on the right handle side of the action item.

For this method to be called you must specify in the UIData method “optionBox”: True.