Delayed update of outliner ui on change of active collection #109995

Open
opened 2023-07-12 06:47:55 +02:00 by Andrej · 7 comments
Contributor

Blender 3.6

When you change active collection outliner UI updates only after you leave the outliner.
Attached short demo gif.

Way to reproduce the issue:

  1. Start default blender scene.
  2. Add new collection "Example"
  3. Run the script below in the text editor.
  4. Note that above the outliner you can see currently active collection, by default it's "Collection"
  5. Try to select "Example" instead of "Collection" - it won't update in the ui above.
  6. If you leave the outliner it will update the active collection.
  7. You can also try to choose some other collection and run operator to .tag_redraw() - F3 - Update Outliner. Note that info message that says that active collection didn't changed, it's just that outliner area wasn't updated.

What expected - outliner ui to update as you change active collection.

import bpy

def get_outliner_area(context):
    screen = context.screen
    for area in screen.areas:
        if area.type == "OUTLINER":
            return area

class EXAMPLE_OT_custom_collection_new(bpy.types.Operator):
    bl_idname = "example.redraw_outliner"
    bl_label = "Update outliner"
    def execute(self, context):
        before = context.collection.name
        area = get_outliner_area(context)
        area.tag_redraw()
        self.report({"INFO"}, f"{before} -> {context.collection.name}")

        return {'FINISHED'}

def context_draw_outliner_foobar_buttons(self, context):
    layout = self.layout
    layout.label(text=context.collection.name)
    layout.label(text=context.view_layer.active_layer_collection.name)
    layout.operator("example.redraw_outliner")

def register():
    bpy.utils.register_class(EXAMPLE_OT_custom_collection_new)
    bpy.types.OUTLINER_HT_header.append(context_draw_outliner_foobar_buttons)

def unregister():
    bpy.utils.unregister_class(EXAMPLE_OT_custom_collection_new)
    bpy.types.OUTLINER_HT_header.remove(context_draw_outliner_foobar_buttons)

if __name__ == "__main__":
    register()
Blender 3.6 When you change active collection outliner UI updates only after you leave the outliner. Attached short demo gif. Way to reproduce the issue: 1) Start default blender scene. 2) Add new collection "Example" 3) Run the script below in the text editor. 4) Note that above the outliner you can see currently active collection, by default it's "Collection" 5) Try to select "Example" instead of "Collection" - it won't update in the ui above. 6) If you leave the outliner it will update the active collection. 7) You can also try to choose some other collection and run operator to `.tag_redraw()` - F3 - Update Outliner. Note that info message that says that active collection didn't changed, it's just that outliner area wasn't updated. What expected - outliner ui to update as you change active collection. ```python import bpy def get_outliner_area(context): screen = context.screen for area in screen.areas: if area.type == "OUTLINER": return area class EXAMPLE_OT_custom_collection_new(bpy.types.Operator): bl_idname = "example.redraw_outliner" bl_label = "Update outliner" def execute(self, context): before = context.collection.name area = get_outliner_area(context) area.tag_redraw() self.report({"INFO"}, f"{before} -> {context.collection.name}") return {'FINISHED'} def context_draw_outliner_foobar_buttons(self, context): layout = self.layout layout.label(text=context.collection.name) layout.label(text=context.view_layer.active_layer_collection.name) layout.operator("example.redraw_outliner") def register(): bpy.utils.register_class(EXAMPLE_OT_custom_collection_new) bpy.types.OUTLINER_HT_header.append(context_draw_outliner_foobar_buttons) def unregister(): bpy.utils.unregister_class(EXAMPLE_OT_custom_collection_new) bpy.types.OUTLINER_HT_header.remove(context_draw_outliner_foobar_buttons) if __name__ == "__main__": register() ```
Andrej added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-07-12 06:47:55 +02:00
Member

Can replicate the behaviour, but I don't think this is a bug. Redraw tagging is done via notifier listeners internally, it's not "fully automatic" by nature.

Here in python you could refer to msgbus, and subscribe to current collection property, and update regions in the call back. Let us know if this worked for you. Thanks!

Can replicate the behaviour, but I don't think this is a bug. Redraw tagging is done via notifier listeners internally, it's not "fully automatic" by nature. Here in python you could refer to [msgbus](https://docs.blender.org/api/current/bpy.msgbus.html), and subscribe to current collection property, and update regions in the call back. Let us know if this worked for you. Thanks!
YimingWu added
Status
Needs Information from User
Interest
Python API
and removed
Status
Needs Triage
labels 2023-07-12 08:09:16 +02:00
Author
Contributor

@ChengduLittleA can you please help come up with example code how to subscribe to active collection using msgbus? Tried some options also mentioned here but it didn't worked.

@ChengduLittleA can you please help come up with example code how to subscribe to active collection using `msgbus`? Tried some options also mentioned [here ](https://blender.stackexchange.com/questions/276043/how-to-be-notified-when-the-active-collection-changes)but it didn't worked.
Member

Hi @Andrej730 Maybe Application handler could help?

Hi @Andrej730 Maybe [Application handler](https://blender.stackexchange.com/questions/274471/operator-that-runs-when-a-value-input-is-changed/274914#274914) could help?
Author
Contributor

@ChengduLittleA but checking depsgraph every update to support updating some area in outliner seems to be a bit an overkill.

@ChengduLittleA but checking depsgraph every update to support updating some area in outliner seems to be a bit an overkill.
Pratik Borhade added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2023-08-30 10:49:34 +02:00
Member

Since blender itself does not have the need to listen to the notifier in the header of the Outliner it just does not do it.
Like mentioned in the stackexchange link, handlers should work.

It could simply be added (as a feature request so to say), added a patch !111725

Agree this is not a bug though, maybe you could elaborate a bit on the usecase? Why would you want to place buttons/operators in the header that need this info? (this might make it easier to justify a redraw that blender itself does not need)

Since blender itself does not have the need to listen to the notifier in the header of the Outliner it just does not do it. Like mentioned in the stackexchange link, handlers should work. It could simply be added (as a feature request so to say), added a patch !111725 Agree this is not a bug though, maybe you could elaborate a bit on the usecase? Why would you want to place buttons/operators in the header that need this info? (this might make it easier to justify a redraw that blender itself does not need)
Philipp Oeser added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-08-31 10:17:58 +02:00
Author
Contributor

Agree this is not a bug though, maybe you could elaborate a bit on the usecase? Why would you want to place buttons/operators in the header that need this info? (this might make it easier to justify a redraw that blender itself does not need)

In my case I was trying to display there buttons that only make sense if some special folder is active (for example I had "Export" folder and operators were suppose to prepare the objects in that folder to export). I can also use it to show some other stats for the active folder.
I also found this when I was looking for a solution.

> Agree this is not a bug though, maybe you could elaborate a bit on the usecase? Why would you want to place buttons/operators in the header that need this info? (this might make it easier to justify a redraw that blender itself does not need) In my case I was trying to display there buttons that only make sense if some special folder is active (for example I had "Export" folder and operators were suppose to prepare the objects in that folder to export). I can also use it to show some other stats for the active folder. I also found [this ](https://stackoverflow.com/questions/70788910/blender-python-scripting-ui-how-to-refresh-outliner-header-when-a-different-co) when I was looking for a solution.
Member

OK, there has not been much of a reaction on !111725 (but will poke devs again if this could be merged).

Will leave this report open, but update its status.

OK, there has not been much of a reaction on !111725 (but will poke devs again if this could be merged). Will leave this report open, but update its status.
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#109995
No description provided.