I want to update a layout.label
based on a selected manipulator tool. I don't want to have it update on selection of object or change of interaction mode, rather, update when the tool has been changed.
tool: str = str()
@persistent
def tool_updated():
global tool
context = bpy.context
workspace = context.workspace.name
tools = bpy.data.workspaces[workspace].tools
active_tool = tools.from_space_view3d_mode(context.mode).idname
tool = ".".join(str(active_tool).split('.')[1:])
# check again once every second.
return 0.5
class InfoPanel(bpy.types.Panel):
bl_idname = "OBJECT_PT_InfoTools"
bl_label = "Info Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Info"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
self.layout.label(text="Blender Info Tools")
self.layout.label(text="Current Tool: {0}".format(tool)) # I want to update this each time the manipulator tool is changed... Move to Rotate to Scale to Crease to Transform, etc.
def register():
bpy.utils.register_class(InfoPanel)
bpy.app.timers.register(tool_updated)
def unregister():
bpy.utils.unregister_class(InfoPanel)
bpy.app.timers.unregister(tool_updated)
if __name__ == "__main__":
register()