Python API: add bpy.context.property, for property under the mouse cursor

This can be useful for example to add custom operators to the property
context menu.

Pull Request: https://projects.blender.org/blender/blender/pulls/107280
This commit is contained in:
Josh Maros
2023-04-29 20:31:27 -07:00
committed by Brecht Van Lommel
parent ea937b304d
commit 6ba0346797
6 changed files with 88 additions and 5 deletions

View File

@@ -0,0 +1,10 @@
"""
Get the property associated with a hovered button.
Returns a tuple of the datablock, data path to the property, and array index.
"""
# Example inserting keyframe for the hovered property.
active_property = bpy.context.property
if active_property:
datablock, data_path, index = active_property
datablock.keyframe_insert(data_path=data_path, index=index, frame=1)

View File

@@ -1202,6 +1202,7 @@ context_type_map = {
"particle_settings": ("ParticleSettings", False),
"particle_system": ("ParticleSystem", False),
"particle_system_editable": ("ParticleSystem", False),
"property": ("(:class:`bpy.types.ID`, :class:`string`, :class:`int`)", False),
"pointcloud": ("PointCloud", False),
"pose_bone": ("PoseBone", False),
"pose_object": ("Object", False),
@@ -1347,7 +1348,11 @@ def pycontext2sphinx(basepath):
raise SystemExit(
"Error: context key %r not found in context_type_map; update %s" %
(member, __file__)) from None
fw(" :type: %s :class:`bpy.types.%s`\n\n" % ("sequence of " if is_seq else "", member_type))
if member_type.isidentifier():
member_type = ":class:`bpy.types.%s`" % member_type
fw(" :type: %s %s\n\n" % ("sequence of " if is_seq else "", member_type))
write_example_ref(" ", fw, "bpy.context." + member)
# Generate type-map:
# for member in sorted(unique_context_strings):