A question came up in the
Maya-Python mailing list that I thought was a really good topic, and should be reposted.
Someone asked how you can create maya UI objects and embed them within your main PyQt application. Specifically he wanted to create a modelPanel and embed it so that he would have a camera view within his own PyQt window.
Here is my example of how to achieve this…
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)
self.setWindowTitle("PyQt ModelPanel Test")
self.verticalLayout = QtGui.QVBoxLayout(self)
# need to set a name so it can be referenced by maya node path
# First use SIP to unwrap the layout into a pointer
# Then get the full path to the UI in maya as a string
layout = mui.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
self._cameraName = cmds.camera()
nodeName = cmds.modelPanel(cam=self._cameraName)
# Find a pointer to the modelPanel that we just created
ptr = mui.MQtUtil.findControl(nodeName)
# Wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr), QtCore.QObject)
# add our QObject reference to the modelPanel to our layout
# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
# use a shared instance of QApplication
app = QtGui.QApplication.instance()
# get a pointer to the maya main window
ptr = mui.MQtUtil.mainWindow()
# use sip to wrap the pointer into a QObject
win = sip.wrapinstance(long(ptr), QtCore.QObject)
d = MyDialog(win)
You need sip and the MQtUtil functions to convert between maya node paths and python Qbjects. Its the same idea as having to use those functions to get a reference to the maya MainWindow, in order to parent your dialog.