I want to write a function, which will be called after changing the workspace.
I thought, that i can find workspace change event in bpy.app.handlers, but it looks like where is no such handler here… What can I do?
I want to write a function, which will be called after changing the workspace.
I thought, that i can find workspace change event in bpy.app.handlers, but it looks like where is no such handler here… What can I do?
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
import bpy
handle = object()
Triggers when window's workspace 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)
Output:
Layout
Scripting
Texture Paint
...
https://docs.blender.org/api/current/bpy.msgbus.html
context.workspace is None.. and overriding the context will be no use in this case. If not and it is like the window manager it will work. – batFINGER Apr 03 '19 at 11:13