I’m writing an addon which needs to ascertain the function of the UI element the mouse is over when one of the addon’s operators is executed.
For general information I can use:
print('ui area is', bpy.context.area.ui_type)
print('space type is', context.space_data.type)
print('workspace is',context.window.screen.name)
try:
spaceproperties = context.space_data.context
print('properties tab is',spaceproperties)
except:
print('no space data context')
#print('mode is',context.workspace.object_mode) not sure what this was
print('mode is',context.mode)
For some operators and properties I can use:
#try to copy the button data path, this will work if it's a property
try:
bpy.ops.ui.copy_data_path_button(full_path=False)
print('copy data path:',bpy.context.window_manager.clipboard)
except Exception as e:
print('could not copy the button data path\n',e,'\n')
#try to copy the python command
try:
bpy.ops.ui.copy_python_command_button()
print('copy python command button:',bpy.context.window_manager.clipboard)
except Exception as e:
print('could not get python command to clipboard\n',e, '\n')
But the real issue is that a lot of elements don’t work with the copy commands, for example if it’s a UI element which only has a description, or a menu item.
In other scenarios running the copy commands from the addon will return an incorrect context error message, whereas using ctrl C directly will successfully copy the command. For example pressing ctrl C whilst hovered over the 3d viewports object menu will return:
bpy.ops.wm.call_menu(name="VIEW3D_MT_object")
but running the copy command from the addon will return:
could not copy the button data path
Operator bpy.ops.ui.copy_data_path_button.poll() failed, context is incorrect
could not get python command to clipboard
Operator bpy.ops.ui.copy_python_command_button.poll() failed, context is incorrect
So what I think I need to do is somehow gather all of the tooltip information from the item under the mouse when my operator is executed (description, shortcut, and python command).
Does anyone know how to do this, or perhaps have an alternative approach for finding the function of the UI element the mouse is over when the operator is executed?
I did start brushing up my C++ skills which have been out of service for 20 odd years (and weren’t that great to begin with), so that I could try and create an API function to return the info I need, but it was taking too much time to try and figure out what exactly was going on under the hood. Perhaps if anyone could help with that?