76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 | def override_toolbox_ui():
"""Add custom buttons in Toolbox as replacement for Maya web help icon."""
icons = resources.get_resource("icons")
parent_widget = get_main_window()
# Ensure the maya web icon on toolbox exists
button_names = [
# Maya 2022.1+ with maya.cmds.iconTextStaticLabel
"ToolBox|MainToolboxLayout|mayaHomeToolboxButton",
# Older with maya.cmds.iconTextButton
"ToolBox|MainToolboxLayout|mayaWebButton"
]
for name in button_names:
if cmds.control(name, query=True, exists=True):
web_button = name
break
else:
# Button does not exist
log.warning("Can't find Maya Home/Web button to override toolbox ui..")
return
cmds.control(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 cmds.objectTypeUI(parent) == "formLayout":
return
# Create our controls
controls = []
controls.append(
cmds.iconTextButton(
"ayon_toolbox_lookmanager",
annotation="Look Manager",
label="Look Manager",
image=os.path.join(icons, "lookmanager.png"),
command=lambda: show_look_assigner(
parent=parent_widget
),
width=icon_size,
height=icon_size,
parent=parent
)
)
controls.append(
cmds.iconTextButton(
"ayon_toolbox_workfiles",
annotation="Work Files",
label="Work Files",
image=os.path.join(icons, "workfiles.png"),
command=lambda: host_tools.show_workfiles(
parent=parent_widget
),
width=icon_size,
height=icon_size,
parent=parent
)
)
controls.append(
cmds.iconTextButton(
"ayon_toolbox_loader",
annotation="Loader",
label="Loader",
image=os.path.join(icons, "loader.png"),
command=lambda: host_tools.show_loader(
parent=parent_widget, use_context=True
),
width=icon_size,
height=icon_size,
parent=parent
)
)
controls.append(
cmds.iconTextButton(
"ayon_toolbox_manager",
annotation="Inventory",
label="Inventory",
image=os.path.join(icons, "inventory.png"),
command=lambda: host_tools.show_scene_inventory(
parent=parent_widget
),
width=icon_size,
height=icon_size,
parent=parent
)
)
# 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
cmds.formLayout(parent, edit=True,
attachControl=[control, "bottom", 0, previous],
attachForm=([control, "left", 1],
[control, "right", 1]))
|