Merged changes in the trunk up to revision 25613.

This commit is contained in:
2009-12-29 21:46:36 +00:00
294 changed files with 19336 additions and 17280 deletions

View File

@@ -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");
}

View File

@@ -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) );

View File

@@ -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);

View File

@@ -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

View File

@@ -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() {}