mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Support OpenPype icon override in Maya Toolbox in Maya 2022+
- Also refactor import maya.cmds as `mc` to `cmds` to match with other code in the OpenPype code base
This commit is contained in:
parent
74cfde55ec
commit
d090655764
1 changed files with 34 additions and 23 deletions
|
|
@ -5,7 +5,7 @@ import logging
|
|||
|
||||
from functools import partial
|
||||
|
||||
import maya.cmds as mc
|
||||
import maya.cmds as cmds
|
||||
import maya.mel as mel
|
||||
|
||||
from avalon.maya import pipeline
|
||||
|
|
@ -31,9 +31,9 @@ def override_component_mask_commands():
|
|||
log.info("Installing override_component_mask_commands..")
|
||||
|
||||
# Get all object mask buttons
|
||||
buttons = mc.formLayout("objectMaskIcons",
|
||||
query=True,
|
||||
childArray=True)
|
||||
buttons = cmds.formLayout("objectMaskIcons",
|
||||
query=True,
|
||||
childArray=True)
|
||||
# Skip the triangle list item
|
||||
buttons = [btn for btn in buttons if btn != "objPickMenuLayout"]
|
||||
|
||||
|
|
@ -44,14 +44,14 @@ def override_component_mask_commands():
|
|||
# toggle the others based on whether any of the buttons
|
||||
# was remaining active after the toggle, if not then
|
||||
# enable all
|
||||
if mc.getModifiers() == 4: # = CTRL
|
||||
if cmds.getModifiers() == 4: # = CTRL
|
||||
state = True
|
||||
active = [mc.iconTextCheckBox(btn, query=True, value=True) for btn
|
||||
in buttons]
|
||||
active = [cmds.iconTextCheckBox(btn, query=True, value=True)
|
||||
for btn in buttons]
|
||||
if any(active):
|
||||
mc.selectType(allObjects=False)
|
||||
cmds.selectType(allObjects=False)
|
||||
else:
|
||||
mc.selectType(allObjects=True)
|
||||
cmds.selectType(allObjects=True)
|
||||
|
||||
# Replace #1 with the current button state
|
||||
cmd = raw_command.replace(" #1", " {}".format(int(state)))
|
||||
|
|
@ -64,13 +64,13 @@ def override_component_mask_commands():
|
|||
# try to implement the fix. (This also allows us to
|
||||
# "uninstall" the behavior later)
|
||||
if btn not in COMPONENT_MASK_ORIGINAL:
|
||||
original = mc.iconTextCheckBox(btn, query=True, cc=True)
|
||||
original = cmds.iconTextCheckBox(btn, query=True, cc=True)
|
||||
COMPONENT_MASK_ORIGINAL[btn] = original
|
||||
|
||||
# Assign the special callback
|
||||
original = COMPONENT_MASK_ORIGINAL[btn]
|
||||
new_fn = partial(on_changed_callback, original)
|
||||
mc.iconTextCheckBox(btn, edit=True, cc=new_fn)
|
||||
cmds.iconTextCheckBox(btn, edit=True, cc=new_fn)
|
||||
|
||||
|
||||
def override_toolbox_ui():
|
||||
|
|
@ -78,18 +78,29 @@ def override_toolbox_ui():
|
|||
icons = resources.get_resource("icons")
|
||||
|
||||
# Ensure the maya web icon on toolbox exists
|
||||
web_button = "ToolBox|MainToolboxLayout|mayaWebButton"
|
||||
if not mc.iconTextButton(web_button, query=True, exists=True):
|
||||
maya_version = int(cmds.about(version=True))
|
||||
if maya_version >= 2022:
|
||||
# Maya 2022+ has an updated toolbox with a different web
|
||||
# button name and type
|
||||
web_button = "ToolBox|MainToolboxLayout|mayaHomeToolboxButton"
|
||||
button_fn = cmds.iconTextStaticLabel
|
||||
else:
|
||||
web_button = "ToolBox|MainToolboxLayout|mayaWebButton"
|
||||
button_fn = cmds.iconTextButton
|
||||
|
||||
if not button_fn(web_button, query=True, exists=True):
|
||||
# Button does not exist
|
||||
log.warning("Can't find Maya Home/Web button to override toolbox ui..")
|
||||
return
|
||||
|
||||
mc.iconTextButton(web_button, edit=True, visible=False)
|
||||
button_fn(web_button, edit=True, visible=False)
|
||||
|
||||
# real = 32, but 36 with padding - according to toolbox mel script
|
||||
icon_size = 36
|
||||
parent = web_button.rsplit("|", 1)[0]
|
||||
|
||||
# Ensure the parent is a formLayout
|
||||
if not mc.objectTypeUI(parent) == "formLayout":
|
||||
if not cmds.objectTypeUI(parent) == "formLayout":
|
||||
return
|
||||
|
||||
# Create our controls
|
||||
|
|
@ -106,7 +117,7 @@ def override_toolbox_ui():
|
|||
|
||||
if look_assigner is not None:
|
||||
controls.append(
|
||||
mc.iconTextButton(
|
||||
cmds.iconTextButton(
|
||||
"pype_toolbox_lookmanager",
|
||||
annotation="Look Manager",
|
||||
label="Look Manager",
|
||||
|
|
@ -120,7 +131,7 @@ def override_toolbox_ui():
|
|||
)
|
||||
|
||||
controls.append(
|
||||
mc.iconTextButton(
|
||||
cmds.iconTextButton(
|
||||
"pype_toolbox_workfiles",
|
||||
annotation="Work Files",
|
||||
label="Work Files",
|
||||
|
|
@ -136,7 +147,7 @@ def override_toolbox_ui():
|
|||
)
|
||||
|
||||
controls.append(
|
||||
mc.iconTextButton(
|
||||
cmds.iconTextButton(
|
||||
"pype_toolbox_loader",
|
||||
annotation="Loader",
|
||||
label="Loader",
|
||||
|
|
@ -152,7 +163,7 @@ def override_toolbox_ui():
|
|||
)
|
||||
|
||||
controls.append(
|
||||
mc.iconTextButton(
|
||||
cmds.iconTextButton(
|
||||
"pype_toolbox_manager",
|
||||
annotation="Inventory",
|
||||
label="Inventory",
|
||||
|
|
@ -173,7 +184,7 @@ def override_toolbox_ui():
|
|||
for i, control in enumerate(controls):
|
||||
previous = controls[i - 1] if i > 0 else web_button
|
||||
|
||||
mc.formLayout(parent, edit=True,
|
||||
attachControl=[control, "bottom", 0, previous],
|
||||
attachForm=([control, "left", 1],
|
||||
[control, "right", 1]))
|
||||
cmds.formLayout(parent, edit=True,
|
||||
attachControl=[control, "bottom", 0, previous],
|
||||
attachForm=([control, "left", 1],
|
||||
[control, "right", 1]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue