A small correction (to the manual)

This page:


contains the following sample class that listens for mouse clicks:

class Hello(DirectObject.DirectObject):
def init(self):
def printHello(self):
print ‘Hello!’

At least in 1.0.5 it should be class Hello(DirectObject). Maybe this part of the manual was updated for 1.1, or maybe it’s a mistake.

Thats the problem right now… 1.1 is still beta, but People are using it already. So some of the changes are already in the manual even if 1.0.5 is still “stable” and not “deprecated” :frowning:

I’d prefer too to have a STABLE 1.1 first before we start rewriting the manual with 1.1 specific changes… (or mention the changes in the manual, that they are 1.1 related)

However, thanks for pointing that out. :slight_smile:

Regards, Bigfoot29

Edit: Tested it: Its working the way its written with 1.0.5 too. However, in case you do

from direct.gui.DirectGui import *

you NEED to do:

class Hello(DirectObject):

If you only import

from direct.showbase import DirectObject

-Then you need to call it

class Hello(DirectObject.DirectObject)

Its like any other module. - Example:

import time
print 'hello'
print 'world!'


from time import *
print 'hello'
print 'world!'

Regards, Bigfoot29

Let me interject at this point that:

from direct.gui.DirectGui import *

in both Panda 1.0.5 and Panda 1.1.0 will import DirectObject for you. But this is not intended, and in fact, in the current CVS version of Panda, it does not do this, so you should not rely on it.
Ideally, if you want to reference DirectObject, you should import it yourself, and you should import it after you have imported DirectGui, like this:

from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject

This way, you can be confident that whenever you reference DirectObject, you are referencing it the way you intended, and you will be safe from code changes deep inside DirectGui.

In general, it is good advice within Python: if you use the “from blah import *” syntax to import something, all of your import * lines should appear before all of your other import lines, and you should always explictly import everything you reference within your own code.


I would like to add something for anyone new to panda or python:

Together, these two lines in the manual are incorrect. It says the line of code imports a class, but really it imports a module. Many of the classes in panda have the same name of the file that contains them, leading to the DirectObject module having a class attribute named DirectObject. This is why DirectObject.DirectObject is the class you would inherit from using the above code. It shouldn’t matter which version of panda you are using as long as you understand which namespace you have imported.

To import the class, use the dot syntax David showed above:

from direct.showbase.DirectObject import DirectObject

Then you can directly reference the DirectObject class without using the module name qualification.