Panel API Reference
blendcss.Panel is the primary entry point for creating Blender N-Panels. It generates a bpy.types.Panel, manages a shared GpuManager per addon_id, mounts a UICssDocument, and coordinates lifecycle hooks.
class blendcss.Panel
Blender metadata attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
addon_id | str | "blendcss" | Unique addon identifier. Panels sharing an addon_id share one GpuManager ({addon_id}.gpu_panel_handler). |
category | str | "blendcss" | N-Panel sidebar tab name (bl_category). |
label | str | "" | Panel header title (bl_label). Defaults to the class name if empty. |
idname | str | "" | Optional explicit bl_idname. Auto-synthesized as <ADDON>_PT_<class> when empty. |
space_type | str | 'VIEW_3D' | Blender editor space (bl_space_type). |
region_type | str | 'UI' | Blender region type (bl_region_type). |
context | str | "" | Optional bl_context (e.g. "objectmode", "mesh_edit"). |
parent_id | str | "" | Optional parent panel bl_idname to nest as a sub-panel. |
options | set | set() | Optional bl_options (e.g. {'DEFAULT_CLOSED'}). |
order | int | None | None | Optional bl_order controlling vertical sort order. |
Content & rendering attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
html | str | "" | Inline HTML/RML markup. |
css | str | "" | Inline CSS rules. |
html_file | str | None | None | Path to external .html file (relative to base_dir or the panel's .py file). |
css_file | str | None | None | Path to external .css file (relative to base_dir or the panel's .py file). |
base_dir | str | None | None | Base directory for resolving html_file, css_file, fonts, and images. Defaults to the module directory. |
default_styles | bool | True | Prepends DEFAULT_UI_CSS when using draw() or build(). Set to False for a blank stylesheet. |
min_height | float | 100.0 | Minimum reserved panel height in pixels. |
width | int | 240 | Initial document width (auto-adjusted when auto_width=True). |
height | int | 300 | Initial document height (auto-adjusted when auto_height=True). |
auto_width | bool | True | Automatically matches Blender's N-Panel width. |
auto_height | bool | True | Automatically measures content height and reserves space in Blender. |
anti_aliasing | bool | True | Enables single-pass SSAA offscreen rendering. |
scale | float | 4.0 | SSAA oversampling factor. |
hi_dpi | bool | True | Enables HiDPI scaling using Blender's UI scale (px → dp). |
dp_ratio | float | None | None | Optional manual dp_ratio override. |
sync_theme | bool | True | Live-syncs Blender --bl-* theme variables and Dark/Light rules. |
theme_overrides | dict | None | None | Optional dict overriding specific --bl-* CSS custom properties. |
Lifecycle hooks & methods
| Method | Signature | Description |
|---|---|---|
poll (classmethod) | poll(cls, context) -> bool | Return False to hide the panel conditionally. |
draw | draw(self, ui: UIBuilder, context) | Immediate-mode UI builder called on Blender redraws. Patches unchanged structure in place. |
build | build(self, ui: UIBuilder) | Retained-mode Python UI builder called once on mount and reload(). |
build_html | build_html(self) -> str | Override to return dynamically generated HTML markup. |
build_css | build_css(self) -> str | Override to return dynamically generated CSS rules. |
on_mount | on_mount(self, doc: UICssDocument) | Called once after the document loads (and again after reload()). |
on_sync | on_sync(self, context) | Called on Blender redraws before layout reservation to sync dynamic state. |
on_destroy | on_destroy(self) | Called right before the panel's document and canvas are torn down. |
reload | reload(self) | Hot-reloads HTML/CSS (from files or build methods), re-runs on_mount(), re-binds events, and syncs bindings. |
Instance properties & class helpers
panel.doc→ MountedUICssDocumentinstance.panel.canvas→GpuCanvasowning this panel's document.panel.manager→ SharedGpuManagerfor thisaddon_id.MyPanel.register()→ Registers this panel class (shorthand forblendcss.register(MyPanel)).MyPanel.unregister()→ Unregisters this panel class.MyPanel.instance()→ Returns the active mountedPanelinstance, orNone.MyPanel.bpy_panel()→ Returns the generatedbpy.types.Panelsubclass, orNone.
Registration & Decorator Functions
blendcss.register(*panel_classes)
Registers one or more blendcss.Panel subclasses (accepts variadic arguments or nested tuples/lists/sets). Re-registering an already registered panel cleanly unregisters the previous instance first. Returns the mounted Panel instance (or a list of instances when multiple classes are passed).
blendcss.unregister(*panel_classes)
Unregisters the specified blendcss.Panel subclasses and releases their GPU resources. When called with no arguments, unregisters all registered panels in reverse order. Automatically unregisters a shared GpuManager once its last panel is removed.
blendcss.get_panel(panel_cls)
Returns the active mounted Panel instance for panel_cls, or None if not registered.
@blendcss.on(elem_id: str, event: str = "click")
Decorator that binds a Panel method to a DOM element event on mount and after every reload(). Supports zero-argument methods (def on_click(self):) and one-argument methods (def on_click(self, ev):).
@blendcss.on("export_btn", "click")
def handle_export(self):
print("Export clicked")