Running the code below adds the splitter. Do you know if there's a work around
for this?
Thanks
from PySide2 import QtCore, QtWidgets
import shiboken2
import maya.cmds as cmds
import maya.OpenMayaUI as mui
#class MyDialog(QtWidgets.QDialog):
class MyDialog(QtWidgets.QMainWindow):
def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)
self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)
#self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout = QtWidgets.QVBoxLayout(self.central_widget)
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(shiboken2.getCppPointer(self.verticalLayout)[0]))
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# Find a pointer to the paneLayout that we just created
ptr = mui.MQtUtil.findControl(paneLayoutName)
# Wrap the pointer into a python QObject
self.paneLayout = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
self.cameraName = cmds.camera()[0]
self.modelPanelName = cmds.modelPanel("customModelPanel#",
label="ModelPanel Test", cam=self.cameraName)
timeline = cmds.timePort('cameraViewerTimePort')
time_ptr = mui.MQtUtil.findControl(timeline)
self.timePaneLayout = shiboken2.wrapInstance(long(time_ptr),
QtWidgets.QWidget)
# Find a pointer to the modelPanel that we just created
ptr = mui.MQtUtil.findControl(self.modelPanelName)
# Wrap the pointer into a python QObject
self.modelPanel = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
splitter1 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
splitter1.addWidget(self.paneLayout)
splitter1.addWidget(self.timePaneLayout)
splitter1.setSizes([500, 200])
# add our QObject reference to the paneLayout to our layout
#self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addWidget(splitter1)
def showEvent(self, event):
super(MyDialog, self).showEvent(event)
# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
self.modelPanel.repaint()
def show():
# get a pointer to the maya main window
ptr = mui.MQtUtil.mainWindow()
# use sip to wrap the pointer into a QObject
win = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
d = MyDialog(win)
d.show()
return d
try:
dialog.deleteLater()
except:
pass
dialog = show()
________________________________
From: Timothy Kim
Sent: Thursday, August 23, 2018 12:35:46 PM
To: [email protected]
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?
Hey Justin,
It seems like putting the paneLayout into a QSplitter causes the issue. I
edited your code to add the splitter.
________________________________
From: [email protected] <[email protected]>
on behalf of Timothy Kim <[email protected]>
Sent: Monday, August 20, 2018 9:44:08 AM
To: [email protected]
Subject: [MailingList] Re: [Maya-Python] Re: How to embed modelPanel to a pyqt
ui (again) ?
Thank Justin. I don't have access to my code right now to check the differences
between mine and this one but this code works perfectly fine. Thanks again.
________________________________
From: [email protected] <[email protected]>
on behalf of Justin Israel <[email protected]>
Sent: Sunday, August 19, 2018 9:37:26 PM
To: [email protected]
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?
** Incoming mail from outside The Mill **
On Sat, Aug 18, 2018 at 4:14 AM tim2018
<[email protected]<mailto:[email protected]>> wrote:
Hello, Thanks for the examples but I noticed that none of the icons in
modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have no
effect in the viewport. Does anyone know how to fix this problem? I am
referring to example1.
Thanks
I've updated the original blog post with a Maya >= 2017 port of that example
code:
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/
I tested it in Maya 2018 and it seems like the toolbar icons in the model
editor worked just fine. Can you confirm?
On Friday, 23 May 2014 13:50:56 UTC-4, oglop wrote:
i know this <http:///> 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 = 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.QMainWindow):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)
cam = MayaView()
self.mid.addSubWindow(cam)
a = MainWin()
a.show()
--
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]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com<https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.