Issues with inheritance

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

Replacing any DirectFrame declaration with a declaration of this class doesn’t work. What gives?

The DirectGui system plays some shenanigans to ensure that the initialiseoptions() call is only made once, by the most specific constructor. Since you have created a more specific constructor, it therefore becomes your responsibility to call this method. Try this code:

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


drwr, can you explain this inheritance issue with DirectFrame?

In [1]: from pandac.PandaModules import *

In [2]: import direct.directbase.DirectStart
DirectStart: Starting the game.
Warning: DirectNotify: category 'Interval' already exists
Known pipe types:
(all display modules loaded.)
:util(warning): Adjusting global clock's real time by 0.347273 seconds.

In [3]: from direct.gui.DirectGui import *

In [4]: class Foo(DirectFrame):
   ...:     pass

In [5]: f = DirectFrame()

In [6]: f.bounds
Out[6]: [0.0, 0.0, 0.0, 0.0]

In [7]: f = Foo()

In [8]: f.bounds
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/home/seanh/<ipython console> in <module>()

<type 'exceptions.AttributeError'>: 'Foo' object has no attribute 'bounds'

In [9]:

As above. You need to declare your own init() and have it explicitly call initialiseoptions. This is because the default init() function checks the value of self.class, and won’t call initialiseoptions unless it is the most specific init.

The upshot is, if you inherit from a DirectGui object, you must define your own init() to call initialiseoptions(), or it won’t get called and the object won’t be fully initialized.


Oh right yeah. My head is half way between Java and Python. Argh.