Layered Menus¶
The LayeredMenuAPI allows users to define and register custom
menus for the Node Graph tab that appear and behave in the same way as
the built-in node creation menu that is shown when pressing the Tab
key. These custom menus are named layered menus, as they appear in a menu
layer on top of the nodes that make up the node graph of a Katana project.
The entries that are shown for a layered menu can be customized with an arbitrary text and a color per entry. When entering text while a layered menu is shown, its entries are filtered based on the entered text, just like entries of the node creation menu are filtered when entering the name of a node type.
When an entry from a layered menu is chosen, custom Python code can be executed. One common use case for layered menus is the ability to create and configure nodes of certain types based on a pre-defined or dynamic list of menu entries for the user to choose from.
Layered menus can be registered from UIPlugins scripts using this API.
-
LayeredMenuAPI.GetLayeredMenu(layeredMenuID)¶ Return type: LayeredMenuorNoneParameters: layeredMenuID ( str) – The ID that uniquely identifies the layered menu to return.Returns: The layered menu with the given ID, or Noneif no layered menu with the given ID has been registered.
-
LayeredMenuAPI.GetLayeredMenuIDs()¶ Return type: listofstrReturns: A list of unique IDs of layered menus that have been registered using RegisterLayeredMenu.
-
class
LayeredMenuAPI.LayeredMenu(populateCallback, actionCallback, keyboardShortcut, alwaysPopulate=False, onlyMatchWordStart=True)¶ Class implementing a layered menu that contains layered menu entries.
-
addEntry(value, text=None, color=None, size=None)¶ Adds an entry to the menu to represent the given value, optionally with the given text, color, and size.
Parameters: - value (
object) – An arbitrary object that the added menu entry represents, which is passed to the callback that is called when the entry has been chosen by the user. - text (
strorNone) – The text to use for the entry in the menu, orNoneto use the given value converted usingstr(). - color (3-
tupleoffloatorNone) – The color to use for the entry in the menu, orNoneto use a default color for the entry. - size (2-
tupleoffloatorNone) – The width and height in pixels of the entry, orNoneto calculate the entry’s size automatically based on its text.
- value (
-
alwaysPopulate()¶ Return type: boolReturns: Trueif the populate callback is to be called every time before the menu is shown, orFalseif it is to be called only the first time.
-
clear()¶ Clears the cache of menu entries and resets the flag that indicates whether the menu has been populated (see
isPopulated.
-
getChosenValue()¶ Return type: objectorNoneReturns: The arbitrary object that the chosen menu entry represents, or Noneif no entry has been chosen yet.
-
getEntries()¶ Return type: listofLayeredMenuEntryReturns: The list of entries that make up this menu.
-
getKeyboardShortcut()¶ Return type: strReturns: The keyboard shortcut to use for showing the menu, for example "M"or"Alt+P".
-
isPopulated()¶ Return type: boolReturns: Trueif this menu has been populated with entries already, otherwiseFalse.Note: Calling clearresets the cache of menu entries and the flag that indicates whether the menu has been populated.
-
onEntryChosen(value)¶ Calls the action callback with the given value when the user has chosen an entry from the menu.
Return type: objectorNoneParameters: value ( object) – The arbitrary object of the menu entry that was chosen, which is passed as an argument to the action callback.Returns: The result of the action callback, or Noneif the action callback could not be called.
-
onlyMatchWordStart()¶ Return type: boolReturns: Trueif an entered word should be matched against the beginning of an entry’s text, orFalseif it should be matched against any part of an entry’s text.
-
-
class
LayeredMenuAPI.LayeredMenuEntry(value, text=None, color=None, size=None)¶ Class implementing an entry in a layered menu.
Stores the value, and optionally a text, color, and size for a menu entry.
-
getColor()¶ Return type: 3- tupleoffloatorNoneReturns: The color to be rendered for the menu entry.
-
getSize()¶ Return type: 2- tupleoffloatorNoneReturns: The width and height of the entry in pixels.
-
getText()¶ Return type: strReturns: The text to be rendered for the menu entry.
-
getValue()¶ Return type: objectReturns: An arbitrary object that the menu entry represents, which is passed to the callback that is called when this entry has been chosen by the user.
-
-
LayeredMenuAPI.RegisterLayeredMenu(layeredMenu, layeredMenuID)¶ Registers the given layered menu under the given ID.
Parameters: - layeredMenu (
LayeredMenu) – The layered menu to register. - layeredMenuID (
str) – The ID that uniquely identifies the layered menu.
- layeredMenu (