1

Ok so I'm having a bit of a problem with the code below. It works as is but if I try to change the part with the comment about me not being able to get super to work correctly to.

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

or to

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

and change

class Error_Popup(QtGui.QDialog):

to

class Error_Popup(QtGui.QDialog,Pipeline_UI):

I get the following error

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

Which normally means that I need to call the method, but doesn't super handle all this for me. Or am I goofing this?

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

Thanks in advance everyone

1 Answers1

1

Looks to me like it's a problem of using super with multiple inheritance. It picks one of the parents in a certain order to use. For example, super(Error_Popup,self).__init__(parent) only calls one of the parents __init__ methods. You have to manually call all of them.

When calling methods or accessing variables, you have to be specific about which parent you want to use or super will pick for you. See this answer and this answer.

leetNightshade
  • 2,673
  • 2
  • 36
  • 47
  • makes me question the validity of super in general. – timcoolmode May 02 '15 at 03:34
  • 1
    I think Super is a great design in itself. But it can be confusing on how it works. In general multiple inheritance is complex and you should be aware how the MRO works. I think this explains super the best https://www.youtube.com/watch?v=EiOglTERPEo – skar May 06 '15 at 16:38