Skip to content

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 ​

AttributeTypeDefaultDescription
addon_idstr"blendcss"Unique addon identifier. Panels sharing an addon_id share one GpuManager ({addon_id}.gpu_panel_handler).
categorystr"blendcss"N-Panel sidebar tab name (bl_category).
labelstr""Panel header title (bl_label). Defaults to the class name if empty.
idnamestr""Optional explicit bl_idname. Auto-synthesized as <ADDON>_PT_<class> when empty.
space_typestr'VIEW_3D'Blender editor space (bl_space_type).
region_typestr'UI'Blender region type (bl_region_type).
contextstr""Optional bl_context (e.g. "objectmode", "mesh_edit").
parent_idstr""Optional parent panel bl_idname to nest as a sub-panel.
optionssetset()Optional bl_options (e.g. {'DEFAULT_CLOSED'}).
orderint | NoneNoneOptional bl_order controlling vertical sort order.

Content & rendering attributes ​

AttributeTypeDefaultDescription
htmlstr""Inline HTML/RML markup.
cssstr""Inline CSS rules.
html_filestr | NoneNonePath to external .html file (relative to base_dir or the panel's .py file).
css_filestr | NoneNonePath to external .css file (relative to base_dir or the panel's .py file).
base_dirstr | NoneNoneBase directory for resolving html_file, css_file, fonts, and images. Defaults to the module directory.
default_stylesboolTruePrepends DEFAULT_UI_CSS when using draw() or build(). Set to False for a blank stylesheet.
min_heightfloat100.0Minimum reserved panel height in pixels.
widthint240Initial document width (auto-adjusted when auto_width=True).
heightint300Initial document height (auto-adjusted when auto_height=True).
auto_widthboolTrueAutomatically matches Blender's N-Panel width.
auto_heightboolTrueAutomatically measures content height and reserves space in Blender.
anti_aliasingboolTrueEnables single-pass SSAA offscreen rendering.
scalefloat4.0SSAA oversampling factor.
hi_dpiboolTrueEnables HiDPI scaling using Blender's UI scale (px → dp).
dp_ratiofloat | NoneNoneOptional manual dp_ratio override.
sync_themeboolTrueLive-syncs Blender --bl-* theme variables and Dark/Light rules.
theme_overridesdict | NoneNoneOptional dict overriding specific --bl-* CSS custom properties.

Lifecycle hooks & methods ​

MethodSignatureDescription
poll (classmethod)poll(cls, context) -> boolReturn False to hide the panel conditionally.
drawdraw(self, ui: UIBuilder, context)Immediate-mode UI builder called on Blender redraws. Patches unchanged structure in place.
buildbuild(self, ui: UIBuilder)Retained-mode Python UI builder called once on mount and reload().
build_htmlbuild_html(self) -> strOverride to return dynamically generated HTML markup.
build_cssbuild_css(self) -> strOverride to return dynamically generated CSS rules.
on_mounton_mount(self, doc: UICssDocument)Called once after the document loads (and again after reload()).
on_syncon_sync(self, context)Called on Blender redraws before layout reservation to sync dynamic state.
on_destroyon_destroy(self)Called right before the panel's document and canvas are torn down.
reloadreload(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 → Mounted UICssDocument instance.
  • panel.canvas → GpuCanvas owning this panel's document.
  • panel.manager → Shared GpuManager for this addon_id.
  • MyPanel.register() → Registers this panel class (shorthand for blendcss.register(MyPanel)).
  • MyPanel.unregister() → Unregisters this panel class.
  • MyPanel.instance() → Returns the active mounted Panel instance, or None.
  • MyPanel.bpy_panel() → Returns the generated bpy.types.Panel subclass, or None.

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):).

python
@blendcss.on("export_btn", "click")
def handle_export(self):
    print("Export clicked")

Released under the GNU GPL v3.0 License.