Merged changes in the trunk up to revision 25613.
This commit is contained in:
@@ -129,7 +129,6 @@ extern "C" {
|
||||
// void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
|
||||
// void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
|
||||
// unsigned short event, short val, char ascii );
|
||||
// void BPY_clear_script( struct Script *script );
|
||||
// void BPY_free_finished_script( struct Script *script );
|
||||
// void BPY_scripts_clear_pyobjects( void );
|
||||
//
|
||||
|
||||
@@ -1,760 +0,0 @@
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Contributor(s): Campbell Barton
|
||||
#
|
||||
# #**** END GPL LICENSE BLOCK #****
|
||||
|
||||
script_help_msg = '''
|
||||
Usage,
|
||||
run this script from blenders root path once you have compiled blender
|
||||
./blender.bin -P source/blender/python/epy_doc_gen.py
|
||||
|
||||
This will generate python files in "./source/blender/python/doc/bpy"
|
||||
Generate html docs by running...
|
||||
|
||||
epydoc source/blender/python/doc/bpy/ -v \\
|
||||
-o source/blender/python/doc/html \\
|
||||
--inheritance=included \\
|
||||
--no-sourcecode \\
|
||||
--graph=classtree \\
|
||||
--graph-font-size=8
|
||||
|
||||
'''
|
||||
|
||||
# if you dont have graphvis installed ommit the --graph arg.
|
||||
|
||||
# GLOBALS['BASEDIR'] = './source/blender/python/doc'
|
||||
|
||||
import os
|
||||
|
||||
SUBMODULES = {}
|
||||
INIT_SUBMODULES = {} # store initialized files
|
||||
|
||||
INIT_SUBMODULES_IMPORTS = {} # dont import the same module twice
|
||||
|
||||
def append_package(package_path, mod_name):
|
||||
|
||||
init_path = os.path.join(os.path.dirname(package_path), "__init__.py")
|
||||
|
||||
# avoid double ups
|
||||
if mod_name:
|
||||
imports = INIT_SUBMODULES_IMPORTS.setdefault(init_path, [])
|
||||
if mod_name in imports:
|
||||
return
|
||||
imports.append(mod_name)
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(init_path)) # make the dirs if they are not there
|
||||
except:
|
||||
pass
|
||||
|
||||
# Open the new file for the first time, otherwise keep it open.
|
||||
f = INIT_SUBMODULES.get(init_path)
|
||||
if f == None:
|
||||
f = INIT_SUBMODULES[init_path] = open(init_path, 'w')
|
||||
|
||||
if mod_name:
|
||||
f.write("import %s\n" % mod_name)
|
||||
|
||||
return f
|
||||
|
||||
def append_package_recursive(package_path, BASEPATH):
|
||||
'''
|
||||
assume the last item of package_path will be a file (not a dir thats created)
|
||||
'''
|
||||
|
||||
package_path = os.path.splitext(package_path)[0] # incase of .py
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.join(BASEPATH, os.path.dirname(package_path))) # make the dirs if they are not there
|
||||
except:
|
||||
pass
|
||||
|
||||
new_path = BASEPATH
|
||||
|
||||
for mod_name in package_path.split(os.sep):
|
||||
init_path = os.path.join(new_path, "__init__.py")
|
||||
new_path = os.path.join(new_path, mod_name)
|
||||
append_package(init_path, mod_name)
|
||||
|
||||
|
||||
def open_submodule(subpath, BASEPATH):
|
||||
'''
|
||||
This is a utility function that lets us quickly add submodules
|
||||
'''
|
||||
|
||||
# create all the package paths leading up to this module
|
||||
append_package_recursive(subpath, BASEPATH)
|
||||
|
||||
module_name = os.path.basename( os.path.splitext(subpath)[0] )
|
||||
mod_path = os.path.join(BASEPATH, subpath)
|
||||
|
||||
# Open the new file for the first time, otherwise keep it open.
|
||||
f = SUBMODULES.get(mod_path)
|
||||
if f == None:
|
||||
f = SUBMODULES[mod_path] = open(mod_path, 'w')
|
||||
|
||||
f = open(mod_path, 'w')
|
||||
return f
|
||||
|
||||
def close_all():
|
||||
for files in (INIT_SUBMODULES.values(), SUBMODULES.values()):
|
||||
for f in files:
|
||||
if f.name.endswith('.py'):
|
||||
f_name = f.name
|
||||
f.close()
|
||||
|
||||
f = open(f_name, 'a')
|
||||
f.write("\ndel __package__\n") # annoying, no need do show this
|
||||
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
def range_str(val):
|
||||
if val < -10000000: return '-inf'
|
||||
if val > 10000000: return 'inf'
|
||||
if type(val)==float:
|
||||
return '%g' % val
|
||||
else:
|
||||
return str(val)
|
||||
|
||||
def get_array_str(length):
|
||||
if length > 0: return ' array of %d items' % length
|
||||
else: return ''
|
||||
|
||||
def full_rna_struct_path(rna_struct):
|
||||
'''
|
||||
Needed when referencing one struct from another
|
||||
'''
|
||||
nested = rna_struct.nested
|
||||
if nested:
|
||||
return "%s.%s" % (full_rna_struct_path(nested), rna_struct.identifier)
|
||||
else:
|
||||
return rna_struct.identifier
|
||||
|
||||
def rna_id_ignore(rna_id):
|
||||
if rna_id == "rna_type":
|
||||
return True
|
||||
|
||||
if "_OT_" in rna_id:
|
||||
return True
|
||||
if "_MT_" in rna_id:
|
||||
return True
|
||||
if "_PT_" in rna_id:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def write_func(rna, ident, out, func_type):
|
||||
# Keyword attributes
|
||||
kw_args = [] # "foo = 1", "bar=0.5", "spam='ENUM'"
|
||||
kw_arg_attrs = [] # "@type mode: int"
|
||||
|
||||
rna_struct= rna.rna_type
|
||||
|
||||
# Operators and functions work differently
|
||||
if func_type=='OPERATOR':
|
||||
rna_func_name = rna_struct.identifier.split("_OT_")[-1]
|
||||
rna_func_desc = rna_struct.description.strip()
|
||||
items = rna_struct.properties.items()
|
||||
else:
|
||||
rna_func_name = rna.identifier
|
||||
rna_func_desc = rna.description.strip()
|
||||
items = rna.parameters.items()
|
||||
|
||||
|
||||
for rna_prop_identifier, rna_prop in items:
|
||||
if rna_id_ignore(rna_prop_identifier):
|
||||
continue
|
||||
|
||||
# clear vars
|
||||
val = val_error = val_str = rna_prop_type = None
|
||||
|
||||
# ['rna_type', 'name', 'array_length', 'description', 'hard_max', 'hard_min', 'identifier', 'precision', 'readonly', 'soft_max', 'soft_min', 'step', 'subtype', 'type']
|
||||
#rna_prop= op_rna.rna_type.properties[attr]
|
||||
rna_prop_type = rna_prop.type.lower() # enum, float, int, boolean
|
||||
|
||||
|
||||
# only for rna functions, operators should not get pointers as args
|
||||
if rna_prop_type=='pointer':
|
||||
rna_prop_type_refine = "L{%s}" % rna_prop.fixed_type.identifier
|
||||
else:
|
||||
# Collections/Arrays can have a srna type
|
||||
rna_prop_srna_type = rna_prop.srna
|
||||
if rna_prop_srna_type:
|
||||
print(rna_prop_srna_type.identifier)
|
||||
rna_prop_type_refine = "L{%s}" % rna_prop_srna_type.identifier
|
||||
else:
|
||||
rna_prop_type_refine = rna_prop_type
|
||||
|
||||
del rna_prop_srna_type
|
||||
|
||||
|
||||
try: length = rna_prop.array_length
|
||||
except: length = 0
|
||||
|
||||
array_str = get_array_str(length)
|
||||
|
||||
if rna_prop.use_return:
|
||||
kw_type_str= "@rtype: %s%s" % (rna_prop_type_refine, array_str)
|
||||
kw_param_str= "@return: %s" % (rna_prop.description.strip())
|
||||
else:
|
||||
kw_type_str= "@type %s: %s%s" % (rna_prop_identifier, rna_prop_type_refine, array_str)
|
||||
kw_param_str= "@param %s: %s" % (rna_prop_identifier, rna_prop.description.strip())
|
||||
|
||||
kw_param_set = False
|
||||
|
||||
if func_type=='OPERATOR':
|
||||
try:
|
||||
val = getattr(rna, rna_prop_identifier)
|
||||
val_error = False
|
||||
except:
|
||||
val = "'<UNDEFINED>'"
|
||||
val_error = True
|
||||
|
||||
|
||||
if val_error:
|
||||
val_str = val
|
||||
elif rna_prop_type=='float':
|
||||
if length==0:
|
||||
val_str= '%g' % val
|
||||
if '.' not in val_str and '-' not in val_str: # value could be 1e-05
|
||||
val_str += '.0'
|
||||
else:
|
||||
# array
|
||||
val_str = str(tuple(val))
|
||||
|
||||
kw_param_str += (' in (%s, %s)' % (range_str(rna_prop.hard_min), range_str(rna_prop.hard_max)))
|
||||
kw_param_set= True
|
||||
|
||||
elif rna_prop_type=='int':
|
||||
if length==0:
|
||||
val_str='%d' % val
|
||||
else:
|
||||
val_str = str(tuple(val))
|
||||
|
||||
# print(dir(rna_prop))
|
||||
kw_param_str += (' in (%s, %s)' % (range_str(rna_prop.hard_min), range_str(rna_prop.hard_max)))
|
||||
# These strings dont have a max length???
|
||||
#kw_param_str += ' (maximum length of %s)' % (rna_prop.max_length)
|
||||
kw_param_set= True
|
||||
|
||||
elif rna_prop_type=='boolean':
|
||||
if length==0:
|
||||
if val: val_str='True'
|
||||
else: val_str='False'
|
||||
else:
|
||||
val_str = str(tuple(val))
|
||||
|
||||
elif rna_prop_type=='enum':
|
||||
# no array here?
|
||||
val_str="'%s'" % val
|
||||
# Too cramped
|
||||
kw_param_str += (' in (%s)' % ', '.join(rna_prop.items.keys()))
|
||||
|
||||
kw_param_set= True
|
||||
|
||||
elif rna_prop_type=='string':
|
||||
# no array here?
|
||||
val_str='"%s"' % val
|
||||
|
||||
# todo - collection - array
|
||||
# print (rna_prop.type)
|
||||
|
||||
kw_args.append('%s = %s' % (rna_prop_identifier, val_str))
|
||||
|
||||
# stora
|
||||
else:
|
||||
# currently functions dont have a default value
|
||||
if not rna_prop.use_return:
|
||||
kw_args.append('%s' % (rna_prop_identifier))
|
||||
else:
|
||||
kw_param_set = True
|
||||
|
||||
|
||||
# Same for operators and functions
|
||||
kw_arg_attrs.append(kw_type_str)
|
||||
if kw_param_set:
|
||||
kw_arg_attrs.append(kw_param_str)
|
||||
|
||||
|
||||
|
||||
out.write(ident+'def %s(%s):\n' % (rna_func_name, ', '.join(kw_args)))
|
||||
out.write(ident+'\t"""\n')
|
||||
|
||||
# Descriptions could be multiline
|
||||
for rna_func_desc_line in rna_func_desc.split('\n'):
|
||||
out.write(ident+'\t%s\n' % rna_func_desc_line.strip())
|
||||
|
||||
for desc in kw_arg_attrs:
|
||||
out.write(ident+'\t%s\n' % desc)
|
||||
|
||||
# out.write(ident+'\t@rtype: None\n') # implicit
|
||||
out.write(ident+'\t"""\n')
|
||||
|
||||
|
||||
|
||||
def rna2epy(BASEPATH):
|
||||
|
||||
# Use for faster lookups
|
||||
# use rna_struct.identifier as the key for each dict
|
||||
rna_struct_dict = {} # store identifier:rna lookups
|
||||
rna_full_path_dict = {} # store the result of full_rna_struct_path(rna_struct)
|
||||
rna_children_dict = {} # store all rna_structs nested from here
|
||||
rna_references_dict = {} # store a list of rna path strings that reference this type
|
||||
rna_functions_dict = {} # store all functions directly in this type (not inherited)
|
||||
rna_words = set()
|
||||
|
||||
# def write_func(rna_func, ident):
|
||||
|
||||
|
||||
def write_struct(rna_struct, ident):
|
||||
identifier = rna_struct.identifier
|
||||
|
||||
rna_base = rna_struct.base
|
||||
|
||||
if rna_base:
|
||||
out.write(ident+ 'class %s(%s):\n' % (identifier, rna_base.identifier))
|
||||
rna_base_prop_keys = rna_base.properties.keys() # could be cached
|
||||
rna_base_func_keys = [f.identifier for f in rna_base.functions]
|
||||
else:
|
||||
out.write(ident+ 'class %s:\n' % identifier)
|
||||
rna_base_prop_keys = []
|
||||
rna_base_func_keys = []
|
||||
|
||||
out.write(ident+ '\t"""\n')
|
||||
|
||||
title = 'The %s Object' % rna_struct.name
|
||||
description = rna_struct.description.strip()
|
||||
out.write(ident+ '\t%s\n' % title)
|
||||
out.write(ident+ '\t%s\n' % ('=' * len(title)))
|
||||
out.write(ident+ '\t\t%s\n' % description)
|
||||
rna_words.update(description.split())
|
||||
|
||||
|
||||
# For convenience, give a list of all places were used.
|
||||
rna_refs= rna_references_dict[identifier]
|
||||
|
||||
if rna_refs:
|
||||
out.write(ident+ '\t\t\n')
|
||||
out.write(ident+ '\t\tReferences\n')
|
||||
out.write(ident+ '\t\t==========\n')
|
||||
|
||||
for rna_ref_string in rna_refs:
|
||||
out.write(ident+ '\t\t\t- L{%s}\n' % rna_ref_string)
|
||||
|
||||
out.write(ident+ '\t\t\n')
|
||||
|
||||
else:
|
||||
out.write(ident+ '\t\t\n')
|
||||
out.write(ident+ '\t\t(no references to this struct found)\n')
|
||||
out.write(ident+ '\t\t\n')
|
||||
|
||||
for rna_prop_identifier, rna_prop in rna_struct.properties.items():
|
||||
|
||||
if rna_prop_identifier=='RNA': continue
|
||||
if rna_id_ignore(rna_prop_identifier): continue
|
||||
if rna_prop_identifier in rna_base_prop_keys: continue # does this prop exist in our parent class, if so skip
|
||||
|
||||
rna_desc = rna_prop.description.strip()
|
||||
|
||||
if rna_desc: rna_words.update(rna_desc.split())
|
||||
if not rna_desc: rna_desc = rna_prop.name
|
||||
if not rna_desc: rna_desc = 'Note - No documentation for this property!'
|
||||
|
||||
rna_prop_type = rna_prop.type.lower()
|
||||
|
||||
if rna_prop_type=='collection': collection_str = 'Collection of '
|
||||
else: collection_str = ''
|
||||
|
||||
# some collections have a srna for their own properties
|
||||
# TODO - arrays, however this isnt used yet
|
||||
rna_prop_srna_type = rna_prop.srna
|
||||
if rna_prop_srna_type:
|
||||
collection_str = "L{%s} %s" % (rna_prop_srna_type.identifier, collection_str)
|
||||
del rna_prop_srna_type
|
||||
|
||||
try: rna_prop_ptr = rna_prop.fixed_type
|
||||
except: rna_prop_ptr = None
|
||||
|
||||
try: length = rna_prop.array_length
|
||||
except: length = 0
|
||||
|
||||
array_str = get_array_str(length)
|
||||
|
||||
if rna_prop.editable: readonly_str = ''
|
||||
else: readonly_str = ' (readonly)'
|
||||
|
||||
if rna_prop_ptr: # Use the pointer type
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %sL{%s}%s%s\n' % (rna_prop_identifier, collection_str, rna_prop_ptr.identifier, array_str, readonly_str))
|
||||
else:
|
||||
if rna_prop_type == 'enum':
|
||||
if 0:
|
||||
out.write(ident+ '\t@ivar %s: %s in (%s)\n' % (rna_prop_identifier, rna_desc, ', '.join(rna_prop.items.keys())))
|
||||
else:
|
||||
out.write(ident+ '\t@ivar %s: %s in...\n' % (rna_prop_identifier, rna_desc))
|
||||
for e, e_rna_prop in rna_prop.items.items():
|
||||
#out.write(ident+ '\t\t- %s: %s\n' % (e, e_rna_prop.description)) # XXX - segfaults, FIXME
|
||||
out.write(ident+ '\t\t- %s\n' % e)
|
||||
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
elif rna_prop_type == 'int' or rna_prop_type == 'float':
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %s%s%s in [%s, %s]\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str, range_str(rna_prop.hard_min), range_str(rna_prop.hard_max) ))
|
||||
elif rna_prop_type == 'string':
|
||||
out.write(ident+ '\t@ivar %s: %s (maximum length of %s)\n' % (rna_prop_identifier, rna_desc, rna_prop.max_length))
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
else:
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
|
||||
|
||||
out.write(ident+ '\t"""\n\n')
|
||||
|
||||
|
||||
# Write functions
|
||||
# for rna_func in rna_struct.functions: # Better ignore inherited (line below)
|
||||
for rna_func in rna_functions_dict[identifier]:
|
||||
if rna_func not in rna_base_func_keys:
|
||||
write_func(rna_func, ident+'\t', out, 'FUNCTION')
|
||||
|
||||
out.write('\n')
|
||||
|
||||
# Now write children recursively
|
||||
for child in rna_children_dict[identifier]:
|
||||
write_struct(child, ident + '\t')
|
||||
|
||||
|
||||
|
||||
# out = open(target_path, 'w')
|
||||
out = open_submodule("types.py", BASEPATH) # bpy.types
|
||||
|
||||
def base_id(rna_struct):
|
||||
try: return rna_struct.base.identifier
|
||||
except: return '' # invalid id
|
||||
|
||||
#structs = [(base_id(rna_struct), rna_struct.identifier, rna_struct) for rna_struct in bpy.doc.structs.values()]
|
||||
'''
|
||||
structs = []
|
||||
for rna_struct in bpy.doc.structs.values():
|
||||
structs.append( (base_id(rna_struct), rna_struct.identifier, rna_struct) )
|
||||
'''
|
||||
structs = []
|
||||
for rna_type_name in dir(bpy.types):
|
||||
rna_type = getattr(bpy.types, rna_type_name)
|
||||
|
||||
try: rna_struct = rna_type.bl_rna
|
||||
except: rna_struct = None
|
||||
|
||||
if rna_struct:
|
||||
#if not rna_type_name.startswith('__'):
|
||||
|
||||
identifier = rna_struct.identifier
|
||||
|
||||
if not rna_id_ignore(identifier):
|
||||
structs.append( (base_id(rna_struct), identifier, rna_struct) )
|
||||
|
||||
# Simple lookup
|
||||
rna_struct_dict[identifier] = rna_struct
|
||||
|
||||
# Store full rna path 'GameObjectSettings' -> 'Object.GameObjectSettings'
|
||||
rna_full_path_dict[identifier] = full_rna_struct_path(rna_struct)
|
||||
|
||||
# Store a list of functions, remove inherited later
|
||||
rna_functions_dict[identifier]= list(rna_struct.functions)
|
||||
|
||||
|
||||
# fill in these later
|
||||
rna_children_dict[identifier]= []
|
||||
rna_references_dict[identifier]= []
|
||||
|
||||
|
||||
else:
|
||||
print("Ignoring", rna_type_name)
|
||||
|
||||
|
||||
# Sucks but we need to copy this so we can check original parent functions
|
||||
rna_functions_dict__copy = {}
|
||||
for key, val in rna_functions_dict.items():
|
||||
rna_functions_dict__copy[key] = val[:]
|
||||
|
||||
|
||||
structs.sort() # not needed but speeds up sort below, setting items without an inheritance first
|
||||
|
||||
# Arrange so classes are always defined in the correct order
|
||||
deps_ok = False
|
||||
while deps_ok == False:
|
||||
deps_ok = True
|
||||
rna_done = set()
|
||||
|
||||
for i, (rna_base, identifier, rna_struct) in enumerate(structs):
|
||||
|
||||
rna_done.add(identifier)
|
||||
|
||||
if rna_base and rna_base not in rna_done:
|
||||
deps_ok = False
|
||||
data = structs.pop(i)
|
||||
ok = False
|
||||
while i < len(structs):
|
||||
if structs[i][1]==rna_base:
|
||||
structs.insert(i+1, data) # insert after the item we depend on.
|
||||
ok = True
|
||||
break
|
||||
i+=1
|
||||
|
||||
if not ok:
|
||||
print('Dependancy "%s" could not be found for "%s"' % (identifier, rna_base))
|
||||
|
||||
break
|
||||
|
||||
# Done ordering structs
|
||||
|
||||
|
||||
# precalc vars to avoid a lot of looping
|
||||
for (rna_base, identifier, rna_struct) in structs:
|
||||
|
||||
if rna_base:
|
||||
rna_base_prop_keys = rna_struct_dict[rna_base].properties.keys() # could cache
|
||||
rna_base_func_keys = [f.identifier for f in rna_struct_dict[rna_base].functions]
|
||||
else:
|
||||
rna_base_prop_keys = []
|
||||
rna_base_func_keys= []
|
||||
|
||||
# rna_struct_path = full_rna_struct_path(rna_struct)
|
||||
rna_struct_path = rna_full_path_dict[identifier]
|
||||
|
||||
for rna_prop_identifier, rna_prop in rna_struct.properties.items():
|
||||
|
||||
if rna_prop_identifier=='RNA': continue
|
||||
if rna_id_ignore(rna_prop_identifier): continue
|
||||
if rna_prop_identifier in rna_base_prop_keys: continue
|
||||
|
||||
|
||||
for rna_prop_ptr in (getattr(rna_prop, "fixed_type", None), getattr(rna_prop, "srna", None)):
|
||||
# Does this property point to me?
|
||||
if rna_prop_ptr:
|
||||
rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_prop_identifier) )
|
||||
|
||||
for rna_func in rna_struct.functions:
|
||||
for rna_prop_identifier, rna_prop in rna_func.parameters.items():
|
||||
|
||||
if rna_prop_identifier=='RNA': continue
|
||||
if rna_id_ignore(rna_prop_identifier): continue
|
||||
if rna_prop_identifier in rna_base_func_keys: continue
|
||||
|
||||
|
||||
try: rna_prop_ptr = rna_prop.fixed_type
|
||||
except: rna_prop_ptr = None
|
||||
|
||||
# Does this property point to me?
|
||||
if rna_prop_ptr:
|
||||
rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_func.identifier) )
|
||||
|
||||
|
||||
# Store nested children
|
||||
nested = rna_struct.nested
|
||||
if nested:
|
||||
rna_children_dict[nested.identifier].append(rna_struct)
|
||||
|
||||
|
||||
if rna_base:
|
||||
rna_funcs = rna_functions_dict[identifier]
|
||||
if rna_funcs:
|
||||
# Remove inherited functions if we have any
|
||||
rna_base_funcs = rna_functions_dict__copy[rna_base]
|
||||
rna_funcs[:] = [f for f in rna_funcs if f not in rna_base_funcs]
|
||||
|
||||
rna_functions_dict__copy.clear()
|
||||
del rna_functions_dict__copy
|
||||
|
||||
# Sort the refs, just reads nicer
|
||||
for rna_refs in rna_references_dict.values():
|
||||
rna_refs.sort()
|
||||
|
||||
for (rna_base, identifier, rna_struct) in structs:
|
||||
if rna_struct.nested:
|
||||
continue
|
||||
|
||||
write_struct(rna_struct, '')
|
||||
|
||||
|
||||
out.write('\n')
|
||||
out.close()
|
||||
|
||||
# # We could also just run....
|
||||
# os.system('epydoc source/blender/python/doc/rna.py -o ./source/blender/python/doc/html -v')
|
||||
|
||||
target_path = os.path.join(BASEPATH, "dump.py") # XXX - used for other funcs
|
||||
|
||||
# Write graphviz
|
||||
out= open(target_path.replace('.py', '.dot'), 'w')
|
||||
out.write('digraph "rna data api" {\n')
|
||||
out.write('\tnode [style=filled, shape = "box"];\n')
|
||||
out.write('\toverlap=false;\n')
|
||||
out.write('\trankdir = LR;\n')
|
||||
out.write('\tsplines=true;\n')
|
||||
out.write('\tratio=auto;\n')
|
||||
|
||||
|
||||
|
||||
out.write('\tsize="10,10"\n')
|
||||
#out.write('\tpage="8.5,11"\n')
|
||||
#out.write('\tcenter=""\n')
|
||||
|
||||
def isop(rna_struct):
|
||||
return '_OT_' in rna_struct.identifier
|
||||
|
||||
|
||||
for (rna_base, identifier, rna_struct) in structs:
|
||||
if isop(rna_struct):
|
||||
continue
|
||||
|
||||
base = rna_struct.base
|
||||
|
||||
|
||||
out.write('\t"%s";\n' % identifier)
|
||||
|
||||
for (rna_base, identifier, rna_struct) in structs:
|
||||
|
||||
if isop(rna_struct):
|
||||
continue
|
||||
|
||||
base = rna_struct.base
|
||||
|
||||
if base and not isop(base):
|
||||
out.write('\t"%s" -> "%s" [label="(base)" weight=1.0];\n' % (base.identifier, identifier))
|
||||
|
||||
nested = rna_struct.nested
|
||||
if nested and not isop(nested):
|
||||
out.write('\t"%s" -> "%s" [label="(nested)" weight=1.0];\n' % (nested.identifier, identifier))
|
||||
|
||||
|
||||
|
||||
rna_refs= rna_references_dict[identifier]
|
||||
|
||||
for rna_ref_string in rna_refs:
|
||||
|
||||
if '_OT_' in rna_ref_string:
|
||||
continue
|
||||
|
||||
ref = rna_ref_string.split('.')[-2]
|
||||
out.write('\t"%s" -> "%s" [label="%s" weight=0.01];\n' % (ref, identifier, rna_ref_string))
|
||||
|
||||
|
||||
out.write('}\n')
|
||||
out.close()
|
||||
|
||||
# # We could also just run....
|
||||
# os.system('dot source/blender/python/doc/rna.dot -Tsvg -o ./source/blender/python/doc/rna.svg')
|
||||
|
||||
|
||||
out= open(target_path.replace('.py', '.words'), 'w')
|
||||
rna_words = list(rna_words)
|
||||
rna_words.sort()
|
||||
for w in rna_words:
|
||||
out.write('%s\n' % w)
|
||||
|
||||
|
||||
def op2epy(BASEPATH):
|
||||
# out = open(target_path, 'w')
|
||||
|
||||
op_mods = dir(bpy.ops)
|
||||
op_mods.remove('add')
|
||||
op_mods.remove('remove')
|
||||
|
||||
for op_mod_name in sorted(op_mods):
|
||||
if op_mod_name.startswith('__'):
|
||||
continue
|
||||
|
||||
# open the submodule
|
||||
mod_path = os.path.join("ops", op_mod_name + ".py")
|
||||
out = open_submodule(mod_path, BASEPATH)
|
||||
|
||||
|
||||
op_mod = getattr(bpy.ops, op_mod_name)
|
||||
operators = dir(op_mod)
|
||||
for op in sorted(operators):
|
||||
# rna = getattr(bpy.types, op).bl_rna
|
||||
try:
|
||||
rna = getattr(op_mod, op).get_rna()
|
||||
except AttributeError:
|
||||
rna = None
|
||||
except TypeError:
|
||||
rna = None
|
||||
|
||||
if rna:
|
||||
write_func(rna, '', out, 'OPERATOR')
|
||||
|
||||
out.write('\n')
|
||||
out.close()
|
||||
|
||||
def misc2epy(BASEPATH):
|
||||
'''
|
||||
Hard coded modules, try to avoid adding stuff here
|
||||
'''
|
||||
|
||||
f = append_package(os.path.join(BASEPATH, ""), ""); # add a slash on the end of the base path
|
||||
f.write('''
|
||||
"""
|
||||
@type data: L{bpy.types.Main}
|
||||
@var data: blender data is accessed from here
|
||||
"""
|
||||
''')
|
||||
|
||||
f = open_submodule("props.py", BASEPATH)
|
||||
f.write('''
|
||||
MAX_INT= 2**31
|
||||
MAX_FLOAT= 1e+37
|
||||
def BoolProperty(attr, name="", description="", default=False):
|
||||
"""
|
||||
return a new bool property
|
||||
"""
|
||||
def IntProperty(attr, name="", description="", min=-MAX_INT, max=MAX_INT, soft_min=-MAX_INT, soft_max=MAX_INT, default=0):
|
||||
"""
|
||||
return a new int property
|
||||
"""
|
||||
def FloatProperty(attr, name="", description="", min=-MAX_FLOAT, max=MAX_FLOAT, soft_min=-MAX_FLOAT, soft_max=MAX_FLOAT, default=0.0):
|
||||
"""
|
||||
return a new float property
|
||||
"""
|
||||
def StringProperty(attr, name="", description="", maxlen=0, default=""):
|
||||
"""
|
||||
return a new string property
|
||||
"""
|
||||
def EnumProperty(attr, items, name="", description="", default=""):
|
||||
"""
|
||||
return a new enum property
|
||||
"""
|
||||
''')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if 'bpy' not in dir():
|
||||
print("\nError, this script must run from inside blender2.5")
|
||||
print(script_help_msg)
|
||||
else:
|
||||
misc2epy('source/blender/python/doc/bpy') # first to write in info in some of the modules.
|
||||
rna2epy('source/blender/python/doc/bpy')
|
||||
op2epy('source/blender/python/doc/bpy')
|
||||
|
||||
|
||||
close_all()
|
||||
|
||||
import sys
|
||||
sys.exit()
|
||||
@@ -55,6 +55,7 @@ static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args
|
||||
static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Geometry_BarycentricTransform( PyObject * self, PyObject * args );
|
||||
|
||||
|
||||
/*-------------------------DOC STRINGS ---------------------------*/
|
||||
@@ -75,6 +76,7 @@ struct PyMethodDef M_Geometry_methods[] = {
|
||||
{"PointInQuad2D", ( PyCFunction ) M_Geometry_PointInQuad2D, METH_VARARGS, M_Geometry_PointInQuad2D_doc},
|
||||
{"BoxPack2D", ( PyCFunction ) M_Geometry_BoxPack2D, METH_O, M_Geometry_BoxPack2D_doc},
|
||||
{"BezierInterp", ( PyCFunction ) M_Geometry_BezierInterp, METH_VARARGS, M_Geometry_BezierInterp_doc},
|
||||
{"BarycentricTransform", ( PyCFunction ) M_Geometry_BarycentricTransform, METH_VARARGS, NULL},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -534,3 +536,36 @@ static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args )
|
||||
MEM_freeN(coord_array);
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyObject *M_Geometry_BarycentricTransform(PyObject * self, PyObject * args)
|
||||
{
|
||||
VectorObject *vec_pt;
|
||||
VectorObject *vec_t1_tar, *vec_t2_tar, *vec_t3_tar;
|
||||
VectorObject *vec_t1_src, *vec_t2_src, *vec_t3_src;
|
||||
float vec[3];
|
||||
|
||||
if( !PyArg_ParseTuple ( args, "O!O!O!O!O!O!O!",
|
||||
&vector_Type, &vec_pt,
|
||||
&vector_Type, &vec_t1_src,
|
||||
&vector_Type, &vec_t2_src,
|
||||
&vector_Type, &vec_t3_src,
|
||||
&vector_Type, &vec_t1_tar,
|
||||
&vector_Type, &vec_t2_tar,
|
||||
&vector_Type, &vec_t3_tar) || ( vec_pt->size != 3 ||
|
||||
vec_t1_src->size != 3 ||
|
||||
vec_t2_src->size != 3 ||
|
||||
vec_t3_src->size != 3 ||
|
||||
vec_t1_tar->size != 3 ||
|
||||
vec_t2_tar->size != 3 ||
|
||||
vec_t3_tar->size != 3)
|
||||
) {
|
||||
PyErr_SetString( PyExc_TypeError, "expected 7, 3D vector types\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
barycentric_transform(vec, vec_pt->vec,
|
||||
vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec,
|
||||
vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec);
|
||||
|
||||
return newVectorObject(vec, 3, Py_NEW, NULL);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "BKE_text.h" /* txt_to_buf */
|
||||
#include "BKE_main.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static Main *bpy_import_main= NULL;
|
||||
|
||||
@@ -100,10 +102,7 @@ PyObject *bpy_text_import_name( char *name, int *found )
|
||||
memcpy( txtname, name, namelen );
|
||||
memcpy( &txtname[namelen], ".py", 4 );
|
||||
|
||||
for(text = maggie->text.first; text; text = text->id.next) {
|
||||
if( !strcmp( txtname, text->id.name+2 ) )
|
||||
break;
|
||||
}
|
||||
text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
|
||||
|
||||
if( !text )
|
||||
return NULL;
|
||||
@@ -142,12 +141,7 @@ PyObject *bpy_text_reimport( PyObject *module, int *found )
|
||||
return NULL;
|
||||
|
||||
/* look up the text object */
|
||||
text = ( Text * ) & ( maggie->text.first );
|
||||
while( text ) {
|
||||
if( !strcmp( txtname, text->id.name+2 ) )
|
||||
break;
|
||||
text = text->id.next;
|
||||
}
|
||||
text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
|
||||
|
||||
/* uh-oh.... didn't find it */
|
||||
if( !text )
|
||||
|
||||
@@ -1136,7 +1136,7 @@ static PyGetSetDef Matrix_getseters[] = {
|
||||
{"rowSize", (getter)Matrix_getRowSize, (setter)NULL, "", NULL},
|
||||
{"colSize", (getter)Matrix_getColSize, (setter)NULL, "", NULL},
|
||||
{"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, "", NULL},
|
||||
{"__owner__",(getter)BaseMathObject_getOwner, (setter)NULL, "",
|
||||
{"_owner",(getter)BaseMathObject_getOwner, (setter)NULL, "",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "BKE_blender.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_context.h"
|
||||
@@ -223,6 +224,16 @@ static void bpy_init_modules( void )
|
||||
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
|
||||
}
|
||||
|
||||
/* blender info that wont change at runtime, add into _bpy */
|
||||
{
|
||||
PyObject *mod_dict= PyModule_GetDict(mod);
|
||||
char tmpstr[256];
|
||||
PyModule_AddStringConstant(mod, "_HOME", BLI_gethome());
|
||||
PyDict_SetItemString(mod_dict, "_VERSION", Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
|
||||
sprintf(tmpstr, "%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
|
||||
PyModule_AddStringConstant(mod, "_VERSION_STR", tmpstr);
|
||||
}
|
||||
|
||||
/* add our own modules dir, this is a python package */
|
||||
bpy_import_test("bpy");
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
ot= WM_operatortype_exists(opname);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator \"%s\"could not be found", opname);
|
||||
PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator \"%s\" could not be found", opname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ PyObject *BPY_operator_module( void )
|
||||
static PyMethodDef pyop_as_string_meth ={"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL};
|
||||
static PyMethodDef pyop_dir_meth = {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL};
|
||||
static PyMethodDef pyop_getrna_meth = {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL};
|
||||
static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
|
||||
// static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
|
||||
static PyMethodDef pyop_add_macro_meth ={"add_macro", (PyCFunction) PYOP_wrap_add_macro, METH_O, NULL};
|
||||
static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL};
|
||||
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
|
||||
@@ -256,7 +256,7 @@ PyObject *BPY_operator_module( void )
|
||||
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
|
||||
PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) );
|
||||
// PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "add_macro", PyCFunction_New(&pyop_add_macro_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "macro_define",PyCFunction_New(&pyop_macro_def_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "remove", PyCFunction_New(&pyop_remove_meth, NULL) );
|
||||
|
||||
@@ -105,7 +105,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
|
||||
py_class_instance = PyObject_Call(py_class, args, NULL);
|
||||
Py_DECREF(args);
|
||||
|
||||
|
||||
if (py_class_instance==NULL) { /* Initializing the class worked, now run its invoke function */
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
@@ -128,7 +128,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
else if (mode==PYOP_EXEC) {
|
||||
item= PyObject_GetAttrString(py_class, "execute");
|
||||
args = PyTuple_New(2);
|
||||
|
||||
|
||||
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
||||
}
|
||||
else if (mode==PYOP_POLL) {
|
||||
@@ -173,7 +173,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
Py_DECREF(args);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
|
||||
if (ret == NULL) { /* covers py_class_instance failing too */
|
||||
if(op)
|
||||
BPy_errors_to_report(op->reports);
|
||||
@@ -202,7 +202,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
* If we ever want to do this and use the props again,
|
||||
* it can be done with - pyrna_pydict_to_props(op->ptr, kw, "")
|
||||
*/
|
||||
|
||||
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
BPY_flag_def *flag_def = pyop_ret_flags;
|
||||
|
||||
strcpy(flag_str, "");
|
||||
|
||||
|
||||
while(flag_def->name) {
|
||||
if (ret_flag & flag_def->flag) {
|
||||
if(flag_str[1])
|
||||
@@ -260,6 +260,49 @@ static void PYTHON_OT_draw(bContext *C, wmOperator *op, uiLayout *layout)
|
||||
PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, layout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void operator_wrapper(wmOperatorType *ot, void *userdata)
|
||||
{
|
||||
/* take care not to overwrite anything set in
|
||||
* WM_operatortype_append_ptr before opfunc() is called */
|
||||
StructRNA *srna = ot->srna;
|
||||
*ot= *((wmOperatorType *)userdata);
|
||||
ot->srna= srna; /* restore */
|
||||
|
||||
RNA_struct_blender_type_set(ot->ext.srna, ot);
|
||||
|
||||
|
||||
/* Can't use this because it returns a dict proxy
|
||||
*
|
||||
* item= PyObject_GetAttrString(py_class, "__dict__");
|
||||
*/
|
||||
{
|
||||
PyObject *py_class = ot->ext.data;
|
||||
PyObject *item= ((PyTypeObject*)py_class)->tp_dict;
|
||||
if(item) {
|
||||
/* only call this so pyrna_deferred_register_props gives a useful error
|
||||
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
||||
* later */
|
||||
RNA_def_struct_identifier(ot->srna, ot->idname);
|
||||
|
||||
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
|
||||
/* failed to register operator props */
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
{
|
||||
PyObject *py_class = (PyObject *)userdata;
|
||||
@@ -283,8 +326,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
|
||||
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"undocumented python operator";
|
||||
Py_XDECREF(item);
|
||||
|
||||
/* api callbacks, detailed checks dont on adding */
|
||||
|
||||
/* api callbacks, detailed checks dont on adding */
|
||||
if (PyObject_HasAttrString(py_class, "invoke"))
|
||||
ot->invoke= PYTHON_OT_invoke;
|
||||
//else
|
||||
@@ -296,9 +339,9 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
ot->pyop_poll= PYTHON_OT_poll;
|
||||
if (PyObject_HasAttrString(py_class, "draw"))
|
||||
ot->ui= PYTHON_OT_draw;
|
||||
|
||||
|
||||
ot->pyop_data= userdata;
|
||||
|
||||
|
||||
/* flags */
|
||||
ot->flag= 0;
|
||||
|
||||
@@ -419,11 +462,11 @@ void PYTHON_OT_MACRO_wrapper(wmOperatorType *ot, void *userdata)
|
||||
|
||||
/* pyOperators - Operators defined IN Python */
|
||||
PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
{
|
||||
{
|
||||
PyObject *base_class, *item;
|
||||
wmOperatorType *ot;
|
||||
|
||||
|
||||
|
||||
|
||||
char *idname= NULL;
|
||||
char idname_bl[OP_MAX_TYPENAME]; /* converted to blender syntax */
|
||||
|
||||
@@ -466,7 +509,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
Py_DECREF(item);
|
||||
/* end annoying conversion! */
|
||||
|
||||
|
||||
|
||||
/* remove if it already exists */
|
||||
if ((ot=WM_operatortype_exists(idname))) {
|
||||
if(ot->pyop_data) {
|
||||
@@ -474,7 +517,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
}
|
||||
WM_operatortype_remove(idname);
|
||||
}
|
||||
|
||||
|
||||
Py_INCREF(py_class);
|
||||
WM_operatortype_append_ptr(PYTHON_OT_wrapper, py_class);
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
#ifdef USE_MATHUTILS
|
||||
int subtype, totdim;
|
||||
int len;
|
||||
int is_thick;
|
||||
|
||||
/* disallow dynamic sized arrays to be wrapped since the size could change
|
||||
* to a size mathutils does not support */
|
||||
@@ -154,9 +155,11 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
len= RNA_property_array_length(ptr, prop);
|
||||
subtype= RNA_property_subtype(prop);
|
||||
totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
is_thick = (RNA_property_flag(prop) & PROP_THICK_WRAP);
|
||||
|
||||
if (totdim == 1 || (totdim == 2 && subtype == PROP_MATRIX)) {
|
||||
ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the Mathutils PyObject */
|
||||
if(!is_thick)
|
||||
ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the Mathutils PyObject */
|
||||
|
||||
switch(RNA_property_subtype(prop)) {
|
||||
case PROP_TRANSLATION:
|
||||
@@ -166,40 +169,74 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
case PROP_XYZ:
|
||||
case PROP_XYZ|PROP_UNIT_LENGTH:
|
||||
if(len>=2 && len <= 4) {
|
||||
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the vector owns now */
|
||||
ret= vec_cb; /* return the vector instead */
|
||||
if(is_thick) {
|
||||
ret= newVectorObject(NULL, len, Py_NEW, NULL);
|
||||
RNA_property_float_get_array(ptr, prop, ((VectorObject *)ret)->vec);
|
||||
}
|
||||
else {
|
||||
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the vector owns now */
|
||||
ret= vec_cb; /* return the vector instead */
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PROP_MATRIX:
|
||||
if(len==16) {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
if(is_thick) {
|
||||
ret= newMatrixObject(NULL, 4, 4, Py_NEW, NULL);
|
||||
RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr);
|
||||
}
|
||||
else {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
}
|
||||
}
|
||||
else if (len==9) {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
if(is_thick) {
|
||||
ret= newMatrixObject(NULL, 3, 3, Py_NEW, NULL);
|
||||
RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr);
|
||||
}
|
||||
else {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PROP_EULER:
|
||||
case PROP_QUATERNION:
|
||||
if(len==3) { /* euler */
|
||||
PyObject *eul_cb= newEulerObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= eul_cb; /* return the matrix instead */
|
||||
if(is_thick) {
|
||||
ret= newEulerObject(NULL, Py_NEW, NULL);
|
||||
RNA_property_float_get_array(ptr, prop, ((EulerObject *)ret)->eul);
|
||||
}
|
||||
else {
|
||||
PyObject *eul_cb= newEulerObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= eul_cb; /* return the matrix instead */
|
||||
}
|
||||
}
|
||||
else if (len==4) {
|
||||
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= quat_cb; /* return the matrix instead */
|
||||
if(is_thick) {
|
||||
ret= newQuaternionObject(NULL, Py_NEW, NULL);
|
||||
RNA_property_float_get_array(ptr, prop, ((QuaternionObject *)ret)->quat);
|
||||
}
|
||||
else {
|
||||
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= quat_cb; /* return the matrix instead */
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret==NULL)
|
||||
ret = pyrna_prop_CreatePyObject(ptr, prop); /* TODO, convert to a python list */
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
@@ -1204,7 +1241,7 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
|
||||
return -1;
|
||||
}
|
||||
@@ -1258,7 +1295,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
|
||||
IDProperty *group, *idprop;
|
||||
char *name= _PyUnicode_AsString(key);
|
||||
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1307,7 +1344,7 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
|
||||
{
|
||||
IDProperty *group;
|
||||
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1324,7 +1361,7 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
|
||||
{
|
||||
IDProperty *group;
|
||||
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1342,7 +1379,7 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
|
||||
{
|
||||
IDProperty *group;
|
||||
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1671,7 +1708,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
|
||||
|
||||
if(name[0]=='_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups
|
||||
/* annoying exception, maybe we need to have different types for this... */
|
||||
if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idproperties_check(&self->ptr)) {
|
||||
if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idproperties_check(self->ptr.type)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "StructRNA - no __getitem__ support for this type");
|
||||
ret = NULL;
|
||||
}
|
||||
@@ -1682,7 +1719,8 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
|
||||
else if ((prop = RNA_struct_find_property(&self->ptr, name))) {
|
||||
ret = pyrna_prop_to_py(&self->ptr, prop);
|
||||
}
|
||||
else if ((func = RNA_struct_find_function(&self->ptr, name))) {
|
||||
/* RNA function only if callback is declared (no optional functions) */
|
||||
else if ((func = RNA_struct_find_function(&self->ptr, name)) && RNA_function_defined(func)) {
|
||||
ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self, func);
|
||||
}
|
||||
else if (self->ptr.type == &RNA_Context) {
|
||||
@@ -2027,7 +2065,7 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
|
||||
return NULL;
|
||||
|
||||
/* mostly copied from BPy_IDGroup_Map_GetItem */
|
||||
if(RNA_struct_idproperties_check(&self->ptr)==0) {
|
||||
if(RNA_struct_idproperties_check(self->ptr.type)==0) {
|
||||
PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties");
|
||||
return NULL;
|
||||
}
|
||||
@@ -3011,8 +3049,9 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
|
||||
/* sanity check, could skip this unless in debug mode */
|
||||
if(newclass) {
|
||||
PyObject *base_compare= pyrna_srna_PyBase(srna);
|
||||
PyObject *bases= PyObject_GetAttrString(newclass, "__bases__");
|
||||
//PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values!
|
||||
//PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to.
|
||||
PyObject *bases= ((PyTypeObject *)newclass)->tp_bases;
|
||||
PyObject *slots = PyDict_GetItemString(((PyTypeObject *)newclass)->tp_dict, "__slots__");
|
||||
|
||||
if(slots==NULL) {
|
||||
@@ -3032,8 +3071,6 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
|
||||
fprintf(stderr, "SRNA Subclassed: '%s'\n", idname);
|
||||
}
|
||||
}
|
||||
|
||||
Py_DECREF(bases);
|
||||
}
|
||||
|
||||
return newclass;
|
||||
@@ -3825,13 +3862,12 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
PyObject *item, *fitem;
|
||||
PyObject *py_arg_count;
|
||||
int i, flag, arg_count, func_arg_count;
|
||||
const char *identifier;
|
||||
const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; // __name__
|
||||
|
||||
|
||||
if (base_class) {
|
||||
if (!PyObject_IsSubclass(py_class, base_class)) {
|
||||
PyObject *name= PyObject_GetAttrString(base_class, "__name__");
|
||||
PyErr_Format( PyExc_TypeError, "expected %.200s subclass of class \"%.200s\"", class_type, name ? _PyUnicode_AsString(name):"<UNKNOWN>");
|
||||
Py_XDECREF(name);
|
||||
PyErr_Format( PyExc_TypeError, "expected %.200s subclass of class \"%.200s\"", class_type, py_class_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -3853,7 +3889,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
|
||||
if (item==NULL) {
|
||||
if ((flag & FUNC_REGISTER_OPTIONAL)==0) {
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s class to have an \"%.200s\" attribute", class_type, RNA_function_identifier(func));
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s, %.200s class to have an \"%.200s\" attribute", class_type, py_class_name, RNA_function_identifier(func));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -3868,7 +3904,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
fitem= item; /* py 3.x */
|
||||
|
||||
if (PyFunction_Check(fitem)==0) {
|
||||
PyErr_Format( PyExc_TypeError, "expected %.200s class \"%.200s\" attribute to be a function", class_type, RNA_function_identifier(func));
|
||||
PyErr_Format( PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a function", class_type, py_class_name, RNA_function_identifier(func));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -3880,7 +3916,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
Py_DECREF(py_arg_count);
|
||||
|
||||
if (arg_count != func_arg_count) {
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s class \"%.200s\" function to have %d args", class_type, RNA_function_identifier(func), func_arg_count);
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s, %.200s class \"%.200s\" function to have %d args", class_type, py_class_name, RNA_function_identifier(func), func_arg_count);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -3890,6 +3926,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
/* verify properties */
|
||||
lb= RNA_struct_defined_properties(srna);
|
||||
for(link=lb->first; link; link=link->next) {
|
||||
const char *identifier;
|
||||
prop= (PropertyRNA*)link;
|
||||
flag= RNA_property_flag(prop);
|
||||
|
||||
@@ -3913,9 +3950,20 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if(strcmp(identifier, "bl_label") == 0) {
|
||||
item= PyObject_GetAttrString(py_class, "__doc__");
|
||||
|
||||
if(item) {
|
||||
Py_DECREF(item); /* no need to keep a ref, the class owns it */
|
||||
|
||||
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (item == NULL && (((flag & PROP_REGISTER_OPTIONAL) != PROP_REGISTER_OPTIONAL))) {
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s class to have an \"%.200s\" attribute", class_type, identifier);
|
||||
PyErr_Format( PyExc_AttributeError, "expected %.200s, %.200s class to have an \"%.200s\" attribute", class_type, py_class_name, identifier);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -4093,6 +4141,7 @@ void pyrna_free_types(void)
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
|
||||
}
|
||||
|
||||
/* Note! MemLeak XXX
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
//void BPY_run_python_script() {}
|
||||
//void BPY_start_python() {}
|
||||
void BPY_call_importloader() {}
|
||||
void BPY_clear_script() {}
|
||||
//void BPY_free_compiled_text() {}
|
||||
void BPY_pyconstraint_eval() {}
|
||||
void BPY_pyconstraint_target() {}
|
||||
|
||||
273
source/blender/python/sphinx_doc_gen.py
Normal file
273
source/blender/python/sphinx_doc_gen.py
Normal file
@@ -0,0 +1,273 @@
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Contributor(s): Campbell Barton
|
||||
#
|
||||
# #**** END GPL LICENSE BLOCK #****
|
||||
|
||||
script_help_msg = '''
|
||||
Usage,
|
||||
run this script from blenders root path once you have compiled blender
|
||||
./blender.bin -b -P /b/source/blender/python/sphinx_doc_gen.py
|
||||
|
||||
This will generate python files in "./source/blender/python/doc/bpy/sphinx-in"
|
||||
Generate html docs by running...
|
||||
|
||||
sphinx-build source/blender/python/doc/bpy/sphinx-in source/blender/python/doc/bpy/sphinx-out
|
||||
'''
|
||||
|
||||
# if you dont have graphvis installed ommit the --graph arg.
|
||||
|
||||
# GLOBALS['BASEDIR'] = './source/blender/python/doc'
|
||||
|
||||
import os
|
||||
import inspect
|
||||
import bpy
|
||||
import rna_info
|
||||
reload(rna_info)
|
||||
|
||||
def range_str(val):
|
||||
if val < -10000000: return '-inf'
|
||||
if val > 10000000: return 'inf'
|
||||
if type(val)==float:
|
||||
return '%g' % val
|
||||
else:
|
||||
return str(val)
|
||||
|
||||
def write_indented_lines(ident, fn, text):
|
||||
if text is None:
|
||||
return
|
||||
for l in text.split("\n"):
|
||||
fn(ident + l.strip() + "\n")
|
||||
|
||||
def rna2sphinx(BASEPATH):
|
||||
|
||||
structs, funcs, ops, props = rna_info.BuildRNAInfo()
|
||||
|
||||
try:
|
||||
os.mkdir(BASEPATH)
|
||||
except:
|
||||
pass
|
||||
|
||||
# conf.py - empty for now
|
||||
filepath = os.path.join(BASEPATH, "conf.py")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("project = 'Blender 3D'\n")
|
||||
# fw("master_doc = 'index'\n")
|
||||
fw("copyright = u'Blender Foundation'\n")
|
||||
fw("version = '2.5'\n")
|
||||
fw("release = '2.5'\n")
|
||||
file.close()
|
||||
|
||||
|
||||
filepath = os.path.join(BASEPATH, "contents.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :glob:\n\n")
|
||||
fw(" bpy.ops.*\n\n")
|
||||
fw(" bpy.types.*\n\n")
|
||||
file.close()
|
||||
|
||||
if 0:
|
||||
filepath = os.path.join(BASEPATH, "bpy.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("\n")
|
||||
|
||||
title = ":mod:`bpy` --- Blender Python Module"
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
fw(".. module:: bpy.types\n\n")
|
||||
file.close()
|
||||
|
||||
def write_param(ident, fw, prop, is_return=False):
|
||||
if is_return:
|
||||
id_name = "return"
|
||||
id_type = "rtype"
|
||||
else:
|
||||
id_name = "arg"
|
||||
id_type = "type"
|
||||
|
||||
type_descr = prop.get_type_description(as_arg=True, class_fmt=":class:`%s`")
|
||||
if prop.name or prop.description:
|
||||
fw(ident + " :%s %s: %s\n" % (id_name, prop.identifier, ", ".join([val for val in (prop.name, prop.description) if val])))
|
||||
fw(ident + " :%s %s: %s\n" % (id_type, prop.identifier, type_descr))
|
||||
|
||||
def write_struct(struct):
|
||||
#if not struct.identifier.startswith("Sc") and not struct.identifier.startswith("I"):
|
||||
# return
|
||||
|
||||
#if not struct.identifier.startswith("Bone"):
|
||||
# return
|
||||
|
||||
filepath = os.path.join(BASEPATH, "bpy.types.%s.rst" % struct.identifier)
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
if struct.base:
|
||||
title = "%s(%s)" % (struct.identifier, struct.base.identifier)
|
||||
else:
|
||||
title = struct.identifier
|
||||
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
|
||||
fw(".. module:: bpy.types\n\n")
|
||||
|
||||
bases = struct.get_bases()
|
||||
if bases:
|
||||
if len(bases) > 1:
|
||||
fw("base classes --- ")
|
||||
else:
|
||||
fw("base class --- ")
|
||||
|
||||
fw(", ".join([(":class:`%s`" % base.identifier) for base in reversed(bases)]))
|
||||
fw("\n\n")
|
||||
|
||||
subclasses = [s for s in structs.values() if s.base is struct]
|
||||
|
||||
if subclasses:
|
||||
fw("subclasses --- \n")
|
||||
fw(", ".join([(":class:`%s`" % s.identifier) for s in subclasses]))
|
||||
fw("\n\n")
|
||||
|
||||
|
||||
if struct.base:
|
||||
fw(".. class:: %s(%s)\n\n" % (struct.identifier, struct.base.identifier))
|
||||
else:
|
||||
fw(".. class:: %s\n\n" % struct.identifier)
|
||||
|
||||
fw(" %s\n\n" % struct.description)
|
||||
|
||||
for prop in struct.properties:
|
||||
fw(" .. attribute:: %s\n\n" % prop.identifier)
|
||||
if prop.description:
|
||||
fw(" %s\n\n" % prop.description)
|
||||
type_descr = prop.get_type_description(as_arg=False, class_fmt=":class:`%s`")
|
||||
fw(" *type* %s\n\n" % type_descr)
|
||||
|
||||
# python attributes
|
||||
py_properties = struct.get_py_properties()
|
||||
py_prop = None
|
||||
for identifier, py_prop in py_properties:
|
||||
fw(" .. attribute:: %s\n\n" % identifier)
|
||||
write_indented_lines(" ", fw, py_prop.__doc__)
|
||||
if py_prop.fset is None:
|
||||
fw(" (readonly)\n\n")
|
||||
del py_properties, py_prop
|
||||
|
||||
for func in struct.functions:
|
||||
args_str = ", ".join([prop.get_arg_default(force=False) for prop in func.args])
|
||||
|
||||
fw(" .. method:: %s(%s)\n\n" % (func.identifier, args_str))
|
||||
fw(" %s\n\n" % func.description)
|
||||
|
||||
for prop in func.args:
|
||||
write_param(" ", fw, prop)
|
||||
|
||||
if func.return_value:
|
||||
write_param(" ", fw, func.return_value, is_return=True)
|
||||
fw("\n")
|
||||
|
||||
|
||||
# python methods
|
||||
py_funcs = struct.get_py_functions()
|
||||
py_func = None
|
||||
|
||||
for identifier, py_func in py_funcs:
|
||||
arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
|
||||
if arg_str.startswith("(self, "):
|
||||
arg_str = "(" + arg_str[7:]
|
||||
func_type = "method"
|
||||
elif arg_str.startswith("(cls, "):
|
||||
arg_str = "(" + arg_str[6:]
|
||||
func_type = "classmethod"
|
||||
else:
|
||||
func_type = "staticmethod"
|
||||
|
||||
fw(" .. %s:: %s%s\n\n" % (func_type, identifier, arg_str))
|
||||
if py_func.__doc__:
|
||||
write_indented_lines(" ", fw, py_func.__doc__)
|
||||
fw("\n")
|
||||
del py_funcs, py_func
|
||||
|
||||
if struct.references:
|
||||
# use this otherwise it gets in the index for a normal heading.
|
||||
fw(".. rubric:: References\n\n")
|
||||
|
||||
for ref in struct.references:
|
||||
ref_split = ref.split(".")
|
||||
if len(ref_split) > 2:
|
||||
ref = ref_split[-2] + "." + ref_split[-1]
|
||||
fw("* :class:`%s`\n" % ref)
|
||||
fw("\n")
|
||||
|
||||
|
||||
for struct in structs.values():
|
||||
write_struct(struct)
|
||||
|
||||
# oeprators
|
||||
def write_ops():
|
||||
fw = None
|
||||
|
||||
last_mod = ''
|
||||
|
||||
for op_key in sorted(ops.keys()):
|
||||
op = ops[op_key]
|
||||
|
||||
if last_mod != op.module_name:
|
||||
filepath = os.path.join(BASEPATH, "bpy.ops.%s.rst" % op.module_name)
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
title = "%s Operators" % (op.module_name[0].upper() + op.module_name[1:])
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
|
||||
fw(".. module:: bpy.ops.%s\n\n" % op.module_name)
|
||||
last_mod = op.module_name
|
||||
|
||||
args_str = ", ".join([prop.get_arg_default(force=True) for prop in op.args])
|
||||
fw(".. function:: %s(%s)\n\n" % (op.func_name, args_str))
|
||||
if op.description:
|
||||
fw(" %s\n\n" % op.description)
|
||||
for prop in op.args:
|
||||
write_param(" ", fw, prop)
|
||||
if op.args:
|
||||
fw("\n")
|
||||
|
||||
location = op.get_location()
|
||||
if location != (None, None):
|
||||
fw(" *python operator source --- `%s:%d`* \n\n" % location)
|
||||
|
||||
write_ops()
|
||||
|
||||
file.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
if 'bpy' not in dir():
|
||||
print("\nError, this script must run from inside blender2.5")
|
||||
print(script_help_msg)
|
||||
else:
|
||||
# os.system("rm source/blender/python/doc/bpy/sphinx-in/*.rst")
|
||||
# os.system("rm -rf source/blender/python/doc/bpy/sphinx-out/*")
|
||||
rna2sphinx('source/blender/python/doc/bpy/sphinx-in')
|
||||
|
||||
import sys
|
||||
sys.exit()
|
||||
Reference in New Issue
Block a user