[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27102] trunk/blender/source/blender: allow python api to set values of library liked data ( still checks editable flag)

Campbell Barton ideasman42 at gmail.com
Tue Feb 23 12:19:55 CET 2010


Revision: 27102
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27102
Author:   campbellbarton
Date:     2010-02-23 12:19:55 +0100 (Tue, 23 Feb 2010)

Log Message:
-----------
allow python api to set values of library liked data (still checks editable flag)
+ improved exception messages.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2010-02-23 09:39:47 UTC (rev 27101)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2010-02-23 11:19:55 UTC (rev 27102)
@@ -664,6 +664,7 @@
 
 int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop);
 int RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index);
+int RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop); /* without lib check, only checks the flag */
 int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop);
 int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop);
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2010-02-23 09:39:47 UTC (rev 27101)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2010-02-23 11:19:55 UTC (rev 27102)
@@ -1135,19 +1135,22 @@
 
 int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
 {
-	ID *id;
+	ID *id= ptr->id.data;
 	int flag;
 
 	prop= rna_ensure_property(prop);
+	flag= prop->editable ? prop->editable(ptr) : prop->flag;
+	return (flag & PROP_EDITABLE) && (!id || !id->lib || (prop->flag & PROP_LIB_EXCEPTION));
+}
 
-	if(prop->editable)
-		flag= prop->editable(ptr);
-	else
-		flag= prop->flag;
-	
-	id= ptr->id.data;
+int RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop)
+{
+	ID *id= ptr->id.data;
+	int flag;
 
-	return (flag & PROP_EDITABLE) && (!id || !id->lib || (prop->flag & PROP_LIB_EXCEPTION));
+	prop= rna_ensure_property(prop);
+	flag= prop->editable ? prop->editable(ptr) : prop->flag;
+	return (flag & PROP_EDITABLE);
 }
 
 /* same as RNA_property_editable(), except this checks individual items in an array */

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-02-23 09:39:47 UTC (rev 27101)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-02-23 11:19:55 UTC (rev 27102)
@@ -474,13 +474,13 @@
 		char *param= _PyUnicode_AsString(key);
 
 		if(param==NULL) {
-			PyErr_Format(PyExc_TypeError, "%s expected a string. found a %.200s", error_prefix, Py_TYPE(key)->tp_name);
+			PyErr_Format(PyExc_TypeError, "%.200s expected a string. found a %.200s", error_prefix, Py_TYPE(key)->tp_name);
 			return -1;
 		}
 
 		if(RNA_enum_value_from_id(items, param, &ret) == 0) {
 			char *enum_str= BPy_enum_as_string(items);
-			PyErr_Format(PyExc_TypeError, "%s \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
+			PyErr_Format(PyExc_TypeError, "%.200s \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
 			MEM_freeN(enum_str);
 			return -1;
 		}
@@ -507,7 +507,7 @@
 	}
 	else {
 		if(PySet_GET_SIZE(value)) {
-			PyErr_Format(PyExc_TypeError, "%s: empty enum \"%.200s\" could not have any values assigned.", error_prefix, RNA_property_identifier(prop));
+			PyErr_Format(PyExc_TypeError, "%.200s: empty enum \"%.200s\" could not have any values assigned.", error_prefix, RNA_property_identifier(prop));
 			ret= -1;
 		}
 		else {
@@ -651,7 +651,7 @@
 		ret = pyrna_prop_CreatePyObject(ptr, prop);
 		break;
 	default:
-		PyErr_Format(PyExc_TypeError, "RNA Error: unknown type \"%d\" (pyrna_prop_to_py)", type);
+		PyErr_Format(PyExc_TypeError, "bpy_struct internal error: unknown type \"%d\" (pyrna_prop_to_py)", type);
 		ret = NULL;
 		break;
 	}
@@ -1087,7 +1087,7 @@
 	if(RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr))
 		return pyrna_struct_CreatePyObject(&newptr);
 
-	PyErr_Format(PyExc_IndexError, "index %d out of range", keynum);
+	PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d out of range", keynum);
 	return NULL;
 }
 
@@ -1100,7 +1100,7 @@
 	if(keynum >= 0 && keynum < len)
 		return pyrna_prop_to_py_index(self, keynum);
 
-	PyErr_Format(PyExc_IndexError, "index %d out of range", keynum);
+	PyErr_Format(PyExc_IndexError, "bpy_prop_array[index]: index %d out of range", keynum);
 	return NULL;
 }
 
@@ -1110,7 +1110,7 @@
 	if(RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
 		return pyrna_struct_CreatePyObject(&newptr);
 
-	PyErr_Format(PyExc_KeyError, "key \"%.200s\" not found", keyname);
+	PyErr_Format(PyExc_KeyError, "bpy_prop_collection[key]: key \"%.200s\" not found", keyname);
 	return NULL;
 }
 /* static PyObject *pyrna_prop_array_subscript_str(BPy_PropertyRNA *self, char *keyname) */
@@ -1240,12 +1240,12 @@
 			return pyrna_prop_collection_subscript_slice(&self->ptr, self->prop, start, stop, len);
 		}
 		else {
-			PyErr_SetString(PyExc_TypeError, "slice steps not supported with rna");
+			PyErr_SetString(PyExc_TypeError, "bpy_prop_collection[slice]: slice steps not supported with rna");
 			return NULL;
 		}
 	}
 	else {
-		PyErr_Format(PyExc_TypeError, "invalid rna key, key must be a string or an int instead of %.200s instance.", Py_TYPE(key)->tp_name);
+		PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key]: invalid key, must be a string or an int instead of %.200s instance.", Py_TYPE(key)->tp_name);
 		return NULL;
 	}
 }
@@ -1275,12 +1275,12 @@
 			return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len);
 		}
 		else {
-			PyErr_SetString(PyExc_TypeError, "slice steps not supported with rna");
+			PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice]: slice steps not supported with rna");
 			return NULL;
 		}
 	}
 	else {
-		PyErr_SetString(PyExc_AttributeError, "invalid key, key must be an int");
+		PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int");
 		return NULL;
 	}
 }
@@ -1294,17 +1294,17 @@
 	int ret= 0;
 
 	if(value_orig == NULL) {
-		PyErr_SetString(PyExc_TypeError, "invalid slice assignment, deleting with list types is not supported by StructRNA.");
+		PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice] = value: deleting with list types is not supported by bpy_struct.");
 		return -1;
 	}
 
-	if(!(value=PySequence_Fast(value_orig, "invalid slice assignment, type is not a sequence"))) {
+	if(!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: type is not a sequence"))) {
 		return -1;
 	}
 
 	if(PySequence_Fast_GET_SIZE(value) != stop-start) {
 		Py_DECREF(value);
-		PyErr_SetString(PyExc_TypeError, "invalid slice assignment, resizing StructRNA arrays isn't supported.");
+		PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice] = value: resizing bpy_struct arrays isn't supported.");
 		return -1;
 	}
 
@@ -1397,7 +1397,7 @@
 	if(keynum >= 0 && keynum < len)
 		return pyrna_py_to_prop_index(self, keynum, value);
 
-	PyErr_SetString(PyExc_IndexError, "out of range");
+	PyErr_SetString(PyExc_IndexError, "bpy_prop_array[index] = value: index out of range");
 	return -1;
 }
 
@@ -1405,8 +1405,8 @@
 {
 	/* char *keyname = NULL; */ /* not supported yet */
 	
-	if (!RNA_property_editable(&self->ptr, self->prop)) {
-		PyErr_Format( PyExc_AttributeError, "PropertyRNA - attribute \"%.200s\" from \"%.200s\" is read-only", RNA_property_identifier(self->prop), RNA_struct_identifier(self->ptr.type) );
+	if (!RNA_property_editable_flag(&self->ptr, self->prop)) {
+		PyErr_Format(PyExc_AttributeError, "bpy_prop_collection: attribute \"%.200s\" from \"%.200s\" is read-only", RNA_property_identifier(self->prop), RNA_struct_identifier(self->ptr.type) );
 		return -1;
 	}
 
@@ -1470,7 +1470,7 @@
 	char *keyname = _PyUnicode_AsString(value);
 
 	if(keyname==NULL) {
-		PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, key must be a string type");
+		PyErr_SetString(PyExc_TypeError, "bpy_prop_collection.__contains__: expected a string");
 		return -1;
 	}
 
@@ -1486,12 +1486,12 @@
 	char *name = _PyUnicode_AsString(value);
 
 	if (!name) {
-		PyErr_SetString( PyExc_TypeError, "expected a string");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct.__contains__: expected a string");
 		return -1;
 	}
 
 	if(RNA_struct_idproperties_check(self->ptr.type)==0) {
-		PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct: this type doesnt support IDProperties");
 		return -1;
 	}
 
@@ -1548,21 +1548,21 @@
 	}
 
 	if(name==NULL) {
-		PyErr_SetString( PyExc_TypeError, "only strings are allowed as keys of ID properties");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct[key]: only strings are allowed as keys of ID properties");
 		return NULL;
 	}
 
 	group= RNA_struct_idproperties(&self->ptr, 0);
 
 	if(group==NULL) {
-		PyErr_Format( PyExc_KeyError, "key \"%s\" not found", name);
+		PyErr_Format( PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name);
 		return NULL;
 	}
 
 	idprop= IDP_GetPropertyFromGroup(group, name);
 
 	if(idprop==NULL) {
-		PyErr_Format( PyExc_KeyError, "key \"%s\" not found", name);
+		PyErr_Format( PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name);
 		return NULL;
 	}
 
@@ -1574,7 +1574,7 @@
 	IDProperty *group= RNA_struct_idproperties(&self->ptr, 1);
 
 	if(group==NULL) {
-		PyErr_SetString(PyExc_TypeError, "id properties not supported for this type");
+		PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: id properties not supported for this type");
 		return -1;
 	}
 
@@ -1592,7 +1592,7 @@
 	IDProperty *group;
 
 	if(RNA_struct_idproperties_check(self->ptr.type)==0) {
-		PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct.keys(): this type doesn't support IDProperties");
 		return NULL;
 	}
 
@@ -1609,7 +1609,7 @@
 	IDProperty *group;
 
 	if(RNA_struct_idproperties_check(self->ptr.type)==0) {
-		PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct.items(): this type doesn't support IDProperties");
 		return NULL;
 	}
 
@@ -1627,7 +1627,7 @@
 	IDProperty *group;
 
 	if(RNA_struct_idproperties_check(self->ptr.type)==0) {
-		PyErr_SetString( PyExc_TypeError, "this type doesnt support IDProperties");
+		PyErr_SetString( PyExc_TypeError, "bpy_struct.values(): this type doesn't support IDProperties");
 		return NULL;
 	}
 
@@ -1647,31 +1647,31 @@
 	PropertyRNA *prop;
 
 	if (!PyArg_ParseTuple(args, "s|if", &path, &index, &cfra)) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list