diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-09-09 15:35:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-09-09 15:56:58 +0300 |
commit | 11a9434c2deed4f560f1c7381faf697f77b9de5c (patch) | |
tree | 2aed583aaa97d87234b72a83b11dc38a2569b388 /source/blender | |
parent | 3c3d0898b0c1a1d7da70f4a1778d4360b3cfe5c8 (diff) |
Resolve T52687: Add node label shows as 'Unknown'
Add type access method, need to extend to other types
for now just get node UI working properly again.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index c323366454e..398d2631f6c 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -70,6 +70,8 @@ #include "BKE_report.h" #include "BKE_idprop.h" +/* only for types */ +#include "BKE_node.h" #include "../generic/idprop_py_api.h" /* for IDprop lookups */ #include "../generic/py_capi_utils.h" @@ -3744,20 +3746,20 @@ static PyObject *pyrna_struct_bl_rna_find_subclass_recursive(PyObject *cls, cons return ret_test; } -PyDoc_STRVAR(pyrna_struct_bl_rna_get_subclass_doc, -".. classmethod:: bl_rna_get_subclass(id, default=None)\n" +PyDoc_STRVAR(pyrna_struct_bl_rna_get_subclass_py_doc, +".. classmethod:: bl_rna_get_subclass_py(id, default=None)\n" "\n" " :arg id: The RNA type identifier.\n" -" :type vector: string\n" +" :type id: string\n" " :return: The class or default when not found.\n" " :rtype: type\n" ); -static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args) +static PyObject *pyrna_struct_bl_rna_get_subclass_py(PyObject *cls, PyObject *args) { char *id; PyObject *ret_default = Py_None; - if (!PyArg_ParseTuple(args, "s|O:bl_rna_get_subclass", &id, &ret_default)) { + if (!PyArg_ParseTuple(args, "s|O:bl_rna_get_subclass_py", &id, &ret_default)) { return NULL; } PyObject *ret = pyrna_struct_bl_rna_find_subclass_recursive(cls, id); @@ -3767,6 +3769,50 @@ static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args) return Py_INCREF_RET(ret); } +PyDoc_STRVAR(pyrna_struct_bl_rna_get_subclass_doc, +".. classmethod:: bl_rna_get_subclass(id, default=None)\n" +"\n" +" :arg id: The RNA type identifier.\n" +" :type id: string\n" +" :return: The RNA type or default when not found.\n" +" :rtype: :class:`bpy.types.Struct` subclass\n" +); +static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args) +{ + char *id; + PyObject *ret_default = Py_None; + + if (!PyArg_ParseTuple(args, "s|O:bl_rna_get_subclass", &id, &ret_default)) { + return NULL; + } + + + const BPy_StructRNA *py_srna = (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject *)cls)->tp_dict, bpy_intern_str_bl_rna); + if (py_srna == NULL) { + PyErr_SetString(PyExc_ValueError, "Not a registered class"); + return NULL; + + } + const StructRNA *srna_base = py_srna->ptr.data; + + PointerRNA ptr; + if (srna_base == &RNA_Node) { + bNodeType *nt = nodeTypeFind(id); + if (nt) { + RNA_pointer_create(NULL, &RNA_Struct, nt->ext.srna, &ptr); + return pyrna_struct_CreatePyObject(&ptr); + } + } + else { + /* TODO, panels, menus etc. */ + PyErr_Format(PyExc_ValueError, "Class type \"%.200s\" not supported", + RNA_struct_identifier(srna_base)); + return NULL; + } + + return Py_INCREF_RET(ret_default); +} + static void pyrna_dir_members_py__add_keys(PyObject *list, PyObject *dict) { PyObject *list_tmp; @@ -5065,6 +5111,7 @@ static struct PyMethodDef pyrna_struct_methods[] = { {"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}, + {"bl_rna_get_subclass_py", (PyCFunction) pyrna_struct_bl_rna_get_subclass_py, METH_VARARGS | METH_CLASS, pyrna_struct_bl_rna_get_subclass_py_doc}, {"bl_rna_get_subclass", (PyCFunction) pyrna_struct_bl_rna_get_subclass, METH_VARARGS | METH_CLASS, pyrna_struct_bl_rna_get_subclass_doc}, {"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL}, |