Bindings & Operators Reference
blendcss provides five reactive binding classes that connect DOM elements to Blender RNA properties, Python dictionaries, callables, and Blender operators. You can create them via UIBuilder (bind=...) or directly on a UICssDocument (doc.bind_*).
PropBinding (doc.bind_number)
Two-way numeric binding with horizontal drag-scrubbing (Shift fine, Ctrl snap) and click-to-type AST math evaluation.
doc.bind_number(
element_id: str,
target,
prop_name: str,
index: int = None,
hit_id: str = None,
unit: str = "",
step: float = 0.01,
min_val: float = None,
max_val: float = None,
precision: int = 2,
is_rotation: bool = False,
on_change=None,
formatter=None,
) -> PropBindingtarget: An object,MutableMapping(dict), or zero-arg callable returning one.index: Optional sequence index for vector properties (e.g.0,1,2forscale).hit_id: Optional container element ID that receives mouse drag/click events (defaults toelement_id).is_rotation: Converts radians ↔ degrees automatically when reading/writing.formatter: Optionalcallable(float) -> strfor custom display formatting.doc.bind_prop(...): Backwards-compatible alias fordoc.bind_number(...).
ToggleBinding (doc.bind_toggle)
Two-way boolean binding that toggles a CSS class when clicked and syncs changes back from Blender or Python.
doc.bind_toggle(
element_id: str,
target,
prop_name: str,
active_class: str = "active",
inactive_class: str = None,
hit_id: str = None,
on_change=None,
) -> ToggleBindingChoiceBinding (doc.bind_choice)
Two-way enum, tab, or swatch selector binding across multiple DOM elements.
doc.bind_choice(
items, # dict {elem_id: value} or list of (elem_id, value)
target,
prop_name: str,
active_class: str = "active",
on_change=None,
) -> ChoiceBindingTextBinding (doc.bind_text)
One-way reactive text or HTML binding updated on every sync_bindings().
doc.bind_text(
element_id: str,
target,
prop_name: str = None, # Omit when target is a callable returning the text directly
default: str = "",
format_fn=None,
as_html: bool = False,
) -> TextBindingOperatorBinding (doc.bind_operator)
Binds a Blender operator to a DOM element with live poll() disabling and automatic bpy.context.temp_override(...).
doc.bind_operator(
element_id: str,
operator, # "mod.op", "MOD_OT_op", or bpy.ops.mod.op
*,
props=None, # Static dict or callable returning dict
exec_ctx: str = "INVOKE_DEFAULT",
undo: bool = True,
hit_id: str = None,
event: str = "click",
disabled_class: str = "is-disabled",
sync_poll: bool = True,
context_override="AUTO",
on_done=None,
on_error=None,
**op_kwargs,
) -> OperatorBindingcontext_override options
| Value | Behavior |
|---|---|
"AUTO" (default) | Finds the WINDOW region matching the panel's space_type (e.g. VIEW_3D), preferring the current area. |
Space type string (e.g. "NODE_EDITOR") | Finds the WINDOW region for the specified Blender area type. |
dict | Passes the dictionary directly into bpy.context.temp_override(**spec). |
| Callable | Evaluates the callable at poll/invoke time and uses its returned value. |
None or False | Disables context override. |
OperatorBinding methods & properties
binding.poll() -> bool/binding.enabled -> bool: Evaluatesop.poll()undercontext_override.binding.invoke(doc=None, **extra_props): Runspoll()(ifsync_poll=True), executes the operator, callson_doneoron_error, and syncs bindings.binding.resolve() -> (op_callable, idname_py): Resolves the operator reference.
Helper Functions
blendcss.resolve_operator(op_ref) -> tuple
Resolves "mod.op", "MOD_OT_op", or a bpy.ops.* callable into (op_callable, idname_py). Returns (None, str(op_ref)) if not found.
blendcss.get_operator_info(op_ref) -> dict
Returns Blender RNA metadata: {"idname": str, "name": str, "description": str, "exists": bool}.
blendcss.safe_eval_math(expr: str, default: float = 0.0) -> float
Safely evaluates arithmetic expressions using Python's ast module without eval().
- Supported operators:
+,-,*,/,%,**, unary+/- - Supported constants:
pi,e,tau - Automatically strips trailing unit suffixes:
mm,cm,km,m,deg,rad,px,%,°