你需要一个基于shiboken的类型

时间:2015-06-29 13:47:33

标签: python pyqt4 maya

当我运行代码时,我得到以下错误行11:你需要一个基于shiboken的类型。不知道我在这里做错了什么。当我只运行GetMayaWindow()时它运行正常,但是当它在 init 中运行时它会给我错误

import shiboken
from PySide import QtGui
import maya.OpenMayaUI as apiUI
from cStringIO import StringIO
import pysideuic
import xml.etree.ElementTree as xml

def GetMayaWindow():
    ptr = apiUI.MQtUtil.mainWindow()
    if ptr is not None:
        return shiboken.wrapInstance(long(ptr),QtGui.QMainWindow)

def LoadUiType(ui_file):
    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text
    with open(ui_file,'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.compileUi(f,o,indent = 0)
        pyc = compile(o.getvalue(),'<string>','exec')
        exec pyc in frame

        form_class = frame ['Ui_{0}'.format(form_class)]
        base_class = eval('QtGui.{0}'.format(widget_class))

    return form_class,base_class

import shiboken
from PyQt4 import QtGui,QtCore,uic
from pymel.core import *
import pymel.core as pm
from pymel import *

ui_file = "D:/Swapnil/Workspace/R&D/modellingTools/ModellingTools.ui"
list_form,list_base = LoadUiType(ui_file)

class ModellingToolsUI(list_form,list_base):
    def __init__(self, parent =GetMayaWindow()):
        self.window_name = 'modellingTools'

        if window(self.window_name,exists = True ):
            deleteUI (seld.window_name)

        super(ModellingToolsUI,self).__init__(parent)
        self.setupUi(self)


def run_plugin():
    ex = ModellingToolsUI()
    ex.show()

1 个答案:

答案 0 :(得分:1)

你不能混合使用PySide和PyQt类/对象。

QtGui模块导入两次,因此sys.modules将包含PySide.QtGui {{1}的条目}。但由于PyQt4.QtGuisys.modules,因此python无法保证在您稍后引用dict时会得到哪一个。

在您的情况下,很明显QtGui实际上是QtGui.QMainWindow类,这就是您收到错误的原因。