If Edit Source fails, then it's created by a script on-the-fly (through PyConsole or Text Editor), or it's hardcoded in C - which is more likely the case. You won't find the panel subclasses in bpy.types
in the latter case, they aren't exposed to python.
I usually try to find similar panels or even other types via Auto-complete in the PyConsole, to figure out the naming scheme. Take the Grease Pencil panel for instance:
There is no bpy.types.GREASE*
, so no header, menu, panel or operator. A different name is used apparantly. We can also check for any type that contains "grease":
>>> [d for d in dir(bpy.types) if "grease" in d.lower()]
['BlendDataGreasePencils', 'CLIP_PT_tools_grease_pencil', 'GreasePencil', 'GreasePencilLayers']
Nothing useful in there, I would now try another part of the name or an abbreviation:
>>> [d for d in dir(bpy.types) if "pencil" in d.lower()]
['BlendDataGreasePencils', 'CLIP_PT_tools_grease_pencil', 'DOPESHEET_MT_gpencil_channel', 'DOPESHEET_MT_gpencil_frame', 'GPENCIL_OT_active_frame_delete', 'GPENCIL_OT_convert', 'GPENCIL_OT_data_add', 'GPENCIL_OT_data_unlink', 'GPENCIL_OT_draw', 'GPENCIL_OT_layer_add', 'GPencilFrame', 'GPencilFrames', 'GPencilLayer', 'GPencilStroke', 'GPencilStrokePoint', 'GPencilStrokePoints', 'GPencilStrokes', 'GreasePencil', 'GreasePencilLayers']
This revealed something useful: The naming scheme. Grease Pencil operators start with GPENCIL
.
Time to grep the Blender sources! GPENCIL_PT_
won't match anything, this kind of abstraction isn't really used in the C code. But we know there are buttons (=operators) drawn in the panel, so we can search for them and try to locate what adds them to the layout - GPENCIL_OT_
finds blender\source\blender\editors\gpencil\gpencil_buttons.c
among other files.
GPENCIL_OT_data_add
is the first match, on line 306 it reads:
uiTemplateID(col, C, ctx_ptr, "grease_pencil", "GPENCIL_OT_data_add", NULL, "GPENCIL_OT_data_unlink");
This is part of the function draw_gpencil_panel()
, this is defintely the right place.
UI widgets are directly added to the layout:
uiItemO(col, IFACE_("New Layer"), ICON_NONE, "GPENCIL_OT_layer_add");
This is obviously the C-equivalent of
col.operator("gpencil.layer_add", text="New Layer")
Some of the functions could probably be ported to python, but others can't. Take the 3D View layers widget for example: it draws nice little orange dots on the layers, which have at least one object on them. We couldn't do this nicely in python.