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.
This commit is contained in:
Campbell Barton 2017-09-09 22:35:33 +10:00
parent 3c3d0898b0
commit 11a9434c2d
Notes: blender-bot 2023-02-14 07:49:06 +01:00
Referenced by issue #52703, classroom scene is much brighter after 24 August
Referenced by issue #52696, Sculpt: Brush spacing pressure artifacts
Referenced by issue #52697, Video import/export via FFmpeg: Poor-quality color conversion causes banding
Referenced by issue #52699, Cycles: Denoising generates artifact(s)
Referenced by issue #52700, No Splash Screen option in the help menu
Referenced by issue #52687, Almost all fields for add nodes in compositor listed as "unknown"
Referenced by issue #48684, Circular/radial bands in this hair scene (most noticeable in CPU)
2 changed files with 60 additions and 13 deletions

View File

@ -59,9 +59,9 @@ class NodeItem:
return self._label
else:
# if no custom label is defined, fall back to the node type UI name
cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
if cls is not None:
return cls.bl_rna.name
bl_rna = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
if bl_rna is not None:
return bl_rna.name
else:
return "Unknown"
@ -71,9 +71,9 @@ class NodeItem:
return bpy.app.translations.contexts.default
else:
# if no custom label is defined, fall back to the node type UI name
cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
if cls is not None:
return cls.bl_rna.translation_context
bl_rna = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
if bl_rna is not None:
return bl_rna.translation_context
else:
return bpy.app.translations.contexts.default

View File

@ -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,13 +3746,36 @@ static PyObject *pyrna_struct_bl_rna_find_subclass_recursive(PyObject *cls, cons
return ret_test;
}
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 id: string\n"
" :return: The class or default when not found.\n"
" :rtype: type\n"
);
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_py", &id, &ret_default)) {
return NULL;
}
PyObject *ret = pyrna_struct_bl_rna_find_subclass_recursive(cls, id);
if (ret == NULL) {
ret = ret_default;
}
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 vector: string\n"
" :return: The class or default when not found.\n"
" :rtype: type\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)
{
@ -3760,11 +3785,32 @@ static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args)
if (!PyArg_ParseTuple(args, "s|O:bl_rna_get_subclass", &id, &ret_default)) {
return NULL;
}
PyObject *ret = pyrna_struct_bl_rna_find_subclass_recursive(cls, id);
if (ret == NULL) {
ret = ret_default;
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;
}
return Py_INCREF_RET(ret);
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)
@ -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},