UI Button Placeholder not behaving as expected #124187

Closed
opened 2024-07-04 19:16:05 +02:00 by Zach Eastin · 4 comments

System Information
Operating system: Windows-10-10.0.22621-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 555.99

Blender Version
Broken: version: 4.2.0 Beta, branch: blender-v4.2-release, commit date: 2024-06-30 21:17, hash: 549024b1cc34
Worked: N/A

Short description of error
For layout.prop when placeholder="" no placeholder is shown and None is not allowed to be passed.

Use Case
I suppose this isn't a bug as maybe it is the expected behavior as coded, however, this does limit its use and is unlike some of the other keywords' behavior. Often times I want to show a node's inputs in the viewport. So instead of writing out the same code over and over I'll make a function:

inps = node.inputs
def draw_input(layout, inp_id, text=None, toggle=-1, emboss=True, placeholder="", icon="NONE", icon_value=0):
    layout.prop(inps[inp_id], "default_value", text=text, toggle=toggle, emboss=emboss, placeholder=placeholder, icon=icon, icon_value=icon_value)

Now for placeholder if I pass "" as the placeholder no placeholder shows up. And if I pass None it throws an error:

TypeError: UILayout.prop(): error with keyword argument "placeholder" -  Function.placeholder doesn't support None from string types

The text keyword works this way ("" results in no label but None results in default behavior) and I would have assumed placeholder would too.

Exact steps for others to reproduce the error
Open up the attached blend file.
Run the script. Look for the Test panel in the Debug tab in the 3D Viewport.
You'll notice only 3 of the 4 search inputs appear with the 4th throwing errors.

**System Information** Operating system: Windows-10-10.0.22621-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 555.99 **Blender Version** Broken: version: 4.2.0 Beta, branch: blender-v4.2-release, commit date: 2024-06-30 21:17, hash: `549024b1cc34` Worked: N/A **Short description of error** For `layout.prop` when `placeholder=""` no placeholder is shown and `None` is not allowed to be passed. **Use Case** I suppose this isn't a bug as maybe it is the expected behavior as coded, however, this does limit its use and is unlike some of the other keywords' behavior. Often times I want to show a node's inputs in the viewport. So instead of writing out the same code over and over I'll make a function: ```py inps = node.inputs def draw_input(layout, inp_id, text=None, toggle=-1, emboss=True, placeholder="", icon="NONE", icon_value=0): layout.prop(inps[inp_id], "default_value", text=text, toggle=toggle, emboss=emboss, placeholder=placeholder, icon=icon, icon_value=icon_value) ``` Now for `placeholder` if I pass `""` as the placeholder no placeholder shows up. And if I pass `None` it throws an error: ```prolog TypeError: UILayout.prop(): error with keyword argument "placeholder" - Function.placeholder doesn't support None from string types ``` The text keyword works this way (`""` results in no label but `None` results in default behavior) and I would have assumed placeholder would too. **Exact steps for others to reproduce the error** Open up the attached blend file. Run the script. Look for the Test panel in the Debug tab in the 3D Viewport. You'll notice only 3 of the 4 search inputs appear with the 4th throwing errors.
Zach Eastin added the
Type
Report
Severity
Normal
Status
Needs Triage
labels 2024-07-04 19:16:06 +02:00
Bart van der Braak added
Type
Bug
and removed
Type
Report
labels 2024-08-14 12:57:52 +02:00
Member

Hi, thanks for the report. Can confirm, checking

Hi, thanks for the report. Can confirm, checking
Member

Quick workaround:

diff --git a/source/blender/makesrna/intern/rna_ui_api.cc b/source/blender/makesrna/intern/rna_ui_api.cc
index 44821235742..c1851324ff8 100644
--- a/source/blender/makesrna/intern/rna_ui_api.cc
+++ b/source/blender/makesrna/intern/rna_ui_api.cc
@@ -1332,8 +1332,9 @@ void RNA_api_ui_layout(StructRNA *srna)
                                   "Item. Exposes an RNA item and places it into the layout.");
   api_ui_item_rna_common(func);
   api_ui_item_common(func);
-  RNA_def_string(
+  PropertyRNA *prop = RNA_def_string(
       func, "placeholder", nullptr, 0, "", "Hint describing the expected value when empty");
+  RNA_def_property_clear_flag(prop, PROP_NEVER_NULL);
   RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail");
   RNA_def_boolean(func, "slider", false, "", "Use slider widget for numeric values");
   RNA_def_int(func,

But passing none/null will draw id name in placeholder ("Object" in your case), see:

const char *ui_but_placeholder_get(uiBut *but)
{
const char *placeholder = (but->placeholder) ? but->placeholder : nullptr;
if (!placeholder && but->rnaprop) {
if (but->type == UI_BTYPE_SEARCH_MENU) {
StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop);
const short idcode = RNA_type_to_ID_code(type);
if (idcode != 0) {
RNA_enum_name(rna_enum_id_type_items, idcode, &placeholder);
placeholder = CTX_IFACE_(BLT_I18NCONTEXT_ID_ID, placeholder);
}

@Harley hi, do you think passing "None" should be supported here?

Quick workaround: ```Diff diff --git a/source/blender/makesrna/intern/rna_ui_api.cc b/source/blender/makesrna/intern/rna_ui_api.cc index 44821235742..c1851324ff8 100644 --- a/source/blender/makesrna/intern/rna_ui_api.cc +++ b/source/blender/makesrna/intern/rna_ui_api.cc @@ -1332,8 +1332,9 @@ void RNA_api_ui_layout(StructRNA *srna) "Item. Exposes an RNA item and places it into the layout."); api_ui_item_rna_common(func); api_ui_item_common(func); - RNA_def_string( + PropertyRNA *prop = RNA_def_string( func, "placeholder", nullptr, 0, "", "Hint describing the expected value when empty"); + RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail"); RNA_def_boolean(func, "slider", false, "", "Use slider widget for numeric values"); RNA_def_int(func, ``` But passing none/null will draw id name in placeholder ("Object" in your case), see: https://projects.blender.org/blender/blender/src/commit/a2d6808a7a0ddcc3d7995a52faf231f139cc6423/source/blender/editors/interface/interface.cc#L5748-L5759 @Harley hi, do you think passing "None" should be supported here?
Member

@PratikPB2123 - hi, do you think passing "None" should be supported here?

That was the intention with this. I just didn't realize that PROP_NEVER_NULL would be set and stop this from working from Python.

So yes, this is a bug and your workaround is the fix.

> @PratikPB2123 - hi, do you think passing "None" should be supported here? That was the intention with this. I just didn't realize that PROP_NEVER_NULL would be set and stop this from working from Python. So yes, this is a bug and your workaround is the fix.
Member

Thanks. Then I think I'll make PR tomorrow :)

Thanks. Then I think I'll make PR tomorrow :)
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-08-20 01:03:18 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#124187
No description provided.