3
$\begingroup$

The right click Header menu at the header is a C menu. I want to display the content in a Python menu. Like the View menu of the Text editor.

I can grab the operator, create my own class to execute it. And that way i can display the Flip to Top button. And it is fully functional. But how do i display the Collapse Menus prop with its checkbox? layout.operator is functional, but doesn't display the checkbox state. And layout.prop gives errors since i execute an operator, and don't have a prop involved here yet.

My problem is how the things needs to be connected, how the prop should look like. I cannot create a new prop here, it already exists. Or am i at the wrong track here? Maybe there is a direct way to grab this prop? As told it's a C menu, not Python.

The vital code parts are also marked green in the following screenshot:

class VIEW3D_MT_testheaderflip(bpy.types.Operator):
"""tooltip"""
bl_idname = "view3d.headerflip"
bl_label = "header flip"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):        # execute()
    bpy.ops.screen.header_flip()
    return {'FINISHED'}  
...

layout.operator("view3d.headerflip", text="headerflip")

enter image description here

$\endgroup$

2 Answers 2

2
$\begingroup$

Area.show_menus

Came across the property via @Leander comment on Get topbar area instance to toggle menus

enter image description here

Here it is appended to the view menu of the text editor. Notice it flitters top to bottom of menu when used

import bpy

context = bpy.context

def draw(self, context):
    layout = self.layout
    area = context.area
    layout.prop(area, "show_menus")
    
bpy.types.TEXT_MT_view.append(draw)

Operator

Not sure how to expose the property that indicates whether the header region menu is collapsed or not. You can however add the bpy.ops.screen.header_toolbox() operator to the view menu. This is the header menu that pops up when right clicking in Header.

Notice I've appended / prepended to the view menu class, rather than, (.. the slippery slope of), editing the UI py.

import bpy


def header_toolbox(self, context):
    layout = self.layout
    #layout.operator("screen.header_flip")
    layout.operator("screen.header_toolbox")

# prepend to 3d view view menu
bpy.types.VIEW3D_MT_view.prepend(header_toolbox)
# append text editor view menu
bpy.types.TEXT_MT_view.append(header_toolbox)
$\endgroup$
0
-1
$\begingroup$

is you want A REAL CHECKBOX you must have a property and use the "prop" option in layouts or columns:

example:

rd = context.scene.render            
layout.prop(rd, "use_overwrite")

or with columm:

rd = context.scene.render
split = layout.split()
col = split.column()
col.prop(rd, "use_overwrite")

p1 p2

*----------------------------------------------------------

if you see the properties option use another trick, use icons;

actually isn't a real checkbox, is only a icon that you can change:

icon

you should use something like:

layout.operator("view3d.headerflip", text="headerflip", icon="CHECKBOX_DEHLT")

in order to choose one specific icon, you must activate the "development icons addon"

development icons

$\endgroup$
1
  • $\begingroup$ Thanks yhoyo. The problem is, this specific menu item is not a prop, and it's in a C menu. layout.prop will not work here. Just layout.operator seems to do the trick. But without the checkbox. $\endgroup$
    – Tiles
    Commented Dec 28, 2016 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .