mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
Improve Python API ref
This commit is contained in:
parent
a6229f1fac
commit
ba1e18ce8b
@ -176,7 +176,7 @@ QT_AUTOBRIEF = YES
|
|||||||
# The new default is to treat a multi-line C++ comment block as a detailed
|
# The new default is to treat a multi-line C++ comment block as a detailed
|
||||||
# description. Set this tag to YES if you prefer the old behaviour instead.
|
# description. Set this tag to YES if you prefer the old behaviour instead.
|
||||||
|
|
||||||
MULTILINE_CPP_IS_BRIEF = NO
|
MULTILINE_CPP_IS_BRIEF = YES
|
||||||
|
|
||||||
# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
|
# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
|
||||||
# member inherits the documentation from any documented member that it
|
# member inherits the documentation from any documented member that it
|
||||||
@ -612,8 +612,7 @@ WARN_LOGFILE =
|
|||||||
# directories like "/usr/src/myproject". Separate the files or directories
|
# directories like "/usr/src/myproject". Separate the files or directories
|
||||||
# with spaces.
|
# with spaces.
|
||||||
|
|
||||||
INPUT = pandadoc.hpp \
|
INPUT = pandadoc.hpp built/direct
|
||||||
direct
|
|
||||||
|
|
||||||
# This tag can be used to specify the character encoding of the source files
|
# This tag can be used to specify the character encoding of the source files
|
||||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
|
||||||
@ -644,7 +643,15 @@ RECURSIVE = YES
|
|||||||
# excluded from the INPUT source files. This way you can easily exclude a
|
# excluded from the INPUT source files. This way you can easily exclude a
|
||||||
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
||||||
|
|
||||||
EXCLUDE = direct/src/test
|
EXCLUDE = built/direct/test \
|
||||||
|
built/direct/plugin \
|
||||||
|
built/direct/plugin_npapi \
|
||||||
|
built/direct/plugin_activex \
|
||||||
|
built/direct/plugin_installer \
|
||||||
|
built/direct/plugin_standalone \
|
||||||
|
built/direct/extensions \
|
||||||
|
built/direct/extensions_native \
|
||||||
|
built/direct/directscripts
|
||||||
|
|
||||||
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
|
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
|
||||||
# directories that are symbolic links (a Unix file system feature) are excluded
|
# directories that are symbolic links (a Unix file system feature) are excluded
|
||||||
|
@ -17,15 +17,34 @@ All use of this software is subject to the terms of the revised BSD
|
|||||||
license. You should have received a copy of this license along
|
license. You should have received a copy of this license along
|
||||||
with this source code in a file named \"LICENSE.\"""".split("\n")
|
with this source code in a file named \"LICENSE.\"""".split("\n")
|
||||||
|
|
||||||
libraries = {}
|
|
||||||
for m, lib in panda3d.modules.items():
|
|
||||||
if not isinstance(lib, str):
|
|
||||||
for l in lib:
|
|
||||||
libraries[l.replace("lib", "")] = m
|
|
||||||
else:
|
|
||||||
libraries[lib.replace("lib", "")] = m
|
|
||||||
|
|
||||||
def comment(code):
|
def comment(code):
|
||||||
|
if not code:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
comment = ''
|
||||||
|
|
||||||
|
empty_line = False
|
||||||
|
for line in code.splitlines(False):
|
||||||
|
line = line.strip('\t\n /')
|
||||||
|
if line:
|
||||||
|
if empty_line:
|
||||||
|
# New paragraph.
|
||||||
|
comment += '\n\n'
|
||||||
|
elif comment:
|
||||||
|
comment += '\n'
|
||||||
|
comment += '/// ' + line
|
||||||
|
else:
|
||||||
|
empty_line = True
|
||||||
|
|
||||||
|
if comment:
|
||||||
|
return comment
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def block_comment(code):
|
||||||
|
if not code:
|
||||||
|
return ""
|
||||||
|
|
||||||
lines = code.split("\n")
|
lines = code.split("\n")
|
||||||
newlines = []
|
newlines = []
|
||||||
indent = 0
|
indent = 0
|
||||||
@ -38,18 +57,18 @@ def comment(code):
|
|||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
strline = line.lstrip('/ \t')
|
strline = line.lstrip('/ \t')
|
||||||
if reading_desc:
|
if reading_desc:
|
||||||
newlines.append(line[min(indent, len(line) - len(strline)):])
|
newlines.append('/// ' + line[min(indent, len(line) - len(strline)):])
|
||||||
else:
|
else:
|
||||||
# A "Description:" text starts the description.
|
# A "Description:" text starts the description.
|
||||||
if strline.startswith("Description"):
|
if strline.startswith("Description"):
|
||||||
strline = strline[11:].lstrip(': \t')
|
strline = strline[11:].lstrip(': \t')
|
||||||
indent = len(line) - len(strline)
|
indent = len(line) - len(strline)
|
||||||
reading_desc = True
|
reading_desc = True
|
||||||
newlines.append(strline)
|
newlines.append('/// ' + strline)
|
||||||
|
|
||||||
newcode = "\n".join(newlines)
|
newcode = '\n'.join(newlines)
|
||||||
if len(newcode) > 0:
|
if len(newcode) > 0:
|
||||||
return "/** " + newcode + " */"
|
return newcode
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -67,6 +86,11 @@ def translateFunctionName(name):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
def translated_type_name(type):
|
def translated_type_name(type):
|
||||||
|
if interrogate_type_is_atomic(type):
|
||||||
|
token = interrogate_type_atomic_token(type)
|
||||||
|
if token == 7:
|
||||||
|
return 'str'
|
||||||
|
|
||||||
typename = interrogate_type_name(type)
|
typename = interrogate_type_name(type)
|
||||||
typename = typename.replace("< ", "").replace(" >", "")
|
typename = typename.replace("< ", "").replace(" >", "")
|
||||||
return typename
|
return typename
|
||||||
@ -76,13 +100,24 @@ def translateTypeSpec(name):
|
|||||||
name = name.replace("BitMask< unsigned int, 32 >", "BitMask32")
|
name = name.replace("BitMask< unsigned int, 32 >", "BitMask32")
|
||||||
name = name.replace("atomic ", "")
|
name = name.replace("atomic ", "")
|
||||||
name = name.replace("< ", "").replace(" >", "")
|
name = name.replace("< ", "").replace(" >", "")
|
||||||
|
if name == '_object':
|
||||||
|
name = 'object'
|
||||||
|
elif name == '_typeobject':
|
||||||
|
name = 'type'
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def processElement(handle, element):
|
||||||
|
if interrogate_element_has_comment(element):
|
||||||
|
print >>handle, comment(interrogate_element_comment(element))
|
||||||
|
|
||||||
|
print >>handle, translateTypeSpec(translated_type_name(interrogate_element_type(element))),
|
||||||
|
print >>handle, interrogate_element_name(element) + ';'
|
||||||
|
|
||||||
def processFunction(handle, function, isConstructor = False):
|
def processFunction(handle, function, isConstructor = False):
|
||||||
for i_wrapper in xrange(interrogate_function_number_of_python_wrappers(function)):
|
for i_wrapper in xrange(interrogate_function_number_of_python_wrappers(function)):
|
||||||
wrapper = interrogate_function_python_wrapper(function, i_wrapper)
|
wrapper = interrogate_function_python_wrapper(function, i_wrapper)
|
||||||
if interrogate_wrapper_has_comment(wrapper):
|
if interrogate_wrapper_has_comment(wrapper):
|
||||||
print >>handle, comment(interrogate_wrapper_comment(wrapper))
|
print >>handle, block_comment(interrogate_wrapper_comment(wrapper))
|
||||||
|
|
||||||
if not isConstructor:
|
if not isConstructor:
|
||||||
if not interrogate_wrapper_number_of_parameters(wrapper) > 0 or not interrogate_wrapper_parameter_is_this(wrapper, 0):
|
if not interrogate_wrapper_number_of_parameters(wrapper) > 0 or not interrogate_wrapper_parameter_is_this(wrapper, 0):
|
||||||
@ -114,11 +149,14 @@ def processType(handle, type):
|
|||||||
derivations = [ translated_type_name(interrogate_type_get_derivation(type, n)) for n in range(interrogate_type_number_of_derivations(type)) ]
|
derivations = [ translated_type_name(interrogate_type_get_derivation(type, n)) for n in range(interrogate_type_number_of_derivations(type)) ]
|
||||||
|
|
||||||
if interrogate_type_has_comment(type):
|
if interrogate_type_has_comment(type):
|
||||||
print >>handle, comment(interrogate_type_comment(type))
|
print >>handle, block_comment(interrogate_type_comment(type))
|
||||||
|
|
||||||
if interrogate_type_is_enum(type):
|
if interrogate_type_is_enum(type):
|
||||||
print >>handle, "enum %s {" % typename
|
print >>handle, "enum %s {" % typename
|
||||||
for i_value in range(interrogate_type_number_of_enum_values(type)):
|
for i_value in range(interrogate_type_number_of_enum_values(type)):
|
||||||
|
docstring = comment(interrogate_type_enum_value_comment(type, i_value))
|
||||||
|
if docstring:
|
||||||
|
print >>handle, docstring
|
||||||
print >>handle, translateFunctionName(interrogate_type_enum_value_name(type, i_value)), "=", interrogate_type_enum_value(type, i_value), ","
|
print >>handle, translateFunctionName(interrogate_type_enum_value_name(type, i_value)), "=", interrogate_type_enum_value(type, i_value), ","
|
||||||
else:
|
else:
|
||||||
if interrogate_type_is_struct(type):
|
if interrogate_type_is_struct(type):
|
||||||
@ -148,6 +186,9 @@ def processType(handle, type):
|
|||||||
|
|
||||||
for i_method in xrange(interrogate_type_number_of_make_seqs(type)):
|
for i_method in xrange(interrogate_type_number_of_make_seqs(type)):
|
||||||
print >>handle, "list", translateFunctionName(interrogate_make_seq_seq_name(interrogate_type_get_make_seq(type, i_method))), "();"
|
print >>handle, "list", translateFunctionName(interrogate_make_seq_seq_name(interrogate_type_get_make_seq(type, i_method))), "();"
|
||||||
|
|
||||||
|
for i_element in xrange(interrogate_type_number_of_elements(type)):
|
||||||
|
processElement(handle, interrogate_type_get_element(type, i_element))
|
||||||
|
|
||||||
print >>handle, "};"
|
print >>handle, "};"
|
||||||
|
|
||||||
@ -161,20 +202,22 @@ if __name__ == "__main__":
|
|||||||
interrogate_add_search_directory(os.path.join(os.path.dirname(pandac.__file__), "..", "..", "etc"))
|
interrogate_add_search_directory(os.path.join(os.path.dirname(pandac.__file__), "..", "..", "etc"))
|
||||||
interrogate_add_search_directory(os.path.join(os.path.dirname(pandac.__file__), "input"))
|
interrogate_add_search_directory(os.path.join(os.path.dirname(pandac.__file__), "input"))
|
||||||
|
|
||||||
try:
|
import panda3d.core
|
||||||
panda3d.__load__()
|
|
||||||
except ImportError, msg:
|
for lib in os.listdir(os.path.dirname(panda3d.__file__)):
|
||||||
print msg
|
if lib.endswith(('.pyd', '.so')) and not lib.startswith('core.'):
|
||||||
|
__import__('panda3d.' + os.path.splitext(lib)[0])
|
||||||
|
|
||||||
lastpkg = None
|
lastpkg = None
|
||||||
for i_type in xrange(interrogate_number_of_global_types()):
|
for i_type in xrange(interrogate_number_of_global_types()):
|
||||||
type = interrogate_get_global_type(i_type)
|
type = interrogate_get_global_type(i_type)
|
||||||
|
|
||||||
if interrogate_type_has_module_name(type):
|
if interrogate_type_has_module_name(type):
|
||||||
package = libraries[interrogate_type_module_name(type)]
|
package = interrogate_type_module_name(type)
|
||||||
if lastpkg != package:
|
if lastpkg != package:
|
||||||
print >>handle, "}"
|
if lastpkg is not None:
|
||||||
print >>handle, "namespace panda3d.%s {" % package
|
print >>handle, "}"
|
||||||
|
print >>handle, "namespace %s {" % package
|
||||||
lastpkg = package
|
lastpkg = package
|
||||||
|
|
||||||
processType(handle, type)
|
processType(handle, type)
|
||||||
@ -184,4 +227,3 @@ if __name__ == "__main__":
|
|||||||
if lastpkg is not None:
|
if lastpkg is not None:
|
||||||
print >>handle, "}"
|
print >>handle, "}"
|
||||||
handle.close()
|
handle.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user