When I click on the "new" button, some panels that were disabled appear. I read their code, but I didn't understand. How do I get certain panels to appear when I click a button?
It's a panels poll method
The panels are defined and sitting there polling away, waiting to "show".
The poll classmethod of a panel returns true only when the required context (or otherwise related) conditions are met
Hide Panel With Python ("A Duality Duplicate")
In example displayed in question :
(Speculating haven't checked (...lately), Turn on Developer Extras in settings, so can right click on 99% of UI, view source and see how its done... a common practice is to)
Have one master materials panel, that always polls. In this case the material slots, no panel header, has the option to add a material.
All the others seen are , subpanels ie Panels with their parent set to the master panel, or others in the space, that have poll requirements met.
In the properties space, there is a sort of "polling" option available by setting
bl_context of the panel class to match that of the properties space context, matching the 'OBJECT', 'SCENE', 'RENDER' tabs.
These subpanels only poll when there is a
context.material (In properties space there is a material context member, most likely
context.material == context.object.active_material
When all the panels require the same poll it is common to see a mixin base class
class SomePanelBase: bl_context = 'MATERIAL' @classmethod def poll(cls, context): return context.material is not None
And for any defined panel
class MaterialFooPanel(SomePanelBase, bpy.types.Panel): ...
making any such defined panels only display if there is an active material.