auto-generated py api now shows bpy.context.* items in the 'References' section of each type.

This commit is contained in:
2012-11-03 07:28:51 +00:00
parent 5a8cef4a85
commit d24278635a

View File

@@ -910,36 +910,8 @@ def pymodule2sphinx(basepath, module_name, module, title):
file.close()
def pycontext2sphinx(basepath):
# Only use once. very irregular
filepath = os.path.join(basepath, "bpy.context.rst")
file = open(filepath, "w", encoding="utf-8")
fw = file.write
fw(title_string("Context Access (bpy.context)", "="))
fw(".. module:: bpy.context\n")
fw("\n")
fw("The context members available depend on the area of blender which is currently being accessed.\n")
fw("\n")
fw("Note that all context values are readonly, but may be modified through the data api or by running operators\n\n")
# nasty, get strings directly from blender because there is no other way to get it
import ctypes
context_strings = (
"screen_context_dir",
"view3d_context_dir",
"buttons_context_dir",
"image_context_dir",
"node_context_dir",
"text_context_dir",
"clip_context_dir",
"sequencer_context_dir",
)
# Changes in blender will force errors here
type_map = {
# Changes in blender will force errors here
context_type_map = {
"active_base": ("ObjectBase", False),
"active_bone": ("Bone", False),
"active_object": ("Object", False),
@@ -1003,7 +975,35 @@ def pycontext2sphinx(basepath):
"visible_pose_bones": ("PoseBone", True),
"weight_paint_object": ("Object", False),
"world": ("World", False),
}
}
def pycontext2sphinx(basepath):
# Only use once. very irregular
filepath = os.path.join(basepath, "bpy.context.rst")
file = open(filepath, "w", encoding="utf-8")
fw = file.write
fw(title_string("Context Access (bpy.context)", "="))
fw(".. module:: bpy.context\n")
fw("\n")
fw("The context members available depend on the area of blender which is currently being accessed.\n")
fw("\n")
fw("Note that all context values are readonly, but may be modified through the data api or by running operators\n\n")
# nasty, get strings directly from blender because there is no other way to get it
import ctypes
context_strings = (
"screen_context_dir",
"view3d_context_dir",
"buttons_context_dir",
"image_context_dir",
"node_context_dir",
"text_context_dir",
"clip_context_dir",
"sequencer_context_dir",
)
unique = set()
blend_cdll = ctypes.CDLL("")
@@ -1018,7 +1018,7 @@ def pycontext2sphinx(basepath):
while char_array[i] is not None:
member = ctypes.string_at(char_array[i]).decode(encoding="ascii")
fw(".. data:: %s\n\n" % member)
member_type, is_seq = type_map[member]
member_type, is_seq = context_type_map[member]
fw(" :type: %s :class:`bpy.types.%s`\n\n" % ("sequence of " if is_seq else "", member_type))
unique.add(member)
i += 1
@@ -1026,8 +1026,8 @@ def pycontext2sphinx(basepath):
# generate typemap...
# for member in sorted(unique):
# print(' "%s": ("", False),' % member)
if len(type_map) > len(unique):
raise Exception("Some types are not used: %s" % str([member for member in type_map if member not in unique]))
if len(context_type_map) > len(unique):
raise Exception("Some types are not used: %s" % str([member for member in context_type_map if member not in unique]))
else:
pass # will have raised an error above
@@ -1314,6 +1314,13 @@ def pyrna2sphinx(basepath):
fw(".. hlist::\n")
fw(" :columns: 2\n\n")
# context does its own thing
# "active_base": ("ObjectBase", False),
for ref_attr, (ref_type, ref_is_seq) in sorted(context_type_map.items()):
if ref_type == struct_id:
fw(" * :mod:`bpy.context.%s`\n" % ref_attr)
del ref_attr, ref_type, ref_is_seq
for ref in struct.references:
ref_split = ref.split(".")
if len(ref_split) > 2: