你需要一个基于 shiboken 的类型 [英] You need a shiboken-based type

查看:59
本文介绍了你需要一个基于 shiboken 的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行代码时,出现以下错误第 11 行:您需要基于 shiboken 的类型.不知道我在这里做错了什么.当我只运行 GetMayaWindow() 时,它运行正常,但是在 init 中运行时,它给了我错误

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

推荐答案

您不能混合使用 PySide 和 PyQt 类/对象.

You cannot mix PySide and PyQt classes/objects.

QtGui 模块被导入两次,所以 sys.modules 将包含 PySide.QtGui 的条目> PyQt4.QtGui.但是由于 sys.modules 是一个 dict,python 不能保证你以后引用 QtGui 时会得到哪个.

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.

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

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

这篇关于你需要一个基于 shiboken 的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆