Setting up an operator to center the TOPBARMT_MENU on the active workspace tab bar region when it changes seems hard. The horizontal scroll position of the top menu bar is not available via bpy, at least not obviously to me or according to my searches so far. Is there an object or reference in bpy that would provide this info?
The following python code tries to mitigate, but does not solve, tab horizontal scroll position and tab position detection via bpy. With the bpy code here, when the active workspace changes via mouse click, its tab placement moves to the leftmost position.
However, Simulation.topbar_scroll_left() uses pyautogui to simulate mouse hover and mouse scroll wheel actions at the topbar to show the now-activated first tab – otherwise it may remain out of sight.
class TopbarTabTweak():
def __init__(self):
return
def rna_callback(**how_much):
# Via bpy:
bpy.ops.workspace.reorder_to_front()
# Not via bpy, not certain to put the first tab into
# a visible position if there are many tabs:
Simulation.topbar_scroll_left(how_much=100) # uses pyautogui
# Activates for input "workspace tab left mouse click".
# Not active for default Key Maps:
# Ctrl+PageUp, Ctrl+PageDown in User Preferences, Key Map,
# Screen, Screen (Global), screen.workspace_cycle([direction
# for direction in 'prev', 'next'])
return
def subscribe():
handle = object()
bpy.msgbus.subscribe_rna(
key=(bpy.types.Window, "workspace"),
owner=handle,
args=(), # Callback args
notify=TopbarTabTweak.rna_callback)
def unsubscribe(handle):
bpy.msgbus.clear_by_owner(handle)
return handle
pyautogui is not available to Blender’s Python by default. Blender ran in this case with PYTHONPATH=/usr/lib/python3.9 from bash with --python-use-system-env.
class Simulation():
def __init__(self):
pass
### move_mouse
# self was here but I took it out
def move_mouse(x=50, y=50, t=0.2): # must be float(x), float(y), float(t)
pyautogui.moveTo(x, y, t, pyautogui.easeOutQuint)
logging.debug(pyautogui)
return None
### topbar_scroll_right
def topbar_scroll_left(how_much=10):
logging.debug("scroll_left")
return pyautogui.scroll( how_much )
def topbar_scroll_right(how_much=10):
logging.debug("scroll_right")
return pyautogui.scroll( -how_much )
# pyautogui.hotkey("Ctrl", "PageDown")
# does the action but does not detect it.