Search code examples
pythonapipyqtpysidemaya

Maya API/ PySide2 , wrong argument in wrapInstance


Trying to learn some PySide2 for Maya, but there is no clear documentation for PySide2 yet, so after searching in internet coming here again for help...

I will go straight to the problem -

from PySide2 import QtWidgets, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import shiboken2

def getMayaWindow():
    pointer  = mui.MQtUtil.mainWindow()
    if pointer is not None:
        return shiboken2.wrapInstance(long(pointer), QtWidgets)

Error: TypeError: file line 9: 'wrapInstance' called with wrong argument types:

wrapInstance(long, module)

Supported signatures:

wrapInstance(size_t, PyType) #

Best regards!


Solution

  • You should try to import modules by the following way:

    import maya.cmds as cmds
    from PySide2.QtCore import * 
    from PySide2.QtGui import *
    from PySide2.QtWidgets import *
    import maya.OpenMayaUI as omui
    
    try:
        from shiboken import wrapInstance
    except:
        from shiboken2 import wrapInstance
    
    
    def getMayaWindow():    
        pointer = omui.MQtUtil.mainWindow()
        if pointer is not None:
            return shiboken2.wrapInstance(long(pointer), QWidget)
    
    getMayaWindow()