Some icons cannot be overriden from python (e.g. 'Constraint.mute', 'use_fake_user') #97909

Open
opened 2022-05-06 15:49:21 +02:00 by Demeter Dzadik · 9 comments
Member

Blender Version
Broken: version: 3.3.0 Alpha, branch: master, commit date: 2022-05-06 11:54, hash: c7bffc8fa2
Worked: Looks like this was once working in 2.80 (but has stopped working in 2.81)

Short description of error
Some boolean properties apply an offset to their icon depending on the state of the boolean. This offset is applied even when an icon override is used, like so: UILayout.prop(icon=whatever).

Workaround

def get_icon_value(icon_name: str) -> int:
    icon_items = bpy.types.UILayout.bl_rna.functions["prop"].parameters["icon"].enum_items.items()
    icon_dict = {tup[1].identifier : tup[1].value for tup in icon_items}

    return icon_dict[icon_name]

def draw_with_icon_fix(layout, prop_owner, prop_name, icon: str, offset=1, invert_checkbox=False, **kwargs):
    """Drawing some booleans in the UI with a custom icon can be 
    annoying because Blender might offset the icon based on the boolean state.
    You can use this function to counter that offset. To find the offset, you have to 
    trial and error, it's either 1 or -1. (Or 0 but then you don't need this)
    """

    bool_value = getattr(prop_owner, prop_name)
    offset = offset * int(bool_value)
    if invert_checkbox:
        offset = 1 - offset
    icon_value = get_icon_value(icon) + offset
    layout.prop(prop_owner, prop_name, icon_value=icon_value, invert_checkbox=invert_checkbox, **kwargs)

Exact steps for others to reproduce the error

  • File with script within: icon_madness.blend
  • Script should self-execute, look for a "FixMe" panel in the sidebar.
    image.png

So this file works in 2.80 and is broken in 2.81:
icon_madness_2.blend

**Blender Version** Broken: version: 3.3.0 Alpha, branch: master, commit date: 2022-05-06 11:54, hash: `c7bffc8fa2` Worked: Looks like this was once working in 2.80 (but has stopped working in 2.81) **Short description of error** Some boolean properties apply an offset to their icon depending on the state of the boolean. This offset is applied even when an icon override is used, like so: `UILayout.prop(icon=whatever)`. **Workaround** ```python def get_icon_value(icon_name: str) -> int: icon_items = bpy.types.UILayout.bl_rna.functions["prop"].parameters["icon"].enum_items.items() icon_dict = {tup[1].identifier : tup[1].value for tup in icon_items} return icon_dict[icon_name] def draw_with_icon_fix(layout, prop_owner, prop_name, icon: str, offset=1, invert_checkbox=False, **kwargs): """Drawing some booleans in the UI with a custom icon can be annoying because Blender might offset the icon based on the boolean state. You can use this function to counter that offset. To find the offset, you have to trial and error, it's either 1 or -1. (Or 0 but then you don't need this) """ bool_value = getattr(prop_owner, prop_name) offset = offset * int(bool_value) if invert_checkbox: offset = 1 - offset icon_value = get_icon_value(icon) + offset layout.prop(prop_owner, prop_name, icon_value=icon_value, invert_checkbox=invert_checkbox, **kwargs) ``` **Exact steps for others to reproduce the error** - File with script within: [icon_madness.blend](https://archive.blender.org/developer/F13054802/icon_madness.blend) - Script should self-execute, look for a "FixMe" panel in the sidebar. ![image.png](https://archive.blender.org/developer/F13054803/image.png) So this file works in 2.80 and is broken in 2.81: [icon_madness_2.blend](https://archive.blender.org/developer/F13054848/icon_madness_2.blend)
Author
Member

Found a workaround, added to the task description.

Found a workaround, added to the task description.
Member

Can confirm.
Looks like this was once working in 2.80 (but has stopped working in 2.81)

Can confirm. Looks like this was once working in 2.80 (but has stopped working in 2.81)
Member

Could it additionally be related to #93987?
So mute vs enabled?

Could it additionally be related to #93987? So `mute` vs `enabled`?
Member

In #97909#1353217, @lichtwerk wrote:
Can confirm.
Looks like this was once working in 2.80 (but has stopped working in 2.81)

So this file works in 2.80 and is broken in 2.81:
icon_madness_2.blend

> In #97909#1353217, @lichtwerk wrote: > Can confirm. > Looks like this was once working in 2.80 (but has stopped working in 2.81) So this file works in 2.80 and is broken in 2.81: [icon_madness_2.blend](https://archive.blender.org/developer/F13054848/icon_madness_2.blend)
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:22:07 +01:00

Checkboxes (toggles are more correct) change the icon automatically to represent the on/off state.
It simply selects the next defined icon. PROP_ICONS_CONSECUTIVE
But for hide/show properties it selects the previous icon. UI_BUT_ICON_REVERSE
That's what you're seeing.

So there are three different checkboxes: "no icon", "consecutive" and "reverse consecutive" icon.
It's very confusing, but in general I don't see a bug in any of these cases.

Generally, you should not override default icons, in order not to confuse users.

#97909, #109080, #111366
CC @ChengduLittleA @PratikPB2123 @lichtwerk

Checkboxes (toggles are more correct) change the icon automatically to represent the on/off state. It simply selects the next defined icon. `PROP_ICONS_CONSECUTIVE` But for hide/show properties it selects the previous icon. `UI_BUT_ICON_REVERSE` That's what you're seeing. So there are three different checkboxes: "no icon", "consecutive" and "reverse consecutive" icon. It's very confusing, but in general I don't see a bug in any of these cases. **Generally, you should not override default icons, in order not to confuse users.** #97909, #109080, #111366 CC @ChengduLittleA @PratikPB2123 @lichtwerk
Author
Member

So there are three different checkboxes: "no icon", "consecutive" and "reverse consecutive" icon.

Feels like it would be easier to just pass around 2 icons, one for each state.

Generally, you should not override default icons, in order not to confuse users.

In my use case, without icon overriding, I'm going to have 3 identical looking icons next to each other; One for each of CopyLoc, CopyRot, CopyScale constraint.

I still think the fact that icon overriding is done before the offset rather than after is a bug, otherwise it's not really an override. I don't see why anyone coding it would've had such an intention, especially when it worked fine in 2.80.

> So there are three different checkboxes: "no icon", "consecutive" and "reverse consecutive" icon. Feels like it would be easier to just pass around 2 icons, one for each state. > Generally, you should not override default icons, in order not to confuse users. In my use case, without icon overriding, I'm going to have 3 identical looking icons next to each other; One for each of CopyLoc, CopyRot, CopyScale constraint. I still think the fact that icon overriding is done before the offset rather than after is a bug, otherwise it's not really an override. I don't see why anyone coding it would've had such an intention, especially when it worked fine in 2.80.

You can see the same behavior in 2.8 as well, try the code from #109080. What has changed is that an icon has been added to Disable Constraint property. bf95ab6bb2

It's always been in Blender, it's not a bug, it's a feature to change icon of toggles. I don't want to say it can't be changed, I'm just saying it's intentional, and it's being used all over the place.

You can see the same behavior in 2.8 as well, try the code from #109080. What has changed is that an icon has been added to Disable Constraint property. bf95ab6bb2 It's always been in Blender, it's not a bug, it's a feature to change icon of toggles. I don't want to say it can't be changed, I'm just saying it's intentional, and it's being used all over the place.
Member

Thx checking @jenkm !

Will change to TODO then.

Thx checking @jenkm ! Will change to TODO then.
Philipp Oeser changed title from Drawing Constraint.mute in the UI with custom icon shows wrong icon to Some icons cannot be overriden from python (e.g. 'Constraint.mute', 'use_fake_user') 2023-08-23 09:13:57 +02:00
Author
Member

Is this essentially a "won't fix"? Genuinely asking, so I know not to hold my breath or pester people further about this. I was expecting it to be a 5 minute fix for someone in the know, but if it turns out it's a massive rabbit hole then I understand.

I'll also edit the workaround into the task description to make it more visible for people who might encounter this issue in future.

Is this essentially a "won't fix"? Genuinely asking, so I know not to hold my breath or pester people further about this. I was expecting it to be a 5 minute fix for someone in the know, but if it turns out it's a massive rabbit hole then I understand. I'll also edit the workaround into the task description to make it more visible for people who might encounter this issue in future.
Sign in to join this conversation.
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#97909
No description provided.