Created
December 10, 2016 22:32
-
-
Save tokejepsen/f3b0c710216448e0d946ac441bd82ae4 to your computer and use it in GitHub Desktop.
Maya Widget Explorer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from shiboken import wrapInstance | |
from maya import cmds | |
from maya import mel | |
from maya import OpenMayaUI as omui | |
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin, MayaQWidgetDockableMixin | |
class WidgetHierarchyTree(MayaQWidgetBaseMixin, QTreeView): | |
def __init__(self, rootWidget=None, *args, **kwargs): | |
super(WidgetHierarchyTree, self).__init__(*args, **kwargs) | |
self.setAttribute(Qt.WA_DeleteOnClose, True) | |
# Determine root widget to scan | |
if rootWidget != None: | |
self.rootWidget = rootWidget | |
else: | |
mayaMainWindowPtr = omui.MQtUtil.mainWindow() | |
self.rootWidget = wrapInstance(long(mayaMainWindowPtr), QWidget) | |
self.populateModel() | |
def populateModel(self): | |
# Create the headers | |
self.columnHeaders = ['Class', 'ObjectName', 'Children'] | |
myModel = QStandardItemModel(0,len(self.columnHeaders)) | |
for col,colName in enumerate(self.columnHeaders): | |
myModel.setHeaderData(col, Qt.Horizontal, colName) | |
# Recurse through child widgets | |
parentItem = myModel.invisibleRootItem(); | |
self.populateModel_recurseChildren(parentItem, self.rootWidget) | |
self.setModel( myModel ) | |
def populateModel_recurseChildren(self, parentItem, widget): | |
# Construct the item data and append the row | |
classNameStr = str(widget.__class__).split("'")[1] | |
classNameStr = classNameStr.replace('PySide.','').replace('QtGui.', '').replace('QtCore.', '') | |
items = [QStandardItem(classNameStr), | |
QStandardItem(widget.objectName()), | |
QStandardItem(str(len(widget.children()))), | |
] | |
parentItem.appendRow(items) | |
# Recurse children and perform the same action | |
for childWidget in widget.children(): | |
self.populateModel_recurseChildren(items[0], childWidget) | |
widget = WidgetHierarchyTree() | |
widget.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment