You need a shiboken-based type

妖精的绣舞 提交于 2020-06-27 03:59:17

问题


When i run the code i get the following error line 11: You need a shiboken-based type. Not sure what i am doing wrong here . When i run just the GetMayaWindow() its runs properly but when run it in init its gives me error

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:


You cannot mix PySide and PyQt classes/objects.

The QtGui module gets imported twice, so sys.modules will contain an entry for both PySide.QtGui and PyQt4.QtGui. But since sys.modules is a dict, python cannot guarantee which one you will get when you reference QtGui later on.

In your case, it's obvious that QtGui.QMainWindow is actually a PyQt4 class, which is why you get that error.



来源:https://stackoverflow.com/questions/31117393/you-need-a-shiboken-based-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!