关于pyside:超级的python问题

python problems with super

好吧,我对下面的代码有点问题。它按原样工作,但如果我试图改变的部分与评论,我不能让超级正确地工作。

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

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

和改变

1
class Error_Popup(QtGui.QDialog):

1
class Error_Popup(QtGui.QDialog,Pipeline_UI):

我得到以下错误

1
# TypeError: object of type 'instancemethod' has no len() #

这通常意味着我需要调用这个方法,但不能为我超级处理所有这些。还是我在偷懒?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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_Popup,self).__init__(parent)只调用父级__init__方法之一。你必须手动呼叫所有人。

在调用方法或访问变量时,必须具体说明要使用哪个父级,或者super将为您选择哪个父级。看看这个答案和这个答案。