Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-12-02 17:36:35 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-12-02 17:36:35 +0300
commit9f27be3b2dcf4cd9abfacaca0871340811586664 (patch)
tree373df23dcf530e9840f4ba0cf1dbc6e1c4ca7c09 /source/blender/python
parent54908979c54ab332156f438e995d5dce8ee8420c (diff)
Added RNA functions from PyRNA
* RNA_property_enum_value * RNA_property_enum_identifier To get an enum string from a value and a value from an enum. BPy_StructRNA types (objects, meshes, images etc) can now be used as dictionary keys.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_rna.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 5f9a5b195c0..ab95c01cc74 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -54,6 +54,12 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" ]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop) );
}
+static long pyrna_struct_hash( BPy_StructRNA * self )
+{
+ return (long)self->ptr.data;
+}
+
+
static PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
{
PyObject *ret;
@@ -86,26 +92,17 @@ static PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
break;
}
case PROP_ENUM:
- {
- const EnumPropertyItem *item;
- int totitem, i, val;
-
- val = RNA_property_enum_get(ptr, prop);
-
- RNA_property_enum_items(ptr, prop, &item, &totitem);
-
- for (i=0; i<totitem; i++) {
- if (item[i].value == val)
- break;
- }
+ {
+ const char *identifier;
+ int val = RNA_property_enum_get(ptr, prop);
- if (i<totitem) {
- ret = PyUnicode_FromString( item[i].identifier );
+ if (RNA_property_enum_identifier(ptr, prop, val, &identifier)) {
+ ret = PyUnicode_FromString( identifier );
} else {
PyErr_Format(PyExc_AttributeError, "enum \"%d\" not found", val);
ret = NULL;
}
-
+
break;
}
case PROP_POINTER:
@@ -287,19 +284,8 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
PyErr_SetString(PyExc_TypeError, "expected a string type");
return -1;
} else {
- const EnumPropertyItem *item;
- int totitem, i, val;
-
- RNA_property_enum_items(ptr, prop, &item, &totitem);
-
- for (i=0; i<totitem; i++) {
- if (strcmp(item[i].identifier, param)==0) {
- val = item[i].value;
- break;
- }
- }
-
- if (i<totitem) {
+ int val;
+ if (RNA_property_enum_value(ptr, prop, param, &val)) {
RNA_property_enum_set(ptr, prop, val);
} else {
PyErr_Format(PyExc_AttributeError, "enum \"%s\" not found", param);
@@ -926,7 +912,7 @@ PyTypeObject pyrna_struct_Type = {
/* More standard operations (here for binary compatibility) */
- NULL, /* hashfunc tp_hash; */
+ ( hashfunc )pyrna_struct_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
( getattrofunc ) pyrna_struct_getattro, /* getattrofunc tp_getattro; */