that was a question , because if i do a complex ui, there are many nested layout, and there will be ||| errors, when i press 4 or 5 ? shall i manually call setObjectName on all the "missing" layouts? this doesn't feel correct to me .)
On Saturday, May 24, 2014 3:23:47 AM UTC+8, Justin Israel wrote: > > Wasn't sure if this was a question or another example of how to do it? > > Also another thing I found was that Maya didn't seem to like layouts being > added to layouts. I had to add a widget in between. Maybe that has changed. > Haven't tested it in the latest Maya. > > - Justin (aka Justine) > On May 24, 2014 5:50 AM, "oglop" <[email protected] <javascript:>> wrote: > > i know this has been > asked<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA>on > 2011 and Justine has an awesome example > here <https://gist.github.com/justinfx/1381489> > you saw the last few lines i commented out the setObjectName xxxx and > yyyyy, without them, when you run the code in maya, it successfully opens > the ui, but when you press 4 or 5 on the modelPanel, you will see the > following error message similar to : > > updateModelPanelBar > MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5; > > notice the ||| part. > > it seems as if without object names set, maya doesn't know how to find the > newly created modelPanel. also if i'm using mainwindow i also see this > error unless i set object names using an awkward workaround. > > example1 > > from PyQt4 import QtCore,QtGui > > import maya.cmds as cmds > import maya.OpenMayaUI as OpenMayaUI > import sip > > def getMayaWindow(): > windowPointer = OpenMayaUI.MQtUtil.mainWindow() > return sip.wrapinstance(long(windowPointer), QtCore.QObject) > > class MayaView(QtGui.QDialog): > def __init__(self,parent=None,**kwargs): > super(MayaView,self).__init__(parent,**kwargs) > > self.setObjectName('MyWindow') > > self.setWindowTitle('3dView') > > self.verticalLayout = QtGui.QVBoxLayout(self) > self.verticalLayout.setContentsMargins(0,0,0,0) > self.verticalLayout.setObjectName("mainLayout") > > applyBut = QtGui.QPushButton('Apply') > closeBut = QtGui.QPushButton('Close') > butLayout = QtGui.QHBoxLayout() > butLayout.addWidget(applyBut) > butLayout.addWidget(closeBut) > butLayout.setObjectName("xxxBut") > > layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self. > verticalLayout))) > print "vertical layout",layout > > cmds.setParent(layout) > > paneLayoutName = cmds.paneLayout() > # find a pointer to the paneLayout that we just created > ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName) > # warp the pointer into a python QObject > self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject) > > # new create a camera > self.cameraName = cmds.camera(n='PickerView_camera')[0] > cmds.hide(self.cameraName) > cmds.viewFit(self.cameraName,all=True) > self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent= > paneLayoutName) > > # edit model panel > modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me= > True) > cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca= > False,grid=False,hud=False,\ > manipulators=False,displayTextures=True,ha=False, > j=False,ikh=False,df=False,\ > dim=False,lc=False,nc=True,wos=False,dl='default' > ,av=False) > > # find a pointer to the modelPanel that we just created > ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName) > #wrap the pointer into a python QObject > self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject) > #add our QObject reference to the paneLayout to our layout > self.verticalLayout.addWidget(self.paneLayout) > self.verticalLayout.addLayout(butLayout) > self.verticalLayout.setSpacing(0) > self.setLayout(self.verticalLayout) > > self.setFixedSize(400,600) > > class MainWin(QtGui.QDialog): > def __init__(self,parent=getMayaWindow()): > super(MainWin,self).__init__(parent) > cam = MayaView() > # self.setObjectName('xxxxxx') > but = QtGui.QPushButton('zzz') > layout = QtGui.QVBoxLayout() > layout.addWidget(but) > layout.addWidget(cam) > self.setLayout(layout) > # layout.setObjectName('yyyyy') > > a = MainWin() > a.show() > > > > > > example2: > > from PyQt4 import QtCore,QtGui > > import maya.cmds as cmds > import maya.OpenMayaUI as OpenMayaUI > import sip > def getMayaWindow(): > windowPointer = OpenMayaUI.MQtUtil.mainWindow() > return sip.wrapinstance(long(windowPointer), QtCore.QObject) > class MayaView(QtGui.QWidget): > def __init__(self,parent=None,**kwargs): > super(MayaView,self).__init__(parent,**kwargs) > > self.setObjectName('MyWindow') > > self.setWindowTitle('3dView') > > self.verticalLayout = QtGui.QVBoxLayout(self) > self.verticalLayout.setContentsMargins(0,0,0,0) > self.verticalLayout.setObjectName("mainLayout") > > > applyBut = QtGui.QPushButton('Apply') > closeBut = QtGui.QPushButton('Close') > butLayout = QtGui.QHBoxLayout() > butLayout.addWidget(applyBut) > butLayout.addWidget(closeBut) > > layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self. > verticalLayout))) > cmds.setParent(layout) > > paneLayoutName = cmds.paneLayout() > # find a pointer to the paneLayout that we just created > ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName) > # warp the pointer into a python QObject > self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject) > > # new create a camera > self.cameraName = cmds.camera(n='PickerView_camera')[0] > cmds.hide(self.cameraName) > cmds.viewFit(self.cameraName,all=True) > > self.modelPanelName = cmds.modelPanel(cam=self.cameraName) > cmds.panel(self.modelPanelName,e=True,mbv=False) > flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout= > True) > cmds.frameLayout(flayout,e=True,collapse=True) > # edit model panel > modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me= > True) > cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca= > False,grid=False,hud=False,\ > manipulators=False,displayTextures=True,ha=False, > j=False,ikh=False,df=False,\ > dim=False,lc=False,nc=True,wos=False,dl='default' > ,av=False) > > # find a pointer to the modelPanel that we just created > ptr <span style="co > > ... -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ff495809-87af-44e5-80ac-ae34767a63f9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
