Skip to content

Instantly share code, notes, and snippets.

@justinfx
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/9027370 to your computer and use it in GitHub Desktop.
Save justinfx/9027370 to your computer and use it in GitHub Desktop.
Maya / PyQt: A variation of https://gist.github.com/justinfx/1381489 where we embed the Render View, instead
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
global app
class MyDialog(QtGui.QDialog):
def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)
self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
# need to set a name so it can be referenced by maya node path
self.verticalLayout.setObjectName("mainLayout")
# 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)))
cmds.setParent(layout)
paneLayout = cmds.paneLayout()
self.modelPanelName = cmds.modelPanel("customRenderViewPanel", label="Custom Render View")
# Get the actual Qt objects from the Maya fullpaths
ptr = mui.MQtUtil.findControl(paneLayout)
self.paneLayout = sip.wrapinstance(long(ptr), QtCore.QObject)
ptr = mui.MQtUtil.findControl(self.modelPanelName)
self.modelPanel = sip.wrapinstance(long(ptr), QtCore.QObject)
# add our QObject reference to the modelPanel to our layout
self.verticalLayout.addWidget(self.paneLayout)
def showEvent(self, event):
super(MyDialog, self).showEvent(event)
# Set the panel to the Render View when the window is shown
self.modelPanel.repaint()
cmds.scriptedPanel("renderView", edit=True, rp=self.modelPanelName)
def show():
global app
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)
d.show()
return d
try:
d.deleteLater()
except:
pass
d = show()
"""
Example of hooking into the add/remove callbacks of the Render View panel.
Since the scriptedPanelType() apparently only deals in MEL, we have to
write MEL wrappers for our python callback functions.
This could potentially be used to change our custom display when we lose
the Render View to another panel view, or another view gives up its view
of the Render View panel.
"""
import maya.cmds as cmds
import maya.mel as mm
def addRenderWindowPanel(panelName):
print "addRenderWindowPanel!", panelName
mm.eval('addRenderWindowPanel "%s"' % panelName)
def removeRenderWindowPanel(panelName):
print "removeRenderWindowPanel!", panelName
mm.eval('removeRenderWindowPanel "%s"' % panelName)
mm.eval('''proc addRenderWindowPanelCust(string $panelName)
{
python("addRenderWindowPanel('" + $panelName + "')");
}
''')
mm.eval('''proc removeRenderWindowPanelCust(string $panelName)
{
python("removeRenderWindowPanel('" + $panelName + "')");
}
''')
cmds.scriptedPanelType("renderWindowPanel", e=True, acb='addRenderWindowPanelCust')
cmds.scriptedPanelType("renderWindowPanel", e=True, rcb='removeRenderWindowPanelCust')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment