Maya API / PySide2,wrapInstance中的错误参数

时间:2018-03-31 16:15:10

标签: python api pyqt pyside maya

尝试为Maya学习一些PySide2,但还没有明确的PySide2文档,所以在网上搜索再次来到这里寻求帮助...

我会直接解决问题 -

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)

错误:TypeError:文件第9行:' wrapInstance'用错误的参数类型调用:

wrapInstance(long,module)

支持的签名:

wrapInstance(size_t,PyType)#

祝你好运!

1 个答案:

答案 0 :(得分:0)

您应该尝试通过以下方式导入模块:

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()