Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks. This functionality is implemented for `PointerProperty` and now such properties can be created with Python. In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch. Original author: @artfunkel Alexander (Blend4Web Team) Reviewers: brecht, artfunkel, mont29, campbellbarton Reviewed By: mont29, campbellbarton Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne Maniphest Tasks: T37754 Differential Revision: https://developer.blender.org/D113
This commit is contained in:
@@ -1934,16 +1934,10 @@ static int pyrna_py_to_prop(
|
||||
}
|
||||
else {
|
||||
/* data == NULL, assign to RNA */
|
||||
if (value == Py_None) {
|
||||
PointerRNA valueptr = {{NULL}};
|
||||
RNA_property_pointer_set(ptr, prop, valueptr);
|
||||
}
|
||||
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
|
||||
RNA_property_pointer_set(ptr, prop, param->ptr);
|
||||
}
|
||||
else {
|
||||
if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type))
|
||||
RNA_property_pointer_set(ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr);
|
||||
else
|
||||
raise_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (raise_error) {
|
||||
@@ -3277,6 +3271,16 @@ static int pyrna_struct_ass_subscript(BPy_StructRNA *self, PyObject *key, PyObje
|
||||
return -1;
|
||||
}
|
||||
|
||||
BPy_StructRNA *val = (BPy_StructRNA *)value;
|
||||
if (val && self->ptr.type && val->ptr.type) {
|
||||
if (!RNA_struct_idprops_datablock_allowed(self->ptr.type) &&
|
||||
RNA_struct_idprops_contains_datablock(val->ptr.type))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: datablock id properties not supported for this type");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return BPy_Wrap_SetMapItem(group, key, value);
|
||||
}
|
||||
|
||||
@@ -6745,7 +6749,7 @@ PyObject *pyrna_id_CreatePyObject(ID *id)
|
||||
|
||||
bool pyrna_id_FromPyObject(PyObject *obj, ID **id)
|
||||
{
|
||||
if (BPy_StructRNA_Check(obj) && (RNA_struct_is_ID(((BPy_StructRNA *)obj)->ptr.type))) {
|
||||
if (pyrna_id_CheckPyObject(obj)) {
|
||||
*id = ((BPy_StructRNA *)obj)->ptr.id.data;
|
||||
return true;
|
||||
}
|
||||
@@ -6755,6 +6759,11 @@ bool pyrna_id_FromPyObject(PyObject *obj, ID **id)
|
||||
}
|
||||
}
|
||||
|
||||
bool pyrna_id_CheckPyObject(PyObject *obj)
|
||||
{
|
||||
return BPy_StructRNA_Check(obj) && (RNA_struct_is_ID(((BPy_StructRNA *) obj)->ptr.type));
|
||||
}
|
||||
|
||||
void BPY_rna_init(void)
|
||||
{
|
||||
#ifdef USE_MATHUTILS /* register mathutils callbacks, ok to run more than once. */
|
||||
@@ -7089,6 +7098,21 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
|
||||
args_fake = PyTuple_New(1);
|
||||
PyTuple_SET_ITEM(args_fake, 0, py_srna_cobject);
|
||||
|
||||
PyObject *type = PyDict_GetItemString(py_kw, "type");
|
||||
StructRNA *type_srna = srna_from_self(type, "");
|
||||
if (type_srna) {
|
||||
if (!RNA_struct_idprops_datablock_allowed(srna) &&
|
||||
(*(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_PointerProperty ||
|
||||
*(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_CollectionProperty) &&
|
||||
RNA_struct_idprops_contains_datablock(type_srna))
|
||||
{
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"bpy_struct \"%.200s\" doesn't support datablock properties \n",
|
||||
RNA_struct_identifier(srna));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
py_ret = PyObject_Call(py_func, args_fake, py_kw);
|
||||
|
||||
if (py_ret) {
|
||||
|
Reference in New Issue
Block a user