Modal QDialog and modelEditor

25 views
Skip to first unread message

zoshua

unread,
Oct 22, 2014, 1:48:17 AM10/22/14
to python_in...@googlegroups.com
First time it runs fine.
Succesive calls to getSnapshot() makes maya unstable.
..
Anyone happen to get something like this working?

######################################
import maya.OpenMayaUI as apiUI
from PyQt4 import QtGui, QtCore
import sip

def getMayaWindow():
    ptr = apiUI.MQtUtil.mainWindow()
    return sip.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 sip.wrapinstance(long(ptr), QtCore.QObject)

class MayaSubWindow(QtGui.QDialog):
    def __init__(self, parent=None):
        super(MayaSubWindow, self).__init__(parent)
        
        self.setModal(True)
        
        self.verticalLayout = QtGui.QVBoxLayout(self)
        self.verticalLayout.setContentsMargins(0,0,0,0)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setSpacing(0)
        
        self.setLayout(self.verticalLayout)
        
        if cmds.modelEditor('snapEditor', query=True, exists=True):
          cmds.deleteUI('snapEditor', editor=True )
        self.mp = cmds.modelEditor('snapEditor', displayAppearance='smoothShaded', selectionHiliteDisplay=False, displayTextures=True, wos=False, camera='persp', imagePlane=False, nurbsCurves=False, lights=False, cameras=False, grid=False, joints=False, locators=False, headsUpDisplay=False)
        self.mp_qtObj = toQtObject(self.mp)
        
        self.verticalLayout.addWidget(self.mp_qtObj)
        
def getSnapshot():
    win = getMayaWindow()
    
    cs = MayaSubWindow(win)
    cs.show()
    cs.update()
    valid = cs.exec_()

    cs.close()
    
getSnapshot()
######################################

Marcus Ottosson

unread,
Oct 22, 2014, 1:59:11 AM10/22/14
to python_in...@googlegroups.com

For readability.

--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f8a09ce6-69de-43ce-9122-4dc3a1b4ae58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages