nuke.Menu

class nuke.Menu

Bases: MenuItem

Methods

action

Get the action associated with this menu item.

addAction

Adds the QAction to the menu.

addCommand

Add a new command to this menu/toolbar.

addMenu

Add a new submenu. :param **kwargs The following keyword arguments are accepted: name The name for the menu/toolbar item icon An icon for the menu. Loaded from the nuke search path. tooltip The tooltip text. index The position to insert the menu in. Use -1 to add to the end of the menu. tag Optional. Sets the tag icon that is displayed on the menu/toolbar item (0==None, 1=Beta, 2=Classic). :return: The submenu that was added.

addSeparator

Add a separator to this menu/toolbar. :param **kwargs The following keyword arguments are accepted: index The position to insert the new separator in, in the menu/toolbar. :return: The separator that was created.

clearMenu

self.clearMenu() Clears a menu. :param **kwargs The following keyword arguments are accepted: name The name for the menu/toolbar item :return: true if cleared, false if menu not found .

findItem

Finds a submenu or command with a particular name.

icon

Returns the name of the icon on this menu item as path of the icon.

invoke

Perform the action associated with this menu item.

items

Returns a list of sub menu items.

menu

Finds a submenu or command with a particular name.

name

Returns the name of the menu item.

removeItem

Removes a submenu or command with a particular name.

script

Returns the script that gets executed for this menu item.

setEnabled

Enable or disable the item.

setIcon

Set the icon on this menu item.

setScript

Set the script to be executed for this menu item.

setShortcut

Set the keyboard shortcut on this menu item.

setVisible

Show or hide the item.

shortcut

Returns the keyboard shortcut on this menu item.

updateMenuItems

Updates menu items' states.

action() None

Get the action associated with this menu item.

addAction(action) bool

Adds the QAction to the menu.

addCommand(name, command, shortcut, icon, tooltip, index, readonly, shortcutContext, tag, tagTarget, node) The menu/toolbar item that was added to hold the command.

Add a new command to this menu/toolbar. Note that when invoked, the command is automatically enclosed in an undo group, so that undo/redo functionality works. Optional arguments can be specified by name. Note that if the command argument is not specified, then the command will be auto-created as a “nuke.createNode()” using the name argument as the node to create. Note: During startup this command can cause slowdown when using the custom toolset menu. To speedup the process include “icon=’/’” as an argument, however, it’ll show an empty spot next to each menu where icons are shown.

Example: menubar = nuke.menu(‘Nuke’) fileMenu = menubar.findItem(‘File’) fileMenu.addCommand(‘NewCommand’, ‘print 10’, shortcut=’t’)

Parameters
  • name – The name for the menu/toolbar item. The name may contain submenu names delimited by ‘/’ or ‘’, and submenus are created as needed.

  • command – Optional. The command to add to the menu/toolbar. This can be a string to evaluate or a Python Callable (function, method, etc) to run.

  • shortcut – Optional. The keyboard shortcut for the command, such as ‘R’, ‘F5’ or ‘Ctrl-H’. Note that this overrides pre-existing other uses for the shortcut.

  • icon – Optional. An icon for the command. This should be a path to an icon in the nuke.pluginPath() directory. If the icon is not specified, Nuke will automatically try to find an icon with the name argument and .png appended to it.

  • tooltip – Optional. The tooltip text, displayed on mouseover for toolbar buttons.

  • index – Optional. The position to insert the new item in, in the menu/toolbar. This defaults to last in the menu/toolbar.

  • readonly – Optional. True/False for whether the item should be available when the menu is invoked in a read-only context.

  • shortcutContext – Optional. Sets the shortcut context (0==Window, 1=Application, 2=DAG).

  • tag – Optional. Sets the tag icon that is displayed on the menu/toolbar item (0==None, 1=Beta, 2=Classic).

  • tagTarget – Optional. Determines which type of the menu/toolbar should display the specified tag (0==Unknown, 1=Beta, 2=TabMenu, 3=ContextMenu, 7=All).

  • nodeClass – The NodeClass the tag should apply to.:return: The menu/toolbar item that was added to hold the command.

addMenu(**kwargs) The submenu that was added.

Add a new submenu. :param **kwargs The following keyword arguments are accepted:

name The name for the menu/toolbar item icon An icon for the menu. Loaded from the nuke search path. tooltip The tooltip text. index The position to insert the menu in. Use -1 to add to the end of the menu. tag Optional. Sets the tag icon that is displayed on the menu/toolbar item (0==None, 1=Beta, 2=Classic).

Returns

The submenu that was added.

addSeparator(**kwargs) The separator that was created.

Add a separator to this menu/toolbar. :param **kwargs The following keyword arguments are accepted: index The position to insert the new separator in, in the menu/toolbar. :return: The separator that was created.

clearMenu()

self.clearMenu() Clears a menu. :param **kwargs The following keyword arguments are accepted:

name The name for the menu/toolbar item

Returns

true if cleared, false if menu not found

findItem(name) Menu or None

Finds a submenu or command with a particular name. :param name: The name to search for. :return: The submenu or command we found, or None if we could not find anything.

icon() String

Returns the name of the icon on this menu item as path of the icon.

invoke() None

Perform the action associated with this menu item.

items() None

Returns a list of sub menu items.

menu(name) Menu or None

Finds a submenu or command with a particular name. :param name: The name to search for. :return: The submenu or command we found, or None if we could not find anything.

name() String

Returns the name of the menu item.

removeItem(name) None

Removes a submenu or command with a particular name. If the containing menu becomes empty, it will be removed too. :param name: The name to remove for. :return: true if removed, false if menu not found

script() String

Returns the script that gets executed for this menu item.

setEnabled(enabled, recursive) None

Enable or disable the item. :param enabled: True to enable the object; False to disable it. :param recursive: True to also setEnabled on submenu actions.

setIcon(icon) None

Set the icon on this menu item. :param icon: the new icon as a path

setScript(script) None

Set the script to be executed for this menu item. Note: To call a python script file, you can use the execfile() function. i.e: menu.setScript(“execfile(‘script.py’)”)

setShortcut(keySequence) None

Set the keyboard shortcut on this menu item. :param keySequence: the new shortcut in PortableText format, e.g. “Ctrl+Shift+P”

setVisible(visible) None

Show or hide the item. :param visible: True to show the object; False to hide it.

shortcut() String

Returns the keyboard shortcut on this menu item. The format of this is the PortableText format. It will return a string such as “Ctrl+Shift+P”. Note that on Mac OS X the Command key is equivalent to Ctrl.

updateMenuItems() None

Updates menu items’ states. Call on about to show menu.