Skip to content

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.

python
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,
) -> PropBinding
  • target: An object, MutableMapping (dict), or zero-arg callable returning one.
  • index: Optional sequence index for vector properties (e.g. 0, 1, 2 for scale).
  • hit_id: Optional container element ID that receives mouse drag/click events (defaults to element_id).
  • is_rotation: Converts radians ↔ degrees automatically when reading/writing.
  • formatter: Optional callable(float) -> str for custom display formatting.
  • doc.bind_prop(...): Backwards-compatible alias for doc.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.

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,
) -> ToggleBinding

ChoiceBinding (doc.bind_choice) ​

Two-way enum, tab, or swatch selector binding across multiple DOM elements.

python
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,
) -> ChoiceBinding

TextBinding (doc.bind_text) ​

One-way reactive text or HTML binding updated on every sync_bindings().

python
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,
) -> TextBinding

OperatorBinding (doc.bind_operator) ​

Binds a Blender operator to a DOM element with live poll() disabling and automatic bpy.context.temp_override(...).

python
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,
) -> OperatorBinding

context_override options ​

ValueBehavior
"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.
dictPasses the dictionary directly into bpy.context.temp_override(**spec).
CallableEvaluates the callable at poll/invoke time and uses its returned value.
None or FalseDisables context override.

OperatorBinding methods & properties ​

  • binding.poll() -> bool / binding.enabled -> bool: Evaluates op.poll() under context_override.
  • binding.invoke(doc=None, **extra_props): Runs poll() (if sync_poll=True), executes the operator, calls on_done or on_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, %, °

Released under the GNU GPL v3.0 License.