Add hovered property path to python context. #107280

Manually merged
Brecht Van Lommel merged 1 commits from joshm-2/blender:context_hovered_property into main 2023-05-26 21:54:36 +02:00
Contributor

Problem Addressed:

I frequently find myself adding small fade in/fade out animations to many different properties. I would like to make an addon that does this with a simple shortcut. I want it to work like the built-in Insert Keyframe operator, where I can hover over a property, press a button, and have the animation inserted. However, I currently have to resort to half-functional hacks to find what property is currently under the cursor. This would be much simpler if there were some way to get the currently hovered property using the Python interface.

Proposed Solution:

Add a property context.hovered_property which gives a string containing the path of the property currently under the user's mouse.

Alternative Solutions:

The property could possibly be placed somewhere else.

Limitations:

No known limitations.

Other comments:

Please let me know if any of the changes I made to make this work are undesirable. Namely, I had to modify bContextDataResult to be able to carry strings in addition to RNA pointers and lists.

# Problem Addressed: I frequently find myself adding small fade in/fade out animations to many different properties. I would like to make an addon that does this with a simple shortcut. I want it to work like the built-in Insert Keyframe operator, where I can hover over a property, press a button, and have the animation inserted. However, I currently have to resort to half-functional hacks to find what property is currently under the cursor. This would be much simpler if there were some way to get the currently hovered property using the Python interface. # Proposed Solution: Add a property `context.hovered_property` which gives a string containing the path of the property currently under the user's mouse. # Alternative Solutions: The property could possibly be placed somewhere else. # Limitations: No known limitations. # Other comments: Please let me know if any of the changes I made to make this work are undesirable. Namely, I had to modify `bContextDataResult` to be able to carry strings in addition to RNA pointers and lists.
Author
Contributor

@ideasman42 Would you be able to review this?

@ideasman42 Would you be able to review this?
Brecht Van Lommel requested changes 2023-04-28 17:58:40 +02:00
Brecht Van Lommel left a comment
Owner

The functionality seems useful. But it leaks memory, while it does free the string in the Python API code this can be used in other places too and each place having to free this manually is not the right solution.

Maybe instead add a CTX_DATA_TYPE_PROPERTY that stores a PropertyRNA *prop and int index, and then do the conversion to string in the Python API code?

It may also be more convenient to return this as a tuple id, data_path, index instead, since that is also what keyframe_insert needs.

I think perhaps just property would be a better name as well, since we don't use hovered anywhere else even though the screen/area/region behave similarly.

The functionality seems useful. But it leaks memory, while it does free the string in the Python API code this can be used in other places too and each place having to free this manually is not the right solution. Maybe instead add a `CTX_DATA_TYPE_PROPERTY` that stores a `PropertyRNA *prop` and `int index`, and then do the conversion to string in the Python API code? It may also be more convenient to return this as a tuple `id, data_path, index` instead, since that is also what `keyframe_insert` needs. I think perhaps just `property` would be a better name as well, since we don't use `hovered` anywhere else even though the screen/area/region behave similarly.
Contributor

Can't tell you how many times I've needed this feature when writing add-ons. Thank you Josh for doing it

Can't tell you how many times I've needed this feature when writing add-ons. Thank you Josh for doing it
Josh Maros force-pushed context_hovered_property from c44646193a to dc8a75ed77 2023-04-30 05:31:45 +02:00 Compare
Josh Maros requested review from Brecht Van Lommel 2023-04-30 05:34:51 +02:00
Author
Contributor

I agree with and have incorporated your feedback. What do I need to do to add this functionality to the docs?

I agree with and have incorporated your feedback. What do I need to do to add this functionality to the docs?
Author
Contributor

@brecht Since it has been a while I am realizing it may not have pinged you when I re-requested your review. Are you still available to provide feedback?

@brecht Since it has been a while I am realizing it may not have pinged you when I re-requested your review. Are you still available to provide feedback?
Brecht Van Lommel approved these changes 2023-05-26 20:00:01 +02:00
Brecht Van Lommel left a comment
Owner

Sorry for the delay. I will commit this with documentation and a fix for the memory leak.

Sorry for the delay. I will commit this with documentation and a fix for the memory leak.
@ -4380,0 +4395,4 @@
const PyObject *obj_ptr_py = pyrna_struct_CreatePyObject(&parentptr);
const PyObject *path_str_py = PyUnicode_FromString(path_str);
ret = PyTuple_Pack(3, obj_ptr_py, path_str_py, PyLong_FromLong(newindex));

This leaks memory, as PyTuple_Pack does not steal the reference. I'll change it PyTuple_SET_ITEMS which does.

This leaks memory, as `PyTuple_Pack` does not steal the reference. I'll change it `PyTuple_SET_ITEMS` which does.
Brecht Van Lommel manually merged commit 6ba0346797 into main 2023-05-26 21:54:36 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:36 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107280
No description provided.