[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31526] trunk/blender/source/blender: collection attributes can now be resolved with by rna
Campbell Barton
ideasman42 at gmail.com
Mon Aug 23 07:36:22 CEST 2010
Revision: 31526
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31526
Author: campbellbarton
Date: 2010-08-23 07:36:21 +0200 (Mon, 23 Aug 2010)
Log Message:
-----------
collection attributes can now be resolved with by rna
this now works...
bpy.context.scene.path_resolve("objects.active.location")
Also added an option to coerce the property into a native pytype.
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface.c
trunk/blender/source/blender/editors/object/object_add.c
trunk/blender/source/blender/makesrna/intern/rna_access.c
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2010-08-23 01:17:14 UTC (rev 31525)
+++ trunk/blender/source/blender/editors/interface/interface.c 2010-08-23 05:36:21 UTC (rev 31526)
@@ -2528,8 +2528,10 @@
}
}
}
- else
+ else {
+ printf("ui_def_but_rna: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
str= (char*)propname;
+ }
/* now create button */
but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
Modified: trunk/blender/source/blender/editors/object/object_add.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_add.c 2010-08-23 01:17:14 UTC (rev 31525)
+++ trunk/blender/source/blender/editors/object/object_add.c 2010-08-23 05:36:21 UTC (rev 31526)
@@ -501,7 +501,6 @@
static int object_metaball_add_exec(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
- MetaBall *mball;
MetaElem *elem;
int newob= 0;
int enter_editmode;
Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c 2010-08-23 01:17:14 UTC (rev 31525)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c 2010-08-23 05:36:21 UTC (rev 31526)
@@ -2949,7 +2949,7 @@
PropertyRNA *prop;
PointerRNA curptr, nextptr;
char fixedbuf[256], *token;
- int type, len, intkey;
+ int type, intkey;
prop= NULL;
curptr= *ptr;
@@ -3001,33 +3001,44 @@
break;
case PROP_COLLECTION:
if(*path) {
- /* resolve the lookup with [] brackets */
- token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
+ if(*path == '[') {
+ /* resolve the lookup with [] brackets */
+ token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
+
+ if(!token)
+ return 0;
+
+ /* check for "" to see if it is a string */
+ if(rna_token_strip_quotes(token)) {
+ RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
+ }
+ else {
+ /* otherwise do int lookup */
+ intkey= atoi(token);
+ RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
+ }
- if(!token)
- return 0;
-
- len= strlen(token);
-
- /* check for "" to see if it is a string */
- if(rna_token_strip_quotes(token)) {
- RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
+ if(token != fixedbuf) {
+ MEM_freeN(token);
+ }
}
else {
- /* otherwise do int lookup */
- intkey= atoi(token);
- RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
+ PointerRNA c_ptr;
+
+ /* ensure we quit on invalid values */
+ nextptr.data = NULL;
+
+ if(RNA_property_collection_type_get(&curptr, prop, &c_ptr)) {
+ nextptr= c_ptr;
+ }
}
- if(token != fixedbuf)
- MEM_freeN(token);
-
if(nextptr.data)
curptr= nextptr;
else
return 0;
}
-
+
break;
default:
if (index==NULL)
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2010-08-23 01:17:14 UTC (rev 31525)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2010-08-23 05:36:21 UTC (rev 31526)
@@ -2142,25 +2142,37 @@
}
static char pyrna_struct_path_resolve_doc[] =
-".. method:: path_resolve(path)\n"
+".. method:: path_resolve(path, coerce=True)\n"
"\n"
-" Returns the property from the path given or None if the property is not found.";
+" Returns the property from the path, raise an exception when not found.\n"
+"\n"
+" :arg path: path which this property resolves.\n"
+" :type path: string\n"
+" :arg coerce: optional argument, when True, the property will be converted into its python representation.\n"
+" :type coerce: boolean\n";
-static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *value)
+static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
{
- char *path= _PyUnicode_AsString(value);
+ char *path;
+ PyObject *coerce= Py_True;
PointerRNA r_ptr;
PropertyRNA *r_prop;
- if(path==NULL) {
- PyErr_SetString(PyExc_TypeError, "bpy_struct.path_resolve(): accepts only a single string argument");
+ if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce))
return NULL;
+
+ if (RNA_path_resolve(&self->ptr, path, &r_ptr, &r_prop)) {
+ if(coerce == Py_False) {
+ return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
+ }
+ else {
+ return pyrna_prop_to_py(&r_ptr, r_prop);
+ }
}
-
- if (RNA_path_resolve(&self->ptr, path, &r_ptr, &r_prop))
- return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
-
- Py_RETURN_NONE;
+ else {
+ PyErr_Format(PyExc_TypeError, "%.200s.path_resolve(\"%.200s\") could not be resolved", RNA_struct_identifier(self->ptr.type), path);
+ return NULL;
+ }
}
static char pyrna_struct_path_from_id_doc[] =
@@ -3112,7 +3124,7 @@
{"driver_remove", (PyCFunction)pyrna_struct_driver_remove, METH_VARARGS, pyrna_struct_driver_remove_doc},
{"is_property_set", (PyCFunction)pyrna_struct_is_property_set, METH_VARARGS, pyrna_struct_is_property_set_doc},
{"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, pyrna_struct_is_property_hidden_doc},
- {"path_resolve", (PyCFunction)pyrna_struct_path_resolve, METH_O, pyrna_struct_path_resolve_doc},
+ {"path_resolve", (PyCFunction)pyrna_struct_path_resolve, METH_VARARGS, pyrna_struct_path_resolve_doc},
{"path_from_id", (PyCFunction)pyrna_struct_path_from_id, METH_VARARGS, pyrna_struct_path_from_id_doc},
{"recast_type", (PyCFunction)pyrna_struct_recast_type, METH_NOARGS, pyrna_struct_recast_type_doc},
{"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL},
More information about the Bf-blender-cvs
mailing list