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:
@@ -43,6 +43,9 @@
|
||||
|
||||
#include "python_utildefines.h"
|
||||
|
||||
extern bool pyrna_id_FromPyObject(PyObject *obj, ID **id);
|
||||
extern PyObject *pyrna_id_CreatePyObject(ID *id);
|
||||
extern bool pyrna_id_CheckPyObject(PyObject *obj);
|
||||
|
||||
/*********************** ID Property Main Wrapper Stuff ***************/
|
||||
|
||||
@@ -88,6 +91,11 @@ static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *
|
||||
return (PyObject *)group;
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_id(IDProperty *prop)
|
||||
{
|
||||
return pyrna_id_CreatePyObject(prop->data.pointer);
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
|
||||
{
|
||||
BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &BPy_IDArray_Type);
|
||||
@@ -148,6 +156,7 @@ PyObject *BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent)
|
||||
case IDP_GROUP: return idprop_py_from_idp_group(id, prop, parent);
|
||||
case IDP_ARRAY: return idprop_py_from_idp_array(id, prop);
|
||||
case IDP_IDPARRAY: return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */
|
||||
case IDP_ID: return idprop_py_from_idp_id(prop);
|
||||
default: Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
@@ -586,8 +595,15 @@ static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob)
|
||||
return prop;
|
||||
}
|
||||
|
||||
static IDProperty *idp_from_DatablockPointer(const char *name, PyObject *ob, IDPropertyTemplate *val)
|
||||
{
|
||||
pyrna_id_FromPyObject(ob, &val->id);
|
||||
return IDP_New(IDP_ID, val, name);
|
||||
}
|
||||
|
||||
static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob)
|
||||
{
|
||||
IDPropertyTemplate val = {0};
|
||||
const char *name = idp_try_read_name(name_obj);
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
@@ -608,6 +624,9 @@ static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob)
|
||||
else if (PySequence_Check(ob)) {
|
||||
return idp_from_PySequence(name, ob);
|
||||
}
|
||||
else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) {
|
||||
return idp_from_DatablockPointer(name, ob, &val);
|
||||
}
|
||||
else if (PyMapping_Check(ob)) {
|
||||
return idp_from_PyMapping(name, ob);
|
||||
}
|
||||
@@ -732,6 +751,8 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
return idprop_py_from_idp_float(prop);
|
||||
case IDP_DOUBLE:
|
||||
return idprop_py_from_idp_double(prop);
|
||||
case IDP_ID:
|
||||
return idprop_py_from_idp_id(prop);
|
||||
case IDP_ARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len);
|
||||
|
Reference in New Issue
Block a user