Skip to content

Commit

Permalink
Added dynamic Popup menu to shelf, to easily switch between Hotkey Se…
Browse files Browse the repository at this point in the history
…ts. Issue #15.
  • Loading branch information
david-cattermole committed Oct 26, 2019
1 parent 790f8dc commit 401018d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
19 changes: 19 additions & 0 deletions config/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@
"import mmSolver.tools.deformmarker.tool as deformMkr;",
"deformMkr.remove_layer_override();"
]
},
"hotkey_switcher": {
"name": "Hotkey",
"tooltip": "Switch Hotkey Sets.",
"command": [
"pass"
]
},
"hotkey_switcher_popup": {
"popup": true,
"popup_post_command": [
"import mmSolver.tools.hotkeyswitcher.tool as tool;",
"tool.create_menu('{menu}');"
],
"popup_button": ["left", "right"]
},
"dummy": {
"name": "Dummy",
"tooltip": "A Dummy function to do nothing, used as a placeholder."
}
}
}
3 changes: 2 additions & 1 deletion config/shelf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"general_tools/gen_tools_popup/unparent_to_world",
"general_tools/gen_tools_popup/---Controllers",
"general_tools/gen_tools_popup/create_controller",
"general_tools/gen_tools_popup/remove_controller"
"general_tools/gen_tools_popup/remove_controller",
"hotkey_switcher/hotkey_switcher_popup/dummy"
],
"functions": {
"solver_popup": {
Expand Down
1 change: 1 addition & 0 deletions python/mmSolver/tools/mmshelf/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
TOOLTIP_KEY = 'tooltip'
DIVIDER_KEY = 'divider'
POPUP_KEY = 'popup'
POPUP_POST_CMD_KEY = 'popup_post_command'
POPUP_BUTTON_KEY = 'popup_button'
CMD_LANG_KEY = 'command_lang'
CMD_KEY = 'command'
Expand Down
4 changes: 4 additions & 0 deletions python/mmSolver/tools/mmshelf/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def create_item(parents, func_def, is_first_item, is_last_item):
elif popup:
key_suffix = const.KEY_SUFFIX_MENU
popupBtn = lookup_value(func_def, const.POPUP_BUTTON_KEY, key_suffix)
popupPostCmd = lookup_value(func_def, const.POPUP_POST_CMD_KEY, key_suffix)
if isinstance(popupPostCmd, (list, tuple)):
popupPostCmd = str(os.linesep).join(popupPostCmd)

# Create list of popup buttons, for each button-click used
# to open them.
Expand All @@ -289,6 +292,7 @@ def create_item(parents, func_def, is_first_item, is_last_item):
for index in popupBtnIndexList:
item = menu_utils.create_popup_menu(
parent=parent,
postCmd=popupPostCmd,
button=index
)
items.append(item)
Expand Down
14 changes: 13 additions & 1 deletion python/mmSolver/ui/menuutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def create_menu_item(parent=None,

if isinstance(name, basestring):
label = str(name)
if isinstance(tooltip, basestring):
annotation = str(tooltip)

item = None
if divider is not True and subMenu is not True:
Expand Down Expand Up @@ -144,13 +146,18 @@ def create_menu_item(parent=None,


def create_popup_menu(parent=None,
postCmd=None,
button=None):
"""
Create a Pop-Up menu (for a shelf button).
:param parent: What should this control be placed under?
:type parent: str
:param postCmd: Command to be run before the popup menu is shown.
Replaces '{menu}' with the full menu name.
:type postCmd: None or str
:param button: Which mouse button should active this pop-up menu?
1=left, 2=middle, 3=right mouse button.
:type button: int
Expand All @@ -160,11 +167,16 @@ def create_popup_menu(parent=None,
"""
assert parent is not None
assert isinstance(parent, basestring)
assert postCmd is None or isinstance(postCmd, basestring)
if button is None:
button = 3
assert isinstance(button, int)
menu = maya.cmds.popupMenu(
parent=parent,
button=button)
if postCmd is not None:
cmd = str(postCmd).format(menu=menu)
maya.cmds.popupMenu(
menu, edit=True,
postMenuCommand=cmd)
return menu

0 comments on commit 401018d

Please sign in to comment.