[Solved] Subclassing DirectFrame

So I want to make subclasses of DirectGUI elements. So I found this old thread: [url]Issues with inheritance]

But if I try this:

from direct.gui import DirectFrame

class MainGUI(DirectFrame):

    def __init__(self, **args):
        DirectFrame.__init__(self, **args)
        self.initialiseoptions(ParentedDirectFrame)

or this:

from direct.gui import DirectFrame

class MainGUI(DirectFrame):
    
    def __init__(self, **args):
        super(MainGUI, self).__init__()
        self.initialiseoptions(type(self))

I get this error:

TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)

The error points to the line “class MainGUI(DirectFrame):”.

I have no idea how to solve this. Any suggestions?

Looking at the reference entry for DirectFrame, it seems that DirectFrame also has a “parent” argument that I don’t see in your version.

Perhaps something like the following might work better:
(Note: I haven’t tried this myself that I recall, and may well be mistaken.)

class MainGUI(DirectFrame):

    def __init__(self, parent=None, **args):
        DirectFrame.__init__(self, parent, **args)
        # etc.

That’s not the main problem here. You’re simply importing DirectFrame incorrectly. Given how you’re using it, this is how you should be importing it:

from direct.gui.DirectFrame import DirectFrame

Otherwise, “DirectFrame” refers to the module it’s in, not the actual class.

Yup, that worked. Thanks a lot, rdb! You saved me a lot of trouble.

I always name modules with underscores as seperators instead of CamelCase as per PEP 8, only reserving CamelCase for classes, which is why I mistook the DirectFrame module for the class.

I’m impressed how quickly you guys reacted to this problem. I fully expected to get a answer only as quickly as tomorrow.