Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 超级用户的python问题_Python 2.7_Pyside_Maya_Super - Fatal编程技术网

Python 2.7 超级用户的python问题

Python 2.7 超级用户的python问题,python-2.7,pyside,maya,super,Python 2.7,Pyside,Maya,Super,好的,下面的代码有点问题。它按原样工作,但如果我试图改变部分,并评论我无法让super正常工作 pipeline_class_call = super(Error_Popup,self) broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file() 或 改变 class Error_Popup(QtGui.QDialog): 到 我得到以下错误 # TypeError: object of type 'inst

好的,下面的代码有点问题。它按原样工作,但如果我试图改变部分,并评论我无法让super正常工作

pipeline_class_call = super(Error_Popup,self)
broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file()

改变

class Error_Popup(QtGui.QDialog):

我得到以下错误

# TypeError: object of type 'instancemethod' has no len() # 
这通常意味着我需要调用该方法,但不能为我超级处理所有这些。还是我搞错了

from PySide import QtCore, QtGui
from shiboken import wrapInstance
import pymel.core as pm
import maya.OpenMayaUI as omui
from UI.UI import Pipeline_UI

def something_bad_happened_window():
    sbh_pointer = omui.MQtUtil.mainWindow()
    return wrapInstance(long(sbh_pointer), QtGui.QWidget)

class Error_Popup(QtGui.QDialog):

    def __init__(self,parent=something_bad_happened_window()):
        super(Error_Popup,self).__init__(parent)

        self.setWindowTitle('Something Bad Happened!')
        self.setWindowFlags(QtCore.Qt.Tool)
        self.popup_layout()
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.connections()

    def popup_layout(self):
        self.file_description = QtGui.QListWidget()


        #cant seem to get super to work appropriately... booo
        pipeline_class_call = Pipeline_UI()
        broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file()

        for display in range(0,len(broken_file_w_whats_wrong)):

            broken_list = QtGui.QListWidgetItem()
            if display % 2 == 0:
                broken_list.setText(broken_file_w_whats_wrong[display][0])
                broken_list.asset = broken_file_w_whats_wrong[display][1]

            else:
                broken_list.setText("   " + broken_file_w_whats_wrong[display][0])

            self.file_description.addItem(broken_file_w_whats_wrong[display])

        self.import_button = QtGui.QPushButton('Import Replacement(s)')

        error_layout = QtGui.QVBoxLayout()
        error_layout.setContentsMargins(2,2,2,2)
        error_layout.setSpacing(2)


        error_layout.addWidget(self.file_description)
        error_layout.addWidget(self.import_button)

        error_layout.addStretch()


        self.setLayout(error_layout)

    def connections(self):
        self.import_button.clicked.connect(Error_Popup.make_sphere)


    @classmethod
    def make_sphere(cls):
        pm.polySphere()


def show_window():

    ui = Error_Popup()

    if __name__ == '__main__':
        try:
            ui.close()
        except:
            pass

    ui.show()

show_window()  

提前感谢大家

在我看来,在多重继承中使用
super
是个问题。它按照特定的顺序选择一个父对象来使用。例如,
super(Error\u Popup,self)。\uuuuu init\uuuu(parent)
只调用其中一个parent
\uuuuuu init\uuu
方法。您必须手动调用所有这些


调用方法或访问变量时,必须明确要使用哪个父级,或者
super
将为您选择哪个父级。见和

总的来说,我对super的有效性提出了质疑。我认为super本身就是一个伟大的设计。但它可能会让人对它的工作原理感到困惑。一般来说,多重继承是复杂的,您应该知道MRO是如何工作的。我认为这是最好的解释
# TypeError: object of type 'instancemethod' has no len() # 
from PySide import QtCore, QtGui
from shiboken import wrapInstance
import pymel.core as pm
import maya.OpenMayaUI as omui
from UI.UI import Pipeline_UI

def something_bad_happened_window():
    sbh_pointer = omui.MQtUtil.mainWindow()
    return wrapInstance(long(sbh_pointer), QtGui.QWidget)

class Error_Popup(QtGui.QDialog):

    def __init__(self,parent=something_bad_happened_window()):
        super(Error_Popup,self).__init__(parent)

        self.setWindowTitle('Something Bad Happened!')
        self.setWindowFlags(QtCore.Qt.Tool)
        self.popup_layout()
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.connections()

    def popup_layout(self):
        self.file_description = QtGui.QListWidget()


        #cant seem to get super to work appropriately... booo
        pipeline_class_call = Pipeline_UI()
        broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file()

        for display in range(0,len(broken_file_w_whats_wrong)):

            broken_list = QtGui.QListWidgetItem()
            if display % 2 == 0:
                broken_list.setText(broken_file_w_whats_wrong[display][0])
                broken_list.asset = broken_file_w_whats_wrong[display][1]

            else:
                broken_list.setText("   " + broken_file_w_whats_wrong[display][0])

            self.file_description.addItem(broken_file_w_whats_wrong[display])

        self.import_button = QtGui.QPushButton('Import Replacement(s)')

        error_layout = QtGui.QVBoxLayout()
        error_layout.setContentsMargins(2,2,2,2)
        error_layout.setSpacing(2)


        error_layout.addWidget(self.file_description)
        error_layout.addWidget(self.import_button)

        error_layout.addStretch()


        self.setLayout(error_layout)

    def connections(self):
        self.import_button.clicked.connect(Error_Popup.make_sphere)


    @classmethod
    def make_sphere(cls):
        pm.polySphere()


def show_window():

    ui = Error_Popup()

    if __name__ == '__main__':
        try:
            ui.close()
        except:
            pass

    ui.show()

show_window()