7
$\begingroup$

I'm confused about how to declare a panel.

I've tried to write a simple panel but it doesn't work:

class TestPanel(bpy.types.Panel):
    bl_idname = "object.test"
    bl_label = "test"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = 'sculptmode'
    bl_category = "test"

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

I would like which values can be used in bl_context

$\endgroup$

2 Answers 2

10
$\begingroup$

In you specific case, the bl_context you are looking for is sculpt_mode. There are many others including:

  • objectmode
  • mesh_edit
  • curve_edit
  • surface_edit
  • text_edit
  • armature_edit
  • mball_edit
  • lattice_edit
  • pose_mode
  • imagepaint
  • weightpaint
  • vertexpaint
  • particlemode
$\endgroup$
2
  • 2
    $\begingroup$ Handy list, the docs don't help much. . Is it worth noting what the equivalent Panel.poll(...) test would be, eg "objectmode" context.mode == 'OBJECT' $\endgroup$
    – batFINGER
    Jul 16, 2018 at 15:09
  • $\begingroup$ old question but, is there syntax for specifying multiple contexts at once? $\endgroup$ Mar 10 at 10:30
12
$\begingroup$

As this is not well documented you could query all existing panel properties like this:

import bpy
from bpy.types import Panel
from collections import defaultdict

def all_panels():
    for prop in dir(bpy.types):
        cls = getattr(bpy.types, prop)
        if hasattr(cls, "mro"):
            if Panel in cls.mro():
                yield cls
            
attrs = ["bl_space_type", "bl_region_type", "bl_context"]
options = defaultdict(lambda: set())

for panel in all_panels():
    for attr in attrs:
        if hasattr(panel, attr):
            value = getattr(panel, attr)
            options[attr].add(value)
        
for opt, values in options.items():
    print(60*"-")
    print(opt)
    print(values)

This will print these results:

bl_space_type
{'OUTLINER', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'VIEW_3D', 'FILE_BROWSER', 'TOPBAR', 'SEQUENCE_EDITOR', 'GRAPH_EDITOR', 'PROPERTIES', 'CLIP_EDITOR', 'PREFERENCES', 'IMAGE_EDITOR', 'TEXT_EDITOR', 'NODE_EDITOR'}
------------------------------------------------------------
bl_region_type
{'TOOL_PROPS', 'WINDOW', 'HEADER', 'UI', 'EXECUTE', 'TOOLS', 'NAVIGATION_BAR'}
------------------------------------------------------------
bl_context
{'object', 'interface', 'particle', '.paint_common', 'material', 'scene', '.vertexpaint', 'constraint', 'file_paths', 'data', 'physics', '.imagepaint_2d', 'save_load', '.mesh_edit', '.greasepencil_paint', '.posemode', '.imagepaint', '.objectmode', 'output', '.greasepencil_sculpt', 'system', 'input', 'world', '.paint_common_2d', 'render', 'editing', 'navigation', 'experimental', 'viewport', 'view_layer', '.armature_edit', '.greasepencil_vertex', 'modifier', 'addons', '.uv_sculpt', '.particlemode', 'animation', 'lights', 'shaderfx', 'keymap', 'bone_constraint', 'texture', 'bone', 'themes', '.weightpaint', '.sculpt_mode', '.greasepencil_weight'}
$\endgroup$

You must log in to answer this question.

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