好的,我在下面的代码中遇到了一些问题。它按原样工作,但是如果我尝试用关于我的评论改变部分而不能使超级工作正常工作。
pipeline_class_call = super(Error_Popup,self)
broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file()
或
broken_file_w_whats_wrong = super(Error_Popup,self).whats_wrong_with_file()
并更改
class Error_Popup(QtGui.QDialog):
到
class Error_Popup(QtGui.QDialog,Pipeline_UI):
我收到以下错误
# 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()
先谢谢大家
答案 0 :(得分:1)
在我看来,这是一个使用super
多重继承的问题。它按照特定顺序选择其中一个父母使用。例如,super(Error_Popup,self).__init__(parent)
仅调用其中一个父__init__
方法。您必须手动调用所有这些。
在调用方法或访问变量时,您必须具体说明要使用哪个父级或super
将为您选择。请参阅this answer和this answer。