Skip to content Skip to sidebar Skip to footer

Python: Change Class Type With Decorator And Keep It's Methods

I want to create a class which could be used inside different Applications and their APIs to create UIs. Therefor I created a module called ui.py. Inside this module is the followi

Solution 1:

This looks related to Python: RuntimeError: super-class __init__() of %S was never called but your setup is kind of different so I'll extrapolate to make it more clear.

Traceback (most recent call last):
  File"C:/test/maxUi.py", line 13, in <module>
    A.CreateGui()
RuntimeError: super-class__init__() oftypeTool_UI was never called

This means somewhere in the class hierarchy for Tool_UI that super(...).__init__(...) is not being called. This appears to be raised by QObject or QWidget. Looking at the class defined in GetUiObject(), there is no call to the super's init even though the parent class pUI is QWidget. You most likely need to add a call to the super init there:

defGetUiObject(uiClass):
    pUI = uiClass.PARENT

    classParentUI(pUI):def__init__(self, uiFile):
            super(ParentUI, self).__init__() # <-- Missing.
            CreateGui(uiFile, self)

        def__call__(self, cls):
            for func in uiClass.__dict__:
                setattr(cls, func, uiClass.__dict__[func])

    return ParentUI

Post a Comment for "Python: Change Class Type With Decorator And Keep It's Methods"