diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-10 22:09:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-10 22:09:53 +0400 |
commit | 64f300ccf4ffa687b196b111b91682d8a50d0069 (patch) | |
tree | 2d1993b9b2dc98bb0ec3c1c56e83677505cf4010 /source/blender/python | |
parent | b3d6b2f7283e200e3b3724cc93c8279fe7b4dcf0 (diff) |
Use python subtypes so bpy.types.Mesh is a subtype of bpy.types.ID
This means checks like this work.
isinstance(bpy.data.meshes[0], bpy.types.ID)
bpy.types.Mesh.__base__ == bpy.types.ID
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/generic/Mathutils.h | 7 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 47 |
2 files changed, 31 insertions, 23 deletions
diff --git a/source/blender/python/generic/Mathutils.h b/source/blender/python/generic/Mathutils.h index 6a4e28d6068..5bdd9d9cfe0 100644 --- a/source/blender/python/generic/Mathutils.h +++ b/source/blender/python/generic/Mathutils.h @@ -85,6 +85,13 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps); #endif typedef struct Mathutils_Callback Mathutils_Callback; + +typedef int (*BaseMathCheckFunc)(PyObject *); +typedef int (*BaseMathGetFunc)(PyObject *, int, float *); +typedef int (*BaseMathSetFunc)(PyObject *, int, float *); +typedef int (*BaseMathGetIndexFunc)(PyObject *, int, float *, int); +typedef int (*BaseMathSetIndexFunc)(PyObject *, int, float *, int); + struct Mathutils_Callback { int (*check)(PyObject *user); /* checks the user is still valid */ int (*get)(PyObject *user, int subtype, float *from); /* gets the vector from the user */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 8314a3cc89c..c6fbda0caef 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -94,13 +94,14 @@ static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, fl } Mathutils_Callback mathutils_rna_array_cb = { - mathutils_rna_generic_check, - mathutils_rna_vector_get, - mathutils_rna_vector_set, - mathutils_rna_vector_get_index, - mathutils_rna_vector_set_index + (BaseMathCheckFunc) mathutils_rna_generic_check, + (BaseMathGetFunc) mathutils_rna_vector_get, + (BaseMathSetFunc) mathutils_rna_vector_set, + (BaseMathGetIndexFunc) mathutils_rna_vector_get_index, + (BaseMathSetIndexFunc) mathutils_rna_vector_set_index }; + /* bpyrna matrix callbacks */ static int mathutils_rna_matrix_cb_index= -1; /* index for our callbacks */ @@ -123,11 +124,11 @@ static int mathutils_rna_matrix_set(BPy_PropertyRNA *self, int subtype, float *m } Mathutils_Callback mathutils_rna_matrix_cb = { - mathutils_rna_generic_check, - mathutils_rna_matrix_get, - mathutils_rna_matrix_set, - NULL, - NULL + (BaseMathCheckFunc) mathutils_rna_generic_check, + (BaseMathGetFunc) mathutils_rna_matrix_get, + (BaseMathSetFunc) mathutils_rna_matrix_set, + (BaseMathGetIndexFunc) NULL, + (BaseMathSetIndexFunc) NULL }; #endif @@ -2172,21 +2173,17 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) /* done with rna instance */ } -PyObject* pyrna_struct_Subtype(PointerRNA *ptr) +PyObject* pyrna_srna_Subtype(StructRNA *srna) { PyObject *newclass = NULL; - StructRNA *srna, *base; - - if(ptr->type == &RNA_Struct) - srna= ptr->data; - else - srna= ptr->type; if (srna == NULL) { newclass= NULL; /* Nothing to do */ } 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 */ @@ -2203,22 +2200,21 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) PyObject *py_base= NULL; PyObject *dict = PyDict_New(); PyObject *item; - + // arg 1 //PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name)); PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(RNA_struct_identifier(srna))); // arg 2 -#if 0 // XXX - This should be possible but for some reason it does a recursive call for MirrorModifier base= RNA_struct_base(srna); if(base && base != srna) { - // printf("debug subtype %s\n", RNA_struct_identifier(srna)); - py_base= pyrna_struct_Subtype(base); + /*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */ + py_base= pyrna_srna_Subtype(base); } -#endif + if(py_base==NULL) { - py_base= &pyrna_struct_Type; + py_base= (PyObject *)&pyrna_struct_Type; Py_INCREF(py_base); } @@ -2264,6 +2260,11 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) return newclass; } +PyObject* pyrna_struct_Subtype(PointerRNA *ptr) +{ + return pyrna_srna_Subtype((ptr->type == &RNA_Struct) ? ptr->data : ptr->type); +} + /*-----------------------CreatePyObject---------------------------------*/ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr ) { |