Skip to content

Instantly share code, notes, and snippets.

@mottosso
Last active July 4, 2016 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mottosso/73b6f60de4abcc306ae0 to your computer and use it in GitHub Desktop.
Save mottosso/73b6f60de4abcc306ae0 to your computer and use it in GitHub Desktop.
Add an action to the Maya "Status Bar"
import os
from PySide import QtGui
# Use this to locate your widget; it will return the
# widget currently under your cursor.
# parent = QtGui.qApp.widgetAt(QtGui.QCursor.pos())
# parent.objectName()
# Use this once you know the name of it, in this case "toolBar1"
# We can find it as a child of the main window.
window = {o.objectName(): o for o in QtGui.qApp.topLevelWidgets()}["MayaWindow"]
toolbar = window.findChild(QtGui.QToolBar, "toolBar1")
# This particular QToolBar has been configured to only show
# icons, no text. So we'll need to grab a random icon off your system.
icon_dir = os.environ["XBMLANGPATH"].split(os.pathsep)[1].rstrip("%B")
icon_fname = os.path.join(icon_dir, os.listdir(icon_dir)[0])
icon_pixmap = QtGui.QPixmap(icon_fname)
icon_icon = QtGui.QIcon(icon_pixmap)
# Create a random action
action = QtGui.QAction(icon_icon, "Hello", toolbar)
# Add to the start..
toolbar.insertAction(toolbar.actions()[0], action)
# Or to the end..
# toolbar.addAction(action)
# If you need to replace/update it, you can remove it like so.
# toolbar.removeAction(action)
# Enjoy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment