Manual merge of soc-2009-kazanbas branch:
* copied I/O scripts * copied, modified rna_*_api.c and rna_*.c I/O scripts not working yet due to slight BPY differences and RNA changes. Will fix them later. Not merged changes: * C unit testing integration, because it is clumsy * scons cross-compiling, can be merged easily later
This commit is contained in:
@@ -345,6 +345,27 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, int *val, const char *error_prefix)
|
||||
{
|
||||
char *param= _PyUnicode_AsString(item);
|
||||
|
||||
if (param==NULL) {
|
||||
char *enum_str= pyrna_enum_as_string(ptr, prop);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected a string enum type in (%.200s)", error_prefix, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
return 0;
|
||||
} else {
|
||||
if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, val)) {
|
||||
char *enum_str= pyrna_enum_as_string(ptr, prop);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
PyObject *ret;
|
||||
@@ -603,25 +624,34 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
|
||||
}
|
||||
case PROP_ENUM:
|
||||
{
|
||||
char *param = _PyUnicode_AsString(value);
|
||||
|
||||
if (param==NULL) {
|
||||
char *enum_str= pyrna_enum_as_string(ptr, prop);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected a string enum type in (%.200s)", error_prefix, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
return -1;
|
||||
} else {
|
||||
int val;
|
||||
if (RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, &val)) {
|
||||
if(data) *((int*)data)= val;
|
||||
else RNA_property_enum_set(ptr, prop, val);
|
||||
} else {
|
||||
char *enum_str= pyrna_enum_as_string(ptr, prop);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
int val, i;
|
||||
|
||||
if (PyUnicode_Check(value)) {
|
||||
if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix))
|
||||
return -1;
|
||||
}
|
||||
else if (PyTuple_Check(value)) {
|
||||
/* tuple of enum items, concatenate all values with OR */
|
||||
val= 0;
|
||||
for (i= 0; i < PyTuple_Size(value); i++) {
|
||||
int tmpval;
|
||||
|
||||
/* PyTuple_GET_ITEM returns a borrowed reference */
|
||||
if (!pyrna_string_to_enum(PyTuple_GET_ITEM(value, i), ptr, prop, &tmpval, error_prefix))
|
||||
return -1;
|
||||
|
||||
val |= tmpval;
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *enum_str= pyrna_enum_as_string(ptr, prop);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected a string enum or a tuple of strings in (%.200s)", error_prefix, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(data) *((int*)data)= val;
|
||||
else RNA_property_enum_set(ptr, prop, val);
|
||||
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user