HIDE elements of the interface

As well as overriding classes, it may be simpler to override the draw method of UI elements like headers and panels.

When you right click and choose view source from any UI element it loads the appropriate UI script into the text editor. In the case of the view3d header, it will be space_view3d.py.

Here is a simple example that takes out the usual draw method, and sample code that shows you how to restore it.


import bpy
from bl_ui.space_view3d import VIEW3D_HT_header as V3DH
old_draw = V3DH.draw


from bpy.props import BoolProperty


def toggle_header(self, context):
    if not self.toggle_header:
        bpy.types.VIEW3D_HT_header.draw = my_draw
    else:
        bpy.types.VIEW3D_HT_header.draw = old_draw
        
bpy.types.WindowManager.toggle_header = BoolProperty(update=toggle_header)


def my_draw(self, context):
    layout = self.layout
    layout.prop(context.window_manager, "toggle_header", text="Restore Header", toggle=True)
    layout.label("XXXXXX")
    
bpy.types.VIEW3D_HT_header.draw = my_draw

The original draw method is in the space_view3d.py script here


class VIEW3D_HT_header(Header):
    bl_space_type = 'VIEW_3D'


    def draw(self, context):
        layout = self.layout


        view = context.space_data
        .....
        .....

2 Likes