Revision: 21804
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21804
Author:   campbellbarton
Date:     2009-07-22 21:50:21 +0200 (Wed, 22 Jul 2009)

Log Message:
-----------
less verbose subtyping Py/C API code, use PyObject_CallFunction which supports 
packing the function args into a string.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c

Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c  
2009-07-22 18:06:59 UTC (rev 21803)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c  
2009-07-22 19:50:21 UTC (rev 21804)
@@ -2300,31 +2300,23 @@
        } else if ((newclass= RNA_struct_py_type_get(srna))) {
                Py_INCREF(newclass);
        } else {
-               StructRNA *base;
-               
-               /* for now, return the base RNA type rather then a real module 
*/
-               
-               /* Assume RNA_struct_py_type_get(srna) was alredy checked */
-               
                /* subclass equivelents
                - class myClass(myBase):
                        some='value' # or ...
                - myClass = type(name='myClass', bases=(myBase,), 
dict={'__module__':'bpy.types'})
                */
-               const char *descr= RNA_struct_ui_description(srna);
 
-               PyObject *args = PyTuple_New(3);
-               PyObject *bases = PyTuple_New(1);
+               /* Assume RNA_struct_py_type_get(srna) was alredy checked */
+               StructRNA *base;
+
                PyObject *py_base= NULL;
-               PyObject *dict = PyDict_New();
-               PyObject *item;
-       
+
+               const char *idname= RNA_struct_identifier(srna);
+               const char *descr= RNA_struct_ui_description(srna);
+
+               if(!descr) descr= "(no docs)";
                
-               // arg 1
-               //PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name));
-               PyTuple_SET_ITEM(args, 0, 
PyUnicode_FromString(RNA_struct_identifier(srna)));
-               
-               // arg 2
+               /* get the base type */
                base= RNA_struct_base(srna);
                if(base && base != srna) {
                        /*/printf("debug subtype %s %p\n", 
RNA_struct_identifier(srna), srna); */
@@ -2336,34 +2328,8 @@
                        Py_INCREF(py_base);
                }
                
-               PyTuple_SET_ITEM(bases, 0, py_base);
+               newclass = PyObject_CallFunction(       
(PyObject*)&PyType_Type, "s(N){ssss}", idname, py_base, 
"__module__","bpy.types", "__doc__",descr);
 
-               PyTuple_SET_ITEM(args, 1, bases);
-               
-               // arg 3 - add an instance of the rna 
-               if(descr) {
-                       item= PyUnicode_FromString(descr);
-                       PyDict_SetItemString(dict, "__doc__", item);
-                       Py_DECREF(item);
-               }
-               
-               /* this isnt needed however its confusing if we get python 
script names in blender types,
-                * because the __module__ is used when printing the class */
-               item= PyUnicode_FromString("bpy.types"); /* just to know its an 
internal type */
-               PyDict_SetItemString(dict, "__module__", item);
-               Py_DECREF(item);
-               
-               
-               PyTuple_SET_ITEM(args, 2, dict); // fill with useful subclass 
things!
-               
-               if (PyErr_Occurred()) {
-                       PyErr_Print();
-                       PyErr_Clear();
-               }
-               
-               newclass = PyObject_CallObject((PyObject *)&PyType_Type, args);
-               Py_DECREF(args);
-
                if (newclass) {
                        pyrna_subtype_set_rna(newclass, srna);
                        // PyObSpit("NewStructRNA Type: ", (PyObject 
*)newclass);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to