Hi guys!
(Edit: Unless you’re dead set on using Eclipse/PyDev, I would recommend giving Sublime Text 2 a go. See this thread: https://discourse.panda3d.org/viewtopic.php?p=84204)
There are already a number of helper posts on how to get Panda3D working in Eclipse with Pydev, but I have yet to see one fixing code completion on classes imported from panda3d.core. Maybe it works better if you use the bundled python runtime, I don’t know. Still If you’re like me and using your own installation, I’m here to help you fix your code completion.
If you haven’t setup Panda3D in Eclipse before you’ll want to read these posts.
[url]Code complete in Pydev and Eclipse with Panda3D]
[url]urgent help with eclipse]
Now, the code completion. Due to the black magic (see http://www.panda3d.org/blog/?p=22) used to import from panda3d.core, Pydev is unable see the classes within. We can help Pydev by creating some predefined compilations:
http://pydev.org/manual_101_interpreter.html#id2
There are A LOT of classes in panda3d.core so doing it by hand is not an option. Instead you can use the below script to generate a file called panda3d.core.pypredef. Place it anywhere you like, and then configure Pydev as mentioned in the above link. The script adds all classes, “constants” and functions in panda3d.core. It also adds all member functions of said classes. I haven’t been able to make it add function arguments, but I’m working on it. Enjoy!
Edit: Updated the code with rndbit’s fixes.
# -*- coding: UTF-8 -*-
import inspect
from panda3d.core import *
import libpanda, libpandaexpress
from panda3d.fx import *
import libpandafx
from panda3d.dtoolconfig import *
import libp3dtoolconfig
from panda3d.physics import *
import libpandaphysics
from panda3d.direct import *
import libp3direct
from panda3d.egg import *
import libpandaegg
from panda3d.ode import *
import libpandaode
from panda3d.bullet import *
import libpandabullet
from panda3d.vision import *
import libp3vision
#from panda3d.physx import *
#import libpandaphysx
from panda3d.ai import *
import libpandaai
#from panda3d.awesomium import *
#import libp3awesomium
#from panda3d.speedtree import *
#import libpandaspeedtree
from panda3d.rocket import *
import _rocketcore, _rocketcontrols, libp3rocket
BUILD = {
'fx' : [libpandafx]
,'core' : [libpanda, libpandaexpress]
,"dtoolconfig" : [libp3dtoolconfig]
,"physics" : [libpandaphysics]
,"fx" : [libpandafx]
,"direct" : [libp3direct]
,"egg" : [libpandaegg]
,"ode" : [libpandaode]
,"bullet" : [libpandabullet]
,"vision" : [libp3vision]
# ,"physx" : [libpandaphysx]
,"ai" : [libpandaai]
# ,"awesomium" : [libp3awesomium]
# ,"speedtree" : [libpandaspeedtree]
,"rocket" : [_rocketcore, _rocketcontrols, libp3rocket],
}
indent = ' '
importptrn = 'from panda3d.%s import %s'
skip = [
'DtoolGetSupperBase',
'DtoolClassDict'
]
def record(t, name, f, noclasses=False, baseIndent=''):
if name.startswith('__'): return
if isinstance(t, int):
f.write('%s%s = int\n\n' % (baseIndent, name))
return True
elif isinstance(t, float):
f.write('%s%s = float\n\n' % (baseIndent, name))
return True
elif isinstance(t, str):
f.write('%s%s = str\n\n' % (baseIndent, name))
return True
elif inspect.isclass(t):
if noclasses: return
try:
f.write('%sclass %s:\n%s def __init__(self):\n%s pass\n' % (baseIndent, name, baseIndent, baseIndent))
except:
f.write('%sclass %s:\n%s def __init__(self):\n%s pass\n' % (baseIndent, t.__name__, baseIndent, baseIndent))
for _name in dir(t):
if _name in skip:
continue
try:
_t = eval('%s.%s' %(name, _name))
except:
return False
record(_t, _name, f, noclasses=True, baseIndent=('%s ' % baseIndent))
return True
elif callable(t):
if hasattr(t, '__objclass__'):
f.write('%sdef %s(self):\n%s pass\n' % (baseIndent, t.__name__, baseIndent))
else:
f.write('%sdef %s():\n%s pass\n' % (baseIndent, t.__name__, baseIndent))
return True
return False
def generateCore(base_name, modules):
f = open('predef/panda3d.%s.pypredef' % base_name, 'w+')
for module in modules:
for name in dir(module):
try:
exec(importptrn % (base_name, name))
t = eval(name)
print "Building %s..." % name
record(t, name, f)
except Exception, e:
print e
continue
f.close()
if __name__ == '__main__':
for (name, module) in BUILD.items():
generateCore(name, module)