利用者:Koilz/13.03.12 Panel context
13.03.12 bl_context and poll
http://www.blender.org/documentation/blender_python_api_2_62_0/bpy.types.Panel.html
I did this with the bl_space_type 'VIEW_3D'.
This is a header for a Panel type.
class bpy.types.Panel(bpy_struct): bl_space_type = 'VIEW_3D' # Space Type: 'VIEW_3D' bl_region_type = 'TOOLS' # Region Type: 'TOOLS', 'UI' bl_context = 'objectmode' # 'TOOLS' 3D View Mode: 'objectmode', 'mesh_edit' bl_label = 'Tools' # Panel Name: 'Tools', 'My Panel' @classmethod def poll(cls, context): # poll return ((context.mode == 'OBJECT')) # 'UI' 3D View Mode: 'OBJECT', 'EDIT_MESH'
Before the Panel is drawn, it has methods to check if the context is correct.
DRAW_PANELS: if poll(): # (context.mode == 'EDIT_MESH') DRAW_PANEL()
The "Tools" Region 'TOOLS' uses bl_context.
The "Properties" Region 'UI' uses the return of poll:
bl_context 'objectmode' 'mesh_edit' 'armature_edit' 'posemode' bpy.context.mode 'OBJECT' 'EDIT_MESH' 'EDIT_ARMATURE' 'POSE'
// source\blender\blenkernel\intern\context.c static const char *data_mode_strings[] = { "mesh_edit", "curve_edit", "surface_edit", "text_edit", "armature_edit", "mball_edit", "lattice_edit", "posemode", "sculpt_mode", "weightpaint", "vertexpaint", "imagepaint", "particlemode", "objectmode", NULL };
// source\blender\makesrna\intern\rna_context.c static EnumPropertyItem mode_items[] = { {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""}, {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""}, {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""}, {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""}, {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""}, /* PARSKEL reuse will give issues */ {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""}, {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""}, {CTX_MODE_POSE, "POSE", 0, "Pose ", ""}, {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""}, {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""}, {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""}, {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""}, {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""}, {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""}, {0, NULL, 0, NULL, NULL} };
class bpy.types.Panel(bpy_struct) bl_context Type: string: "3D View Mode" default="" "mesh_edit" "curve_edit" "surface_edit" "text_edit" "armature_edit" "mball_edit" "lattice_edit" "posemode" "sculpt_mode" "weightpaint" "vertexpaint" "imagepaint" "particlemode" "objectmode" ...
class bpy.types.Panel(bpy_struct) classmethod poll(context) Return type: boolean: "3D View Mode + custom" commen (context.mode == 'EDIT_MESH') (context.mode == 'EDIT_CURVE') (context.mode == 'EDIT_SURFACE') (context.mode == 'EDIT_TEXT') (context.mode == 'EDIT_ARMATURE') (context.mode == 'EDIT_METABALL') (context.mode == 'EDIT_LATTICE') (context.mode == 'POSE') (context.mode == 'SCULPT') (context.mode == 'PAINT_WEIGHT') (context.mode == 'PAINT_VERTEX') (context.mode == 'PAINT_TEXTURE') (context.mode == 'PARTICLE') (context.mode == 'OBJECT') (context.my_ex_panel == 4) ...
bpy.data.screens['3D View Full'].areas[0].regions[2].type