diff --git a/colorbleed/maya/__init__.py b/colorbleed/maya/__init__.py index 4e7bb677b4..6e6d0ca869 100644 --- a/colorbleed/maya/__init__.py +++ b/colorbleed/maya/__init__.py @@ -98,18 +98,24 @@ def on_init(_): utils.executeDeferred(_fn) except Exception as exc: print(exc) - + # Force load Alembic so referenced alembics # work correctly on scene open cmds.loadPlugin("AbcImport", quiet=True) cmds.loadPlugin("AbcExport", quiet=True) - + # Force load objExport plug-in (requested by artists) cmds.loadPlugin("objExport", quiet=True) - from .customize import override_component_mask_commands + from .customize import ( + override_component_mask_commands, + override_toolbox_ui + ) safe_deferred(override_component_mask_commands) + if not IS_HEADLESS: + safe_deferred(override_toolbox_ui) + def on_before_save(return_code, _): """Run validation for scene's FPS prior to saving""" diff --git a/colorbleed/maya/customize.py b/colorbleed/maya/customize.py index 64f33d5aae..4de78fba43 100644 --- a/colorbleed/maya/customize.py +++ b/colorbleed/maya/customize.py @@ -3,6 +3,7 @@ import maya.cmds as mc import maya.mel as mel from functools import partial +import os import logging @@ -17,7 +18,7 @@ def override_component_mask_commands(): This implements special behavior for Maya's component mask menu items where a ctrl+click will instantly make it an isolated behavior disabling all others. - + Tested in Maya 2016 and 2018 """ @@ -64,3 +65,76 @@ def override_component_mask_commands(): original = COMPONENT_MASK_ORIGINAL[btn] new_fn = partial(on_changed_callback, original) mc.iconTextCheckBox(btn, edit=True, cc=new_fn) + + +def override_toolbox_ui(): + """Add custom buttons in Toolbox as replacement for Maya web help icon.""" + + import colorbleed + res = os.path.join(os.path.dirname(os.path.dirname(colorbleed.__file__)), + "res") + icons = os.path.join(res, "icons") + + import avalon.tools.cbsceneinventory as inventory + import avalon.tools.cbloader as loader + + # Ensure the maya web icon on toolbox exists + web_button = "ToolBox|MainToolboxLayout|mayaWebButton" + if not mc.iconTextButton(web_button, query=True, exists=True): + return + + mc.iconTextButton(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": + return + + # Create our controls + controls = [] + + control = mc.iconTextButton( + "colorbleed_toolbox_loader", + annotation="Loader", + label="Loader", + image=os.path.join(icons, "loader.png"), + command=lambda: loader.show(use_context=True), + width=icon_size, + height=icon_size, + parent=parent) + controls.append(control) + + control = mc.iconTextButton( + "colorbleed_toolbox_manager", + annotation="Inventory", + label="Inventory", + image=os.path.join(icons, "inventory.png"), + command=lambda: inventory.show(), + width=icon_size, + height=icon_size, + parent=parent) + controls.append(control) + + control = mc.iconTextButton( + "colorbleed_toolbox", + annotation="Colorbleed", + label="Colorbleed", + image=os.path.join(icons, "colorbleed_logo_36x36.png"), + width=icon_size, + height=icon_size, + parent=parent) + controls.append(control) + + # Add the buttons on the bottom and stack + # them above each other with side padding + controls.reverse() + for i, control in enumerate(controls): + previous = controls[i - 1] if i > 0 else web_button + + mc.formLayout(parent, edit=True, + attachControl=[control, "bottom", 1, previous], + attachForm=([control, "left", 1], + [control, "right", 1])) diff --git a/res/icons/colorbleed_logo_36x36.png b/res/icons/colorbleed_logo_36x36.png new file mode 100644 index 0000000000..847a85c228 Binary files /dev/null and b/res/icons/colorbleed_logo_36x36.png differ diff --git a/res/icons/inventory.png b/res/icons/inventory.png new file mode 100644 index 0000000000..34f6488233 Binary files /dev/null and b/res/icons/inventory.png differ diff --git a/res/icons/loader.png b/res/icons/loader.png new file mode 100644 index 0000000000..1988fc76e9 Binary files /dev/null and b/res/icons/loader.png differ