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
path: root/source
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-02-11 19:06:09 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-02-11 19:13:16 +0300
commitf60b4228b929ce4d77187a5bbe52f74df2c3315e (patch)
tree51f79ecf42e79190d366fe573b96313fda031ff5 /source
parentcde1ef403b034084be6d9fb7887cf8ab7c73a524 (diff)
BPY RNA: add `is_property_readonly()`.
This property may be defined dynamically, so mere access to static flag value through `bl_rna.properties[...].is_readonly` is not enough.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/intern/bpy_rna.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 592150239be..fadc50e3317 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3184,6 +3184,34 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
return PyBool_FromLong(RNA_property_flag(prop) & PROP_HIDDEN);
}
+PyDoc_STRVAR(pyrna_struct_is_property_readonly_doc,
+".. method:: is_property_readonly(property)\n"
+"\n"
+" Check if a property is readonly.\n"
+"\n"
+" :return: True when the property is readonly (not writable).\n"
+" :rtype: boolean\n"
+);
+static PyObject *pyrna_struct_is_property_readonly(BPy_StructRNA *self, PyObject *args)
+{
+ PropertyRNA *prop;
+ const char *name;
+
+ PYRNA_STRUCT_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "s:is_property_readonly", &name))
+ return NULL;
+
+ if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.is_property_readonly(\"%.200s\") not found",
+ RNA_struct_identifier(self->ptr.type), name);
+ return NULL;
+ }
+
+ return PyBool_FromLong(!RNA_property_editable(&self->ptr, prop));
+}
+
PyDoc_STRVAR(pyrna_struct_path_resolve_doc,
".. method:: path_resolve(path, coerce=True)\n"
"\n"
@@ -4676,6 +4704,7 @@ static struct PyMethodDef pyrna_struct_methods[] = {
{"is_property_set", (PyCFunction)pyrna_struct_is_property_set, METH_VARARGS, pyrna_struct_is_property_set_doc},
{"property_unset", (PyCFunction)pyrna_struct_property_unset, METH_VARARGS, pyrna_struct_property_unset_doc},
{"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, pyrna_struct_is_property_hidden_doc},
+ {"is_property_readonly", (PyCFunction)pyrna_struct_is_property_readonly, METH_VARARGS, pyrna_struct_is_property_readonly_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},
{"type_recast", (PyCFunction)pyrna_struct_type_recast, METH_NOARGS, pyrna_struct_type_recast_doc},