PyAPI: support returning non ID types when accessing Context.property
Previously accessing properties without an associated ID would return None, even when the non-ID data was available. Ref !116981
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
Get the property associated with a hovered button.
|
Get the property associated with a hovered button.
|
||||||
Returns a tuple of the datablock, data path to the property, and array index.
|
Returns a tuple of the data-block, data path to the property, and array index.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
When the property doesn't have an associated :class:`bpy.types.ID` non-ID data may be returned.
|
||||||
|
This may occur when accessing windowing data, for example, operator properties.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Example inserting keyframe for the hovered property.
|
# Example inserting keyframe for the hovered property.
|
||||||
|
|||||||
@@ -1217,7 +1217,7 @@ context_type_map = {
|
|||||||
"particle_settings": ("ParticleSettings", False),
|
"particle_settings": ("ParticleSettings", False),
|
||||||
"particle_system": ("ParticleSystem", False),
|
"particle_system": ("ParticleSystem", False),
|
||||||
"particle_system_editable": ("ParticleSystem", False),
|
"particle_system_editable": ("ParticleSystem", False),
|
||||||
"property": ("(:class:`bpy.types.ID`, :class:`string`, :class:`int`)", False),
|
"property": ("(:class:`bpy.types.AnyType`, :class:`string`, :class:`int`)", False),
|
||||||
"pointcloud": ("PointCloud", False),
|
"pointcloud": ("PointCloud", False),
|
||||||
"pose_bone": ("PoseBone", False),
|
"pose_bone": ("PoseBone", False),
|
||||||
"pose_object": ("Object", False),
|
"pose_object": ("Object", False),
|
||||||
|
|||||||
@@ -4422,19 +4422,36 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CTX_DATA_TYPE_PROPERTY: {
|
case CTX_DATA_TYPE_PROPERTY: {
|
||||||
char *path_str = nullptr;
|
if (newprop != nullptr) {
|
||||||
if ((newprop != nullptr) && (newptr.owner_id != nullptr) &&
|
|
||||||
(path_str = RNA_path_from_ID_to_property(&newptr, newprop)))
|
|
||||||
{
|
|
||||||
/* Create pointer to parent ID, and path from ID to property. */
|
/* Create pointer to parent ID, and path from ID to property. */
|
||||||
PointerRNA idptr = RNA_id_pointer_create(newptr.owner_id);
|
PointerRNA idptr;
|
||||||
ret = PyTuple_New(3);
|
|
||||||
PyTuple_SET_ITEMS(ret,
|
|
||||||
pyrna_struct_CreatePyObject(&idptr),
|
|
||||||
PyUnicode_FromString(path_str),
|
|
||||||
PyLong_FromLong(newindex));
|
|
||||||
|
|
||||||
MEM_freeN(path_str);
|
PointerRNA *base_ptr;
|
||||||
|
char *path_str;
|
||||||
|
|
||||||
|
if (newptr.owner_id) {
|
||||||
|
idptr = RNA_id_pointer_create(newptr.owner_id);
|
||||||
|
path_str = RNA_path_from_ID_to_property(&idptr, newprop);
|
||||||
|
base_ptr = &idptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path_str = RNA_path_from_ptr_to_property_index(&newptr, newprop, 0, -1);
|
||||||
|
base_ptr = &newptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path_str) {
|
||||||
|
ret = PyTuple_New(3);
|
||||||
|
PyTuple_SET_ITEMS(ret,
|
||||||
|
pyrna_struct_CreatePyObject(base_ptr),
|
||||||
|
PyUnicode_FromString(path_str),
|
||||||
|
PyLong_FromLong(newindex));
|
||||||
|
|
||||||
|
MEM_freeN(path_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = Py_None;
|
||||||
|
Py_INCREF(ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ret = Py_None;
|
ret = Py_None;
|
||||||
|
|||||||
Reference in New Issue
Block a user