[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35536] trunk/blender: bpy.types.libraries .load sphinx doc & examples (doc system needed some updates).

Campbell Barton ideasman42 at gmail.com
Mon Mar 14 11:31:51 CET 2011


Revision: 35536
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35536
Author:   campbellbarton
Date:     2011-03-14 10:31:50 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
bpy.types.libraries.load sphinx doc & examples (doc system needed some updates).

http://www.blender.org/documentation/blender_python_api_2_56_3/bpy.types.BlendDataLibraries.html#bpy.types.BlendDataLibraries.load

Modified Paths:
--------------
    trunk/blender/doc/python_api/sphinx_doc_gen.py
    trunk/blender/release/scripts/modules/rna_info.py
    trunk/blender/source/blender/python/intern/bpy_library.c

Added Paths:
-----------
    trunk/blender/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py

Added: trunk/blender/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
===================================================================
--- trunk/blender/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py	                        (rev 0)
+++ trunk/blender/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py	2011-03-14 10:31:50 UTC (rev 35536)
@@ -0,0 +1,23 @@
+import bpy
+
+filepath = "//link_library.blend"
+
+# load a single scene we know the name of.
+with bpy.data.libraries.load(filepath) as (data_from, data_to):
+    data_to.scenes = ["Scene"]
+
+
+# load all meshes
+with bpy.data.libraries.load(filepath) as (data_from, data_to):
+    data_to.meshes = data_from.meshes
+
+
+# link all objects starting with 'A'
+with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to):
+    data_to.objects = [name for name in data_from.objects if name.startswith("A")]
+
+
+# append everything
+with bpy.data.libraries.load(filepath) as (data_from, data_to):
+    for attr in dir(data_to):
+        setattr(data_to, attr, getattr(data_from, attr))

Modified: trunk/blender/doc/python_api/sphinx_doc_gen.py
===================================================================
--- trunk/blender/doc/python_api/sphinx_doc_gen.py	2011-03-14 07:30:49 UTC (rev 35535)
+++ trunk/blender/doc/python_api/sphinx_doc_gen.py	2011-03-14 10:31:50 UTC (rev 35536)
@@ -279,7 +279,14 @@
         fw(ident + ".. function:: %s()\n\n" % identifier)
         fw(ident + "   " + undocumented_message(module_name, type_name, identifier))
 
+    if is_class:
+        write_example_ref(ident + "   ", fw, module_name + "." + type_name + "." + identifier)
+    else:
+        write_example_ref(ident + "   ", fw, module_name + "." + identifier)
 
+    fw("\n")
+
+
 def pyprop2sphinx(ident, fw, identifier, py_prop):
     '''
     python property to sphinx
@@ -356,7 +363,7 @@
             elif value_type in (types.BuiltinMethodType, types.BuiltinFunctionType):  # both the same at the moment but to be future proof
                 # note: can't get args from these, so dump the string as is
                 # this means any module used like this must have fully formatted docstrings.
-                py_c_func2sphinx("", fw, module_name, module, attribute, value, is_class=False)
+                py_c_func2sphinx("", fw, module_name, None, attribute, value, is_class=False)
             elif value_type == type:
                 classes.append((attribute, value))
             elif value_type in (bool, int, float, str, tuple):
@@ -655,6 +662,12 @@
             pyfunc2sphinx("   ", fw, identifier, py_func, is_class=True)
         del py_funcs, py_func
 
+        py_funcs = struct.get_py_c_functions()
+        py_func = None
+
+        for identifier, py_func in py_funcs:
+            py_c_func2sphinx("   ", fw, "bpy.types", struct.identifier, identifier, py_func, is_class=True)
+
         lines = []
 
         if struct.base or _BPY_STRUCT_FAKE:

Modified: trunk/blender/release/scripts/modules/rna_info.py
===================================================================
--- trunk/blender/release/scripts/modules/rna_info.py	2011-03-14 07:30:49 UTC (rev 35535)
+++ trunk/blender/release/scripts/modules/rna_info.py	2011-03-14 10:31:50 UTC (rev 35536)
@@ -152,6 +152,14 @@
                 functions.append((identifier, attr))
         return functions
 
+    def get_py_c_functions(self):
+        import types
+        functions = []
+        for identifier, attr in self._get_py_visible_attrs():
+            if type(attr) in (types.BuiltinMethodType, types.BuiltinFunctionType):
+                functions.append((identifier, attr))
+        return functions
+
     def __str__(self):
 
         txt = ""

Modified: trunk/blender/source/blender/python/intern/bpy_library.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_library.c	2011-03-14 07:30:49 UTC (rev 35535)
+++ trunk/blender/source/blender/python/intern/bpy_library.c	2011-03-14 10:31:50 UTC (rev 35536)
@@ -155,7 +155,19 @@
 	NULL
 };
 
-
+static char bpy_lib_load_doc[] =
+".. method:: load(filepath, link=False, relative=False)\n"
+"\n"
+"   Returns a context manager which exposes 2 library objects on entering.\n"
+"   Each object has attributes matching bpy.data which are lists of strings to be linked.\n"
+"\n"
+"   :arg filepath: The path to a blend file.\n"
+"   :type filepath: string\n"
+"   :arg link: When False reference to the original file is lost.\n"
+"   :type link: bool\n"
+"   :arg relative: When True the path is stored relative to the open blend file.\n"
+"   :type relative: bool\n"
+;
 static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
 {
 	static const char *kwlist[] = {"filepath", "link", "relative", NULL};
@@ -168,8 +180,8 @@
 
 	ret= PyObject_New(BPy_Library, &bpy_lib_Type);
 
-	BLI_strncpy(ret->relpath, filename, sizeof(BPy_Library));
-	BLI_strncpy(ret->abspath, filename, sizeof(BPy_Library));
+	BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath));
+	BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath));
 	BLI_path_abs(ret->abspath, G.main->name);
 
 	ret->blo_handle= NULL;
@@ -342,7 +354,7 @@
 
 int bpy_lib_init(PyObject *mod_par)
 {
-	static PyMethodDef load_meth= {"load", (PyCFunction)bpy_lib_load, METH_STATIC|METH_VARARGS|METH_KEYWORDS};
+	static PyMethodDef load_meth= {"load", (PyCFunction)bpy_lib_load, METH_STATIC|METH_VARARGS|METH_KEYWORDS, bpy_lib_load_doc};
 	PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
 
 	if(PyType_Ready(&bpy_lib_Type) < 0)




More information about the Bf-blender-cvs mailing list