Skip to content

preloading

preloading #

node.preload(default) — bound onto Procedure.

Wraps a node in a PreloadProcedure, turning a user-input question into a pre-answered, still-adjustable option. Imported into the Procedure class body, so every import here is lazy (the node layer imports Procedure back).

preload(self, default) #

node.preload(default) — pre-answer this node with an adjustable default.

default is a procedure (or a raw literal, lifted to a constant) whose type matches this node's; the runtime preloads it in so the node starts complete and the user may adjust it before capturing::

session.photo &= cg.CaptureImage(
    raw_photo=cg.UserInputBool(label="RAW").preload(False),
)
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/preloading.py
def preload[T: CGType](
    self: Procedure[T],
    default: object,
) -> Procedure[T]:
    """``node.preload(default)`` — pre-answer this node with an adjustable default.

    ``default`` is a procedure (or a raw literal, lifted to a constant) whose
    type matches this node's; the runtime preloads it in so the node starts
    complete and the user may adjust it before capturing::

        session.photo &= cg.CaptureImage(
            raw_photo=cg.UserInputBool(label="RAW").preload(False),
        )
    """
    from capturegraph.procedures.nodes.process.structural import (
        PreloadProcedure,
    )
    from capturegraph.procedures.procedure.authoring.bridge import (
        coerce_input,
    )

    return cast(
        "Procedure[T]",
        PreloadProcedure(procedure=self, default=coerce_input(default)),
    )