4
$\begingroup$

I can write some text on the statusbar on the active workspace.

bpy.context.workspace.status_text_set("Hello World")

Setting statusbar text

Then I can reset to normal with

bpy.context.workspace.status_text_set(None)

Reset statusbar text

I would like to set and reset statusbar text on a different workspace. I would think that getting the different workspaces and calling the status_text_set method on them would work, but did not. E.g. with

bpy.data.workspaces[0]
bpy.data.workspaces[0].status_text_set("Hello World")

I reach the Animation workspace. But calling status_text_set on that workspace will not write on that statusbar, but on the active statusbar, presently the 'Scripting'.

Trying to set Animation workspace statusbar

Definitelly something wrong with my logic, but can someone enlighten me, how I could write and reset other workspaces?

(I would like to write some non-context related status message with a background process. If the user switches from workspace to workspace meanwhile, the text will appear there as well, but finally, when the process is over, I want to reset the statusbars, and it will do it only on the last active workspace statusbar.)

Thank you for your help. Happy Blending! z

$\endgroup$

2 Answers 2

4
$\begingroup$

Replace the draw() method of class STATUSBAR_HT_header

import bpy

def register():

    # testprop: change animation workspace from scripting statusbar
    bpy.types.Scene.status_test = bpy.props.BoolProperty(default=False , name="Change Animation Workspace")

    statusbar_draw = bpy.types.STATUSBAR_HT_header.draw   # original

    def draw_statusbar(self, context):                    # new layout
        layout = self.layout

        if context.workspace.name == 'Scripting':                               # original elements
            layout.label(text = "Status:")            
            layout.template_input_status()                                      # Status       
            layout.separator_spacer()          
            layout.prop(context.scene, 'status_test')
            layout.label(text = "Reports:")
            layout.template_reports_banner()                                    # Messages
            layout.template_running_jobs()                                      # Progress Bar
            layout.separator_spacer()          
            layout.label(text = "Stats:")
            row = layout.row()                
            row.alignment = 'RIGHT'            
            row.label(text=context.screen.statusbar_info(), translate=False)    # Stats & Info             
            layout.label(text = "* nothing more here *")            

        elif context.scene.status_test and context.workspace.name == 'Animation':
            layout.label(text = "Wow! ... I´m in the statusbar")

        else:
            statusbar_draw(self, context)  # original status bar

    bpy.types.STATUSBAR_HT_header.draw = draw_statusbar   # replace 
                    
def unregister():
    bpy.types.STATUSBAR_HT_header.draw = statusbar_draw   # reset

if __name__ == "__main__":
    register()
$\endgroup$
4
$\begingroup$

Use msgbus and subscribe to the workspace property of the window class: https://docs.blender.org/api/current/bpy.types.Window.html#bpy.types.Window.workspace

enter image description here

import bpy

handle = object()

# Triggers when widow's scene is changed
subscribe_to = bpy.types.Window, "workspace"

def notify_test(context):
    print(context.workspace.name)
    context.workspace.status_text_set("Hello: {}".format(context.workspace.name))

bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(bpy.context,),
    notify=notify_test,
)

bpy.msgbus.publish_rna(key=subscribe_to)

https://docs.blender.org/api/current/bpy.msgbus.html

How to get an event when an object is selected?

Msgbus - How to subscribe to bpy.context.scene?

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .