Ok. Super quick example for creating a graph editor panel using Maya cmds:
import maya.cmds as cmds
cmds.window()
cmds.frameLayout()
cmds.animCurveEditor()
cmds.showWindow()

But, for future, if you want to add any Maya widget that isn't available as a Maya command, you could use PySide's power to do that. Here is an example. It is code that I slightly modified from Nathan Horne's awesome post on embedding Maya UI widgets on Qt UI and 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()
Even though this is a seemingly long piece of code, you can safely add wrapinstance()
, getMayaWindow()
and toQtObject()
to your utilities module for reuse.
Hope that was useful.