Python: add Python API for layout panels #116949
No reviewers
Labels
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#116949
Loading…
Reference in New Issue
No description provided.
Delete Branch "JacquesLucke/blender:layout-panel-python"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This adds a Python API for layout panels that have been introduced in #113584. Two new methods on
UILayout
are added:.panel(idname, text="...", default_closed=False) -> Optional[UILayout]
.panel_prop(owner, prop_name, text="...") -> Optional[UILayout]
Both create a panel and return
None
if the panel is collapsed. The difference lies in how the open-close-state is stored. The first method internally manages the open-close-state based on the provided identifier. The second one allows for providing a boolean property that stores whether the panel is open. This is useful when creating a dynamic of panels and when it is difficult to create a unique idname.For the
.panel(...)
method, a new internal map onPanel
is created which keeps track of all the panel states based on the idname. Currently, there is no mechanism for freeing any elements once they have been added to the map. This is unlikely to cause a problem anytime soon, but we might need some kind of garbage collection in the future.@ -1051,0 +1072,4 @@
"UILayout",
"",
"Sub-layout to put items in. May be none in which case the panel collapsed");
RNA_def_function_return(func, parm);
How about
will be None if the panel is collapsed
. Seems less vague that way@ -1051,0 +1063,4 @@
func = RNA_def_function(srna, "panel", "rna_uiLayoutPanel");
RNA_def_function_ui_description(
func, "Sub-layout. Items placed in this sublayout are placed into a collapsable panel");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
Am I missing where the documentation for the
property
argument torna_uiLayoutPanel
is?I think this gets defined by
api_ui_item_rna_common
below.Oh, right. Might be worth adding it manually though, to give it a nice description
I think manually providing a boolean should be more the exception. Storing the state in the region would be consistent with most panels. I think that requires giving some subpanel idname instead.
I'm not sure if this should be handled through optional keyword arguments or different API functions. In #116646 the issue of adding buttons to the header layout also came up. This would probably be another API function that returns two values. So it would be good to think about what this would look like all together.
There should also be some API docs explaining this mechanism for storing the panel state in a boolean property, it's not obvious.
The API now supports creating layout panels using either just an idname or a custom boolean property.
Supporting showing a more complex layout in the panel header requires a bit more refactoring internally. I think it's a good thing to do, but a bit too much for this patch. Nevertheless, here are some ideas for how the API could work. Those ideas don't conflict with the API implemented in this patch, which should remain useful even if an additional API is added.
@ -1051,0 +1084,4 @@
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
api_ui_item_common_text(func);
RNA_def_boolean(func,
"open_by_default",
Why not match the naming and default value of regular panels, so
default_closed=False
?Mainly the different default behavior seems confusing to me.
@ -1051,0 +1099,4 @@
RNA_def_function_ui_description(
func,
"Similar to `.panel(...)` but instead of storing whether it is open or closed in the "
"region, it is stored in the provided boolean property. This can be used when creating a "
To me the reason would be more:
Generating a unique idname is not difficult, just not advisable for such cases.
I think just returning a tuple with two layouts would be simpler, where the body layout can be None if closed.
I haven't seen that before in Blender. How does one return a new tuple from a RNA function?
See
rna_Object_ray_cast
for an example.Thanks. Yes it seems fine to return both layouts in a tuple then.
I do still wonder whether you have an opinion on the two questions mentioned in the patch description.
I think the simplest thing from the API point of view would be to store it in the panel, which then also means you don't need strict idnames because they are automatically scoped to avoid conflicts.
It's not clear to me why there would be a difference in lifetime depending if it's in the region or panel.
@blender-bot build