# Get topbar area instance

Searching for a solution to

When using blender 2.8x on an old 4x3 monitor the workspace tabs get shifted too far right and its a handy option to collapse the menus.

For most, if not all, other area headers, this can be achieved by collapsing menus and saving the start up file.

For other editor types it can also be toggled via script by finding all header regions and passing that area via a context override to header toggle menus op

import bpy

for a in bpy.context.screen.areas:


to toggle menus in headers of all areas in screen. Or as pointed out by @Leander can set the area property directly

    a.show_menus = False


Alas the topbar area is not a part of the screen areas collection, nor have I found a way to reference it from windows or workspaces. There appears to be one instance of the topbar per main window opened.

Would prefer not to go down the slippery slope of patching the UI code directly. I build from source often and overwrite

This "orrible ack" adds a draw method to the topbar header that uses the driver namespace to store a reference to the area, toggle it, then remove the draw method.

import bpy
from bpy.app import driver_namespace as dns

def dummy_draw(self, context):
#self.layout.label(text="Foo")
dns["tba"] = context.area

bpy.types.TOPBAR_HT_upper_bar.prepend(dummy_draw)

while not dns.get("tba"):
continue


• Add context.area.show_menus = False at line 209 in scripts\startup\bl_ui\space_topbar.py. Or remove the first part of the if-else block completely, if you don't plan on opening that meun again. – Leander May 1 at 14:04
• @Leander cheers, using show_menus is much better than the op. Would prefer not to patch the UI code as it is overwritten by nightly build. The issue is can the topbar area be referenced from outside its context. Its not shown in screen areas or window or workspace AFAICT. Edited question. – batFINGER May 2 at 15:32