好的。使用 Maya cmds 创建图形编辑器面板的超级快速示例:
import maya.cmds as cmds
cmds.window()
cmds.frameLayout()
cmds.animCurveEditor()
cmds.showWindow()
但是,对于将来,如果您想添加任何无法作为 Maya 命令使用的 Maya 小部件,您可以使用 PySide 的强大功能来做到这一点。这是一个例子。这是我从 Nathan Horne 在 embedding Maya UI widgets on Qt UI 和 PySide/Shiboken 上的精彩帖子中稍微修改的代码:
import maya.cmds as cmds
import maya.OpenMayaUI as apiUI
from PySide import QtCore, QtGui
import shiboken
def wrapinstance(ptr, base=None):
"""
Utility to convert a pointer to a Qt class instance (PySide/PyQt compatible)
:param ptr: Pointer to QObject in memory
:type ptr: long or Swig instance
:param base: (Optional) Base class to wrap with (Defaults to QObject, which should handle anything)
:type base: QtGui.QWidget
:return: QWidget or subclass instance
:rtype: QtGui.QWidget
"""
if not globals().has_key('QtCore') or not globals().has_key('QtGui'):
return None
if ptr is None:
return None
ptr = long(ptr) # Ensure type
if globals().has_key('shiboken'):
if base is None:
qObj = shiboken.wrapInstance(long(ptr), QtCore.QObject)
metaObj = qObj.metaObject()
cls = metaObj.className()
superCls = metaObj.superClass().className()
if hasattr(QtGui, cls):
base = getattr(QtGui, cls)
elif hasattr(QtGui, superCls):
base = getattr(QtGui, superCls)
else:
base = QtGui.QWidget
return shiboken.wrapInstance(long(ptr), base)
elif globals().has_key('sip'):
base = QtCore.QObject
return sip.wrapinstance(long(ptr), base)
else:
return None
def getMayaWindow():
ptr = apiUI.MQtUtil.mainWindow()
return wrapinstance(long(ptr), QtCore.QObject)
def toQtObject(mayaName):
'''
Given the name of a Maya UI element of any type,
return the corresponding QWidget or QAction.
If the object does not exist, returns None
'''
ptr = apiUI.MQtUtil.findControl(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findLayout(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findMenuItem(mayaName)
if ptr is not None:
return wrapinstance(long(ptr), QtCore.QObject)
class MayaSubWindow(QtGui.QMainWindow):
def __init__(self, parent=getMayaWindow()):
super(MayaSubWindow, self).__init__(parent)
qtObj = toQtObject(cmds.animCurveEditor())
#Fill the window, could use qtObj.setParent
#and then add it to a layout.
self.setCentralWidget(qtObj)
myWindow = MayaSubWindow()
myWindow.show()
即使这是一段看似很长的代码,您也可以放心地将wrapinstance()、getMayaWindow() 和toQtObject() 添加到实用程序模块中以供重复使用。
希望有用。