Skip to content

usd_chunks.chunk_notice

Notices and the dependency graph behind every chunk object.

Tf.Notice is USD's built-in callback system, similar to Qt's signals. This module uses Tf.Notice extensively but hides most of its API, so a client can be up and running with callbacks without managing the lifetime of listeners.

ChunkNoticeAlias names each supported notice class, so the notice you are interested in can be found without caring how it is implemented. Every custom notice subclasses ChunkNotice, which carries additional data whose type depends on the notice and on who sends it.

The easiest way to send a notice is explicitly, with send_notice:

send_notice(ChunkNoticeAlias.PARAM_CHANGED, some_param, {"any": "data"})

AttributeChangeNotice ⚓︎

AttributeChangeNotice(data=None)

Bases: ChunkNotice

Sent when an attribute changes; data is its AttributeSender.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

AttributeFlagsChangeNotice ⚓︎

AttributeFlagsChangeNotice(data=None)

Bases: AttributeChangeNotice

Sent when an object's flags change.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

AttributeStateChangeNotice ⚓︎

AttributeStateChangeNotice(data=None)

Bases: AttributeChangeNotice

Sent when an object's state bits change.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

CallbackContainer ⚓︎

CallbackContainer()

The callbacks on one ChunkNoticePropagator, with their private and on-create tags.

Kept here rather than on the NoticeConnection objects so as not to pollute that class. Private callbacks are neither serialized nor copied between propagators. Callbacks created in init should be private: they are recreated when deserializing, so serializing them too would duplicate them.

Callbacks are stored in self.callbacks as a list of dicts with the keys 'conn' (the NoticeConnection), 'on_create' and 'private'.

Source code in usd_chunks/chunk_notice.py
def __init__(self):
    super().__init__()
    self.callbacks: list[dict[Literal["conn", "on_create", "private"], Any]] = []

add ⚓︎

add(conn, trigger_on_create=True, private=False)

Store a callback.

Parameters:

Name Type Description Default
conn NoticeConnection

The connection.

required
trigger_on_create

Run it when the owning object is added to the scene.

True
private

Keep it out of copies and serialization.

False
Source code in usd_chunks/chunk_notice.py
def add(self, conn: NoticeConnection, trigger_on_create=True, private=False):
    """Store a callback.

    Args:
        conn: The connection.
        trigger_on_create: Run it when the owning object is added to the scene.
        private: Keep it out of copies and serialization.
    """
    self.callbacks.append({"conn": conn, "on_create": trigger_on_create, "private": private})

clear ⚓︎

clear()

Drop every stored callback.

Source code in usd_chunks/chunk_notice.py
def clear(self):
    """Drop every stored callback."""
    self.callbacks.clear()

extend ⚓︎

extend(other)

Add another container's non-private callbacks.

Parameters:

Name Type Description Default
other CallbackContainer

The container to copy from.

required
Source code in usd_chunks/chunk_notice.py
def extend(self, other: CallbackContainer):
    """Add another container's non-private callbacks.

    Args:
        other: The container to copy from.
    """
    for data in other.callbacks:
        if data.get("private"):
            continue

        self.add(data["conn"], data.get("on_create", True))

get ⚓︎

get(include_private=False)

The stored connections.

Parameters:

Name Type Description Default
include_private

Include private callbacks.

False

Returns:

Type Description

The connections.

Source code in usd_chunks/chunk_notice.py
def get(self, include_private=False):
    """The stored connections.

    Args:
        include_private: Include private callbacks.

    Returns:
        The connections.
    """
    return [x["conn"] for x in self.callbacks if include_private or (not x.get("private"))]

get_on_create ⚓︎

get_on_create(include_private=False)

The connections to run when the owning object is added to the scene.

Parameters:

Name Type Description Default
include_private

Include private callbacks.

False

Returns:

Type Description

The connections.

Source code in usd_chunks/chunk_notice.py
def get_on_create(self, include_private=False):
    """The connections to run when the owning object is added to the scene.

    Args:
        include_private: Include private callbacks.

    Returns:
        The connections.
    """
    return [x["conn"] for x in self.callbacks if x.get("on_create") and (include_private or (not x.get("private")))]

CameraChangedNotice ⚓︎

CameraChangedNotice(data=None)

Bases: ChunkNotice

Sent when the host's active camera changes; data is the camera.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkChangeNotice ⚓︎

ChunkChangeNotice(data=None)

Bases: ChunkNotice

Sent when a chunk or anything inside it changes; data is the chunk.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkConfigChanged ⚓︎

ChunkConfigChanged(data=None)

Bases: ChunkNotice

Sent when a chunk's config changes; data is the config.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkDeletedNotice ⚓︎

ChunkDeletedNotice(data=None)

Bases: ChunkNotice

Sent when any chunk object is deleted; data is the object.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkLoadedNotice ⚓︎

ChunkLoadedNotice(data=None)

Bases: ChunkNotice

Sent when a chunk is added to the scene; data is the chunk.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkNotice ⚓︎

ChunkNotice(data=None)

Bases: Notice

A Tf.Notice that carries data about what changed.

Receivers use the data to find what has been changed, including globally registered listeners that did not subscribe to a particular sender.

Attributes:

Name Type Description
data Any

The data sent with the notice. Its type varies between notices.

alias ChunkNoticeAlias

The alias associated with this notice.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ChunkNoticeAlias ⚓︎

Bases: IntEnum

The name of each supported Tf.Notice class, used as the client-facing way to pick a notice.

Any supported notice has an alias in this enum.

Attributes:

Name Type Description
NONE

A default, empty alias

PARAM_CHANGED

Sent when a param changes

GROUP_CHANGED

Sent when a group changes. This includes nested groups and param changes

CHUNK_CHANGED

Similar to GROUP_CHANGED but only for chunks

PARAM_ADDED

Sent when a param was added as a child to a group or chunk

PARAM_REMOVED

Sent when a param was removed as a child from a group or chunk. Not necessarily deleted

CHUNK_DELETED

A chunk object was deleted. Use instead of PARAM_REMOVED for most applications: PARAM_REMOVED is only sent for a child of a NameSyncedContainer (group / chunk / vector), while CHUNK_DELETED is sent whenever ANY chunk object is deleted

ATTRIBUTE_CHANGED

Default notice for attributes that do not set an alias explicitly

FLAGS_CHANGED

Sent when the flags attribute changes

STATE_CHANGED

Sent when the state attribute changes

MENU_ACTION_NOTICE

Sent when a menu action should be executed

PRIM_SELECTION_CHANGED

Sent whenever the host's prim selection changes

PROP_SELECTION_CHANGED

Sent whenever the host's property selection changes

OBJECT_CHANGED

Sent whenever anything was changed on the stage

STAGE_CHANGED

Sent when the stage is changed

STAGE_CONTENTS_CHANGED

Sent when stage contents changed

STAGE_EDIT_TARGET_CHANGED

Sent when the edit target on the stage changed

CHUNK_LOADED

Sent when a new chunk has been added to the registry

CHUNK_UNLOADED

Sent when a chunk was unloaded

CUSTOM

Custom notices should be registered with aliases > CUSTOM

ChunkNoticePropagator ⚓︎

ChunkNoticePropagator(*args, **kwargs)

Base class that makes chunk objects connectable, to each other and to callbacks.

Chunk objects connect to each other through 'physical' connections and to callbacks through 'non-physical' ones. Physical connections rely on dependencies (inputs) and dependants (outputs and owners); non-physical connections rely on the Tf.Notice system and have no dependencies. Callbacks are non-physical; inputs, outputs and the owner are physical.

Physical:

'Children' reference their owning object (parent), and call data_changed() on the owner when the child has been modified. The DagNode manages these connections: it holds references to inputs, outputs and an owner, and solves its outputs recursively while respecting dependencies, so a node does not solve until all its inputs are solved. Any number of dependencies (inputs) can be added to an instance of this class; once all of them are solved, the instance's DagNode solves too, calling data_changed(). Combined with callbacks, this lets a client build dependency graphs of chunk classes and have the system trigger callbacks when appropriate.

Non-physical:

Connections added with add_callback are not managed by the DAG. The Tf.Notice system manages them, without any dependency information, so a callback never triggers another callback implicitly.

By default send_self() is called whenever an attribute or child attribute has been modified. The notice sent is decided by get_notice_alias(), and the DagNode also propagates it up the owner hierarchy.

get_edit_context(), get_layer_identifier() and get_stage() can be implemented to support layer contexts when modifying the stage. A NoticeConnection sets the edit context to the layer returned by get_edit_context() before running its callback, which keeps callbacks contained to the layers managed by ChunkLayerManager. See NoticeConnection.handle_callback.

Source code in usd_chunks/chunk_notice.py
def __init__(self, *args, **kwargs) -> None:
    self._callbacks = CallbackContainer()
    self._dag_node = None
    self._blocked = False
    super().__init__(*args, **kwargs)

add_callback ⚓︎

add_callback(method, sender=None, listen_globally=False, notice_alias=ChunkNoticeAlias.NONE, send_on_create=False, private=False)

Subscribe a callback to a notice.

When the notice is sent, method is called with one of two signatures, chosen from the callback's own declared parameters:

(notice(Tf.Notice), sender(Any)) Matches Tf.Notice. This is what a bound method gets, where self is already the object holding the state -- the preferred form. Plain functions may declare it too.

(owner(Any), notice(Tf.Notice), sender(Any)) The convenience form for module-level functions, where owner is the object add_callback was called on. Note owner is not the same as sender: sender is whatever dispatched the notice, which may be a proxy, an attribute sender, or an unrelated object when listening globally.

With no sender, self is assumed to be the sender, which keeps the simple case simple::

my_param.add_callback(my_callback)

Parameters:

Name Type Description Default
method Callable

The method to call when the notice is sent

required
sender Any

The sender to subscribe to. If None, self is used unless listen_globally is True. Defaults to None.

None
listen_globally bool

Subscribe to every notice of type notice_alias, whatever its sender. Defaults to False.

False
notice_alias ChunkNoticeAlias

The notice to subscribe to. NONE uses the sender's get_notice_alias(). Defaults to ChunkNoticeAlias.NONE.

NONE
send_on_create bool

Also call it when the owning object is added to the scene. Defaults to False.

False
private bool

Keep the callback out of serialization and copies, which is what a callback added inside init needs. Defaults to False.

False

Raises:

Type Description
ValueError

It would hear another chunk. Chunks speak to each other only through wires: listen_globally is for the stage and the host (SCENE_ALIASES), and a sender is this object's own chunk or something in it.

Source code in usd_chunks/chunk_notice.py
def add_callback(
    self,
    method: Callable[[NoticeT, Any], Any] | Callable[[Self, NoticeT, Any], Any],
    sender: ChunkNoticePropagator | None = None,
    listen_globally: bool = False,
    notice_alias: ChunkNoticeAlias = ChunkNoticeAlias.NONE,
    send_on_create=False,
    private=False,
):
    """Subscribe a callback to a notice.

    When the notice is sent, `method` is called with one of two signatures, chosen from the
    callback's own declared parameters:

    (notice(Tf.Notice), sender(Any))
        Matches Tf.Notice. This is what a bound method gets, where `self` is already the
        object holding the state -- the preferred form. Plain functions may declare it too.

    (owner(Any), notice(Tf.Notice), sender(Any))
        The convenience form for module-level functions, where `owner` is the object
        add_callback was called on. Note `owner` is not the same as `sender`: `sender` is
        whatever dispatched the notice, which may be a proxy, an attribute sender, or an
        unrelated object when listening globally.

    With no sender, self is assumed to be the sender, which keeps the simple case simple::

        my_param.add_callback(my_callback)

    Args:
        method (Callable): The method to call when the notice is sent
        sender (Any, optional): The sender to subscribe to. If None, self is used unless
            listen_globally is True. Defaults to None.
        listen_globally (bool, optional): Subscribe to every notice of type notice_alias,
            whatever its sender. Defaults to False.
        notice_alias (ChunkNoticeAlias, optional): The notice to subscribe to. NONE uses the
            sender's get_notice_alias(). Defaults to ChunkNoticeAlias.NONE.
        send_on_create (bool): Also call it when the owning object is added to the scene.
            Defaults to False.
        private (bool): Keep the callback out of serialization and copies, which is what a
            callback added inside __init__ needs. Defaults to False.

    Raises:
        ValueError: It would hear another chunk. Chunks speak to each other only through
            wires: listen_globally is for the stage and the host (SCENE_ALIASES), and a
            sender is this object's own chunk or something in it.
    """
    if listen_globally and notice_alias not in SCENE_ALIASES:
        raise ValueError(
            f"listen_globally hears every chunk's {notice_alias.name}; a chunk may listen "
            f"globally only to the stage and the host ({', '.join(sorted(a.name for a in SCENE_ALIASES))}). "
            "To react to another chunk, wire it in."
        )
    if sender is not None and (mine := _chunk_of(self)) is not None \
            and (theirs := _chunk_of(sender)) is not None and theirs is not mine:
        raise ValueError(
            f"{getattr(self, 'name', self)} listens to {getattr(sender, 'name', sender)} of "
            f"another chunk ({getattr(theirs, 'name', theirs)}): to react to another chunk, "
            "wire it in -- an exec input, or an @Node.param@ expression."
        )
    # If sender is not set and we should not listen for global notices, the sender will be self
    if sender is None and not listen_globally:
        sender = self

    # If sender is specified, only subscribe to changes from it.
    if isinstance(sender, ChunkNoticePropagator) and notice_alias is ChunkNoticeAlias.NONE:
        notice_alias = sender.get_notice_alias()

    self._callbacks.add(
        NoticeConnection(method, notice_alias, sender, listen_globally, self), send_on_create, private
    )

add_dependency ⚓︎

add_dependency(input)

Add an input. This propagator does not evaluate until all inputs are solved.

Parameters:

Name Type Description Default
input ChunkNoticePropagator

The node to add as input

required

Returns:

Name Type Description
int int

The dependency index

Source code in usd_chunks/chunk_notice.py
def add_dependency(self, input: ChunkNoticePropagator) -> int:
    """Add an input. This propagator does not evaluate until all inputs are solved.

    Args:
        input (ChunkNoticePropagator): The node to add as input

    Returns:
        int: The dependency index
    """
    idx = self.get_dag_node().add_dependency(input.get_dag_node())
    # What the input writes names what is wired below it (Transform's op order), so it
    # cooks again too -- and, as it is dirtied, everything below it.
    if getattr(getattr(input.get_chunk_module(), "config", None), "cooks_when_wired_below", False):
        input.get_dag_node().dirty = True
    send_notice(ChunkNoticeAlias.DEPENDENCY_ADDED, self, data=input)
    return idx

data_changed ⚓︎

data_changed(notice=None)

Called by the DagNode when it solves, once all inputs (dependencies) are solved.

The returned notice is propagated by the DagNode.

Parameters:

Name Type Description Default
notice ChunkNotice | None

The notice that was sent

None

Returns:

Type Description
ChunkNotice | None

ChunkNotice | None: The notice to propagate, or None when blocked

Source code in usd_chunks/chunk_notice.py
def data_changed(self, notice: ChunkNotice | None = None) -> ChunkNotice | None:
    """Called by the DagNode when it solves, once all inputs (dependencies) are solved.

    The returned notice is propagated by the DagNode.

    Args:
        notice (ChunkNotice | None): The notice that was sent

    Returns:
        ChunkNotice | None: The notice to propagate, or None when blocked
    """
    if not notice or (notice and notice.alias not in _RECORD_ALIASES):
        if self.is_blocked():
            return None
    if notice:
        notice.Send(self)
    return notice

execute ⚓︎

execute()

Re-execute this object, and everything downstream of it, now.

Dirties it and solves downstream: each solved object's data_changed() runs, and with it send_self(), which triggers any connected callbacks. When the solve has finished, every chunk it reached runs its module's execute(node) once, upstream first (chunk_cook.flush, then chunk_cook.cook). Inside batched_solve() it only dirties, and the solve waits for the block to end; inside another chunk's cook, the chunks it reaches cook once that cook has ended.

This is the one way to run a chunk again: a module's execute(node) is written, never called directly, and chunk_cook.cook is the framework's step, not an API.

Source code in usd_chunks/chunk_notice.py
def execute(self):
    """Re-execute this object, and everything downstream of it, now.

    Dirties it and solves downstream: each solved object's data_changed() runs, and with
    it send_self(), which triggers any connected callbacks. When the solve has finished,
    every chunk it reached runs its module's execute(node) once, upstream first
    (chunk_cook.flush, then chunk_cook.cook). Inside batched_solve() it only dirties,
    and the solve waits for the block to end; inside another chunk's cook, the chunks
    it reaches cook once that cook has ended.

    This is the one way to run a chunk again: a module's execute(node) is written, never
    called directly, and chunk_cook.cook is the framework's step, not an API.
    """
    node = self.get_dag_node()
    node.dirty = True
    if chunk_cook.queue(self):
        return
    with chunk_cook.solving():
        self._solve_downstream()

find_callbacks ⚓︎

find_callbacks(method=None, sender=None, notice_type=None)

Find the NoticeConnections stored on this object that match every given filter.

For example, passing method finds connections whose method is that function.

Parameters:

Name Type Description Default
method Callable

Filter by method on connections. Defaults to None.

None
sender ChunkNoticePropagator

Filter by sender. Defaults to None.

None
notice_type ChunkNoticeAlias

Filter by alias. Defaults to None.

None

Returns:

Type Description
list[NoticeConnection]

list[NoticeConnection]: The matching connections

Source code in usd_chunks/chunk_notice.py
def find_callbacks(
    self,
    method: Callable | None = None,
    sender: ChunkNoticePropagator | None = None,
    notice_type: ChunkNoticeAlias | None = None,
) -> list[NoticeConnection]:
    """Find the NoticeConnections stored on this object that match every given filter.

    For example, passing `method` finds connections whose method is that function.

    Args:
        method (Callable, optional): Filter by method on connections. Defaults to None.
        sender (ChunkNoticePropagator, optional): Filter by sender. Defaults to None.
        notice_type (ChunkNoticeAlias, optional): Filter by alias. Defaults to None.

    Returns:
        list[NoticeConnection]: The matching connections
    """
    query = {"get_method": method, "sender": sender, "alias": notice_type}
    result = []

    def _conn_attr(conn, q):
        res = getattr(conn, q)
        if callable(res):
            return res()
        return res

    for conn in self.get_callbacks():
        if any([query[y] is not None and _conn_attr(conn, y) == query[y] for y in query]):
            result.append(conn)

    return result

get_callbacks ⚓︎

get_callbacks()

Get the callback connections, private ones included.

Returns:

Type Description
list[NoticeConnection]

list[NoticeConnection]: The callback connections

Source code in usd_chunks/chunk_notice.py
def get_callbacks(self) -> list[NoticeConnection]:
    """Get the callback connections, private ones included.

    Returns:
        list[NoticeConnection]: The callback connections
    """
    return self._callbacks.get(True)

get_chunk_module ⚓︎

get_chunk_module()

The registered chunk module this object's behaviour comes from, or None.

Only a chunk has one -- ChunkBase overrides this to look its module up in the registry. Declared here so the solve can ask any propagator whether it has behaviour to run without knowing the chunk classes, which this module cannot import.

Returns:

Type Description
ChunkModule | None

Always None here.

Source code in usd_chunks/chunk_notice.py
def get_chunk_module(self) -> chunk_registry.ChunkModule | None:
    """The registered chunk module this object's behaviour comes from, or None.

    Only a chunk has one -- ChunkBase overrides this to look its module up in the
    registry. Declared here so the solve can ask any propagator whether it has
    behaviour to run without knowing the chunk classes, which this module cannot import.

    Returns:
        Always None here.
    """
    return None

get_dag_node ⚓︎

get_dag_node()

Get this object's DagNode, creating it on first use.

Returns:

Name Type Description
DagNode DagNode

The DagNode held by this ChunkNoticePropagator instance

Source code in usd_chunks/chunk_notice.py
def get_dag_node(self) -> DagNode:
    """Get this object's DagNode, creating it on first use.

    Returns:
        DagNode: The DagNode held by this ChunkNoticePropagator instance
    """
    if not self._dag_node:
        self._dag_node = DagNode(self)
    return self._dag_node

get_dependencies ⚓︎

get_dependencies() -> list[tuple[int, ChunkNoticePropagator]]
get_dependencies(predicate: Predicate[_T] | None = None) -> list[tuple[int, _T]]
get_dependencies(predicate=None)

Get the inputs of this propagator.

Parameters:

Name Type Description Default
predicate Predicate[_T] | None

Only return inputs matching this.

None

Returns:

Type Description

list[tuple[int, ChunkNoticePropagator]]: (key, input) pairs

Source code in usd_chunks/chunk_notice.py
def get_dependencies(self, predicate: Predicate[_T] | None = None):
    """Get the inputs of this propagator.

    Args:
        predicate: Only return inputs matching this.

    Returns:
        list[tuple[int, ChunkNoticePropagator]]: (key, input) pairs
    """
    if not predicate:
        return [(x, y.propagator) for x, y in self.get_dag_node().get_inputs() if y.propagator]
    return [(x, y.propagator) for x, y in self.get_dag_node().get_inputs() if predicate(y.propagator)]

get_dependency ⚓︎

get_dependency(index: int = 0) -> ChunkNoticePropagator | None
get_dependency(index: int = 0, predicate: Predicate[_T] | None = None) -> _T
get_dependency(index=0, predicate=None)

Get one input of this propagator.

Parameters:

Name Type Description Default
index int

The key of the input.

0
predicate Predicate[_T] | None

Only return the input if it matches this.

None

Returns:

Type Description
ChunkNoticePropagator | None | _T

ChunkNoticePropagator | None: The input at index, or None if there is none

Raises:

Type Description
ValueError

The input exists but does not match the predicate.

Source code in usd_chunks/chunk_notice.py
def get_dependency(
    self, index: int = 0, predicate: Predicate[_T] | None = None
) -> ChunkNoticePropagator | None | _T:
    """Get one input of this propagator.

    Args:
        index: The key of the input.
        predicate: Only return the input if it matches this.

    Returns:
        ChunkNoticePropagator | None: The input at index, or None if there is none

    Raises:
        ValueError: The input exists but does not match the predicate.
    """
    try:
        res = self.get_dag_node().get_input(index).propagator
    except (KeyError, IndexError, AttributeError):
        # A missing connection is "not found" -> None regardless of a type predicate.
        # The predicate only filters a connection that exists (see ValueError below).
        return None
    if not predicate or predicate(res):
        return res
    raise ValueError(f"Predicate {predicate} failed for get_dependency({index})")

get_dependent ⚓︎

get_dependent(index: int = 0) -> ChunkNoticePropagator | None
get_dependent(index: int = 0, predicate: Predicate[_T] | None = None) -> _T
get_dependent(index=0, predicate=None)

Get one output of this propagator.

Parameters:

Name Type Description Default
index int

The key of the output.

0
predicate Predicate[_T] | None

Only return the output if it matches this.

None

Returns:

Type Description
ChunkNoticePropagator | None | _T

ChunkNoticePropagator | None: The output at index, or None if there is none

Raises:

Type Description
ValueError

The output exists but does not match the predicate.

Source code in usd_chunks/chunk_notice.py
def get_dependent(
    self, index: int = 0, predicate: Predicate[_T] | None = None
) -> ChunkNoticePropagator | None | _T:
    """Get one output of this propagator.

    Args:
        index: The key of the output.
        predicate: Only return the output if it matches this.

    Returns:
        ChunkNoticePropagator | None: The output at index, or None if there is none

    Raises:
        ValueError: The output exists but does not match the predicate.
    """
    try:
        res = self.get_dag_node().get_output(index).propagator
    except (KeyError, IndexError, AttributeError):
        # A missing connection is "not found" -> None regardless of a type predicate.
        # The predicate only filters a connection that exists (see ValueError below).
        return None
    if not predicate or predicate(res):
        return res
    raise ValueError(f"Predicate {predicate} failed for get_dependency({index})")

get_dependents ⚓︎

get_dependents() -> list[tuple[int, ChunkNoticePropagator]]
get_dependents(predicate: Predicate[_T] | None = None) -> list[tuple[int, _T]]
get_dependents(predicate=None)

Get every propagator that depends on this one (connected to its output).

Parameters:

Name Type Description Default
predicate Predicate[_T] | None

Only return dependents matching this. Defaults to None.

None

Returns:

Type Description

list[tuple[int, ChunkNoticePropagator]]: (key, dependent) pairs

Source code in usd_chunks/chunk_notice.py
def get_dependents(self, predicate: Predicate[_T] | None = None):
    """Get every propagator that depends on this one (connected to its output).

    Args:
        predicate (Predicate[_T] | None, optional): Only return dependents matching this.
            Defaults to None.

    Returns:
        list[tuple[int, ChunkNoticePropagator]]: (key, dependent) pairs
    """
    if not predicate:
        return [(x, y.propagator) for x, y in self.get_dag_node().get_outputs() if y.propagator]
    return [(x, y.propagator) for x, y in self.get_dag_node().get_outputs() if predicate(y.propagator)]

get_edit_context abstractmethod ⚓︎

get_edit_context()

Get a layer the chunk object can safely add changes to the stage in.

Returns:

Type Description
Layer | None

Sdf.Layer | None: The layer that can be modified

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def get_edit_context(self) -> Sdf.Layer | None:
    """Get a layer the chunk object can safely add changes to the stage in.

    Returns:
        Sdf.Layer | None: The layer that can be modified
    """
    pass

get_layer_identifier abstractmethod ⚓︎

get_layer_identifier()

Get a unique layer identifier for creating and accessing layers.

Returns:

Name Type Description
str str

The unique layer identifier

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def get_layer_identifier(self) -> str:
    """Get a unique layer identifier for creating and accessing layers.

    Returns:
        str: The unique layer identifier
    """
    pass

get_notice_alias abstractmethod ⚓︎

get_notice_alias()

The notice this object sends from send_self(), and listens for by default in add_callback().

Subclasses override this to send the right notice when something on the chunk object changes.

Returns:

Name Type Description
ChunkNoticeAlias ChunkNoticeAlias

The default notice alias

Raises:

Type Description
NotImplementedError

A subclass does not implement it.

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def get_notice_alias(self) -> ChunkNoticeAlias:
    """The notice this object sends from send_self(), and listens for by default in add_callback().

    Subclasses override this to send the right notice when something on the chunk object
    changes.

    Returns:
        ChunkNoticeAlias: The default notice alias

    Raises:
        NotImplementedError: A subclass does not implement it.
    """
    raise NotImplementedError

get_notice_data ⚓︎

get_notice_data()

The data attached to the notice send_self() sends.

Returns:

Name Type Description
Self Self

This object, by default

Source code in usd_chunks/chunk_notice.py
def get_notice_data(self) -> Self:
    """The data attached to the notice send_self() sends.

    Returns:
        Self: This object, by default
    """
    return self

get_on_create_callbacks ⚓︎

get_on_create_callbacks()

Get the callbacks to trigger when the chunk is added to the scene.

Returns:

Type Description
list[NoticeConnection]

list[NoticeConnection]: The connections to trigger when loaded

Source code in usd_chunks/chunk_notice.py
def get_on_create_callbacks(self) -> list[NoticeConnection]:
    """Get the callbacks to trigger when the chunk is added to the scene.

    Returns:
        list[NoticeConnection]: The connections to trigger when loaded
    """
    return self._callbacks.get_on_create()

get_owner ⚓︎

get_owner()

Get the owning ChunkNoticePropagator of this object.

Returns:

Type Description
ChunkNoticePropagator | None

ChunkNoticePropagator | None: The owning object, or None

Source code in usd_chunks/chunk_notice.py
def get_owner(self) -> ChunkNoticePropagator | None:
    """Get the owning ChunkNoticePropagator of this object.

    Returns:
        ChunkNoticePropagator | None: The owning object, or None
    """
    return self.get_dag_node().get_owner()

get_stage abstractmethod ⚓︎

get_stage()

Get a handle to the stage.

Returns:

Type Description
Stage | None

Usd.Stage | None: A Usd.Stage if available

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def get_stage(self) -> Usd.Stage | None:
    """Get a handle to the stage.

    Returns:
        Usd.Stage | None: A Usd.Stage if available
    """
    pass

is_blocked abstractmethod ⚓︎

is_blocked()

Check whether this instance should be blocked from sending notices.

Returns:

Name Type Description
bool bool

True if blocked or the owner is blocked, False otherwise

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def is_blocked(self) -> bool:
    """Check whether this instance should be blocked from sending notices.

    Returns:
        bool: True if blocked or the owner is blocked, False otherwise
    """
    if self._blocked:
        return True

    if self.get_notice_alias() == ChunkNoticeAlias.STATE_CHANGED:
        return False

    if owner := self.get_owner():
        return owner.is_blocked()
    return False

is_presentation_change ⚓︎

is_presentation_change()

Whether the change this propagator is being dirtied for is presentation only.

A presentation change is one nothing downstream computes from -- hiding a param, folding a group open, selecting a node. Such a change still has to reach the UI, so it solves and sends its notice as usual, but it must not dirty anything that reads this propagator's data: see chunk_scheduler.propagate_dirty.

Asked at dirty time, so an implementation describes the change that just happened rather than the object in general. Only AttributeSender answers True (for the state attribute, and only while DISABLED is untouched) -- everything else is a data change.

Returns:

Name Type Description
bool bool

True if this change must not dirty dependants

Source code in usd_chunks/chunk_notice.py
def is_presentation_change(self) -> bool:
    """Whether the change this propagator is being dirtied for is presentation only.

    A presentation change is one nothing downstream computes from -- hiding a param,
    folding a group open, selecting a node. Such a change still has to reach the UI, so
    it solves and sends its notice as usual, but it must not dirty anything that reads
    this propagator's data: see chunk_scheduler.propagate_dirty.

    Asked at dirty time, so an implementation describes the change that just happened
    rather than the object in general. Only AttributeSender answers True (for the state
    attribute, and only while DISABLED is untouched) -- everything else is a data change.

    Returns:
        bool: True if this change must not dirty dependants
    """
    return False

remove_dependency ⚓︎

remove_dependency(input)

Remove an input previously added with add_dependency.

Dirties this propagator so the loss of the input propagates downstream like any other change. Sends DEPENDENCY_REMOVED, so ChunkStageSync removes the USD connection too and the saved file loses the wire. When the connection is already gone (the stage sync mirroring a wire the graph cut) that is a no-op.

Parameters:

Name Type Description Default
input ChunkNoticePropagator

The node to drop as input

required

Returns:

Name Type Description
bool bool

True if input was a dependency and got removed

Source code in usd_chunks/chunk_notice.py
def remove_dependency(self, input: ChunkNoticePropagator) -> bool:
    """Remove an input previously added with add_dependency.

    Dirties this propagator so the loss of the input propagates downstream like any other
    change. Sends DEPENDENCY_REMOVED, so ChunkStageSync removes the USD connection too and
    the saved file loses the wire. When the connection is already gone (the stage sync
    mirroring a wire the graph cut) that is a no-op.

    Args:
        input (ChunkNoticePropagator): The node to drop as input

    Returns:
        bool: True if input was a dependency and got removed
    """
    removed = self.get_dag_node().remove_dependency(input.get_dag_node())
    if removed:
        send_notice(ChunkNoticeAlias.DEPENDENCY_REMOVED, self, data=input)
    return removed

request_delete abstractmethod ⚓︎

request_delete()

Delete this object. Implemented by a subclass.

Raises:

Type Description
NotImplementedError

A subclass does not implement it.

Source code in usd_chunks/chunk_notice.py
@abstractmethod
def request_delete(self):
    """Delete this object. Implemented by a subclass.

    Raises:
        NotImplementedError: A subclass does not implement it.
    """
    raise NotImplementedError

send_self ⚓︎

send_self(alias=None, data=None)

Sends a Tf.Notice, with self as sender. The type of notice is determined by get_notice_alias(), or optionally the alias argument.

Parameters:

Name Type Description Default
alias Optional[ChunkNoticeAlias]

An optional alias to send. If alias is not None, it will be used instead of the default from get_notice_alias()

None
data Any

The data to attach to the notice. If None, will use self.get_notice_data(). Defaults to None

None

Returns:

Type Description
ChunkNotice | None

Optional[ChunkNotice]: The notice that was sent, or None if no notice was sent

Source code in usd_chunks/chunk_notice.py
def send_self(self, alias: ChunkNoticeAlias | None = None, data: Any = None) -> ChunkNotice | None:
    """Sends a Tf.Notice, with self as sender. The type of notice is determined by get_notice_alias(), or optionally the alias argument.

    Args:
        alias (Optional[ChunkNoticeAlias]): An optional alias to send. If alias is not None, it will be used instead of the default from get_notice_alias()
        data (Any): The data to attach to the notice. If None, will use self.get_notice_data(). Defaults to None

    Returns:
        Optional[ChunkNotice]: The notice that was sent, or None if no notice was sent
    """
    if alias is None:
        alias = self.get_notice_alias()

    if not alias:
        return None

    if alias not in _STRUCTURAL_ALIASES and self.is_blocked():
        return None

    notice_data = data if data is not None else self.get_notice_data()
    notice = send_notice(alias, self, notice_data)

    if not notice:
        return None

    return notice

set_blocked ⚓︎

set_blocked(block)

Block or unblock this object's notices.

Source code in usd_chunks/chunk_notice.py
def set_blocked(self, block: bool):
    """Block or unblock this object's notices."""
    self._blocked = block

set_owner ⚓︎

set_owner(owner, *, dirty=True)

Set the owner of this object: its parent in a parent-child relationship.

Call this once the parent has actually taken ownership of this object, to update the child when the relationship has changed.

Parameters:

Name Type Description Default
owner ChunkNoticePropagator | None

The owning (parent) object that should receive notices when this instance is modified

required
dirty bool

Whether joining marks the owner dirty; see DagNode.set_owner.

True
Source code in usd_chunks/chunk_notice.py
def set_owner(self, owner: ChunkNoticePropagator | None, *, dirty: bool = True):
    """Set the owner of this object: its parent in a parent-child relationship.

    Call this once the parent has actually taken ownership of this object, to update the
    child when the relationship has changed.

    Args:
        owner (ChunkNoticePropagator | None): The owning (parent) object that should receive notices when this instance is modified
        dirty (bool): Whether joining marks the owner dirty; see DagNode.set_owner.
    """
    self.get_dag_node().set_owner(owner, dirty=dirty)

ChunkNoticeRegistry ⚓︎

The registry mapping each ChunkNoticeAlias to its Tf.Notice class.

The easiest way to register a new notice is to decorate its class with @chunk_notice::

@chunk_notice(ChunkNoticeAlias.PARAM_CHANGED)
class ParamChangeNotice(ChunkNotice):
    pass

Attributes:

Name Type Description
registered dict[int, type[Notice]]

Maps a ChunkNoticeAlias to a registered notice class

get_from_alias classmethod ⚓︎

get_from_alias(alias)

Get a registered notice from a ChunkNoticeAlias.

Parameters:

Name Type Description Default
alias ChunkNoticeAlias

The alias to look up

required

Raises:

Type Description
ErrorException

If the alias has not been registered

Returns:

Type Description
type[ChunkNotice]

type[Tf.Notice]: The class of the registered notice

Source code in usd_chunks/chunk_notice.py
@classmethod
def get_from_alias(cls, alias: ChunkNoticeAlias) -> type[ChunkNotice]:
    """Get a registered notice from a ChunkNoticeAlias.

    Args:
        alias (ChunkNoticeAlias): The alias to look up

    Raises:
        Tf.ErrorException: If the alias has not been registered

    Returns:
        type[Tf.Notice]: The class of the registered notice
    """
    notice = cls.registered.get(alias)
    if notice is None:
        raise Tf.ErrorException(f"No notice found for alias {alias}")
    return notice

register classmethod ⚓︎

register(alias, notice_class)

Register a new notice and associate it with an alias.

Parameters:

Name Type Description Default
alias ChunkNoticeAlias

The alias to associate with the notice

required
notice_class type[Any]

The class that should be registered

required
Source code in usd_chunks/chunk_notice.py
@classmethod
def register(cls, alias: ChunkNoticeAlias, notice_class: type[Any]):
    """Register a new notice and associate it with an alias.

    Args:
        alias (ChunkNoticeAlias): The alias to associate with the notice
        notice_class (type[Any]): The class that should be registered
    """
    if alias not in cls.registered:
        notice_class.alias = alias
        if not hasattr(notice_class, "data"):
            notice_class.data = None
        cls.registered[alias] = notice_class

ChunkUnloadedNotice ⚓︎

ChunkUnloadedNotice(data=None)

Bases: ChunkNotice

Sent when a chunk is unloaded; data is the chunk.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

DagConnections ⚓︎

The connections of one DagNode.

Attributes:

Name Type Description

Parameters:

Name Type Description Default
owner ReferenceType[ChunkNoticePropagator] | None
None
inputs ConnSetT

Mapping class that references values weakly.

Entries in the dictionary will be discarded when no strong reference to the value exists anymore

<dynamic>
outputs ConnSetT

Mapping class that references values weakly.

Entries in the dictionary will be discarded when no strong reference to the value exists anymore

<dynamic>

DagGraphID ⚓︎

DagGraphID()

Which connected graph a DagNode belongs to, merged union-find style as nodes connect.

Source code in usd_chunks/chunk_notice.py
def __init__(self):
    self._store: DagGraphID | None = None
    # A counter, NOT id(self): CPython only guarantees an object's id() is unique among
    # objects alive at the same time, and a scene reload creates and drops these fast
    # enough for a freed address to be reused. Two graphs would then share one
    # identifier, and with it one graph_layers key -- inserting the same layer into a
    # stage's subLayerPaths twice, which Sdf refuses. A counter is unique for the
    # process's lifetime regardless of when any instance is freed.
    self._uid = next(_dag_graph_id_counter)

get_identifier ⚓︎

get_identifier()

The graph's identifier: the root id's unique counter value.

Source code in usd_chunks/chunk_notice.py
def get_identifier(self):
    """The graph's identifier: the root id's unique counter value."""
    return self.root()._uid

root ⚓︎

root()

The terminal DagGraphID of the _store chain, found iteratively.

The path is compressed on the way, so every visited id points directly at the root afterwards.

Returns:

Type Description
DagGraphID

The root id.

Source code in usd_chunks/chunk_notice.py
def root(self) -> DagGraphID:
    """The terminal DagGraphID of the _store chain, found iteratively.

    The path is compressed on the way, so every visited id points directly at the root
    afterwards.

    Returns:
        The root id.
    """
    node = self
    while node._store is not None:
        node = node._store

    # Path compression: repoint the whole chain at the root
    current = self
    while current is not node:
        nxt = current._store
        current._store = node
        current = nxt  # type: ignore[assignment]
    return node

DagNode ⚓︎

DagNode(propagator)

A connectable node in the dependency graph between chunk objects.

A DagNode handles the 'physical' connections between ChunkNoticePropagator objects, as opposed to NoticeConnection, which handles non-physical ones. It may have any number of inputs and outputs, and one owner. Dirtying a node dirties its outputs and owner, recursively. A client solves this node and everything connected downstream by calling solve_outputs().

Attributes:

Name Type Description
dirty bool

Whether this node needs solving

propagator ChunkNoticePropagator

The propagator this node represents

Source code in usd_chunks/chunk_notice.py
def __init__(self, propagator: ChunkNoticePropagator):
    # Insertion-ordered map of the change reasons that dirtied this node, maintained
    # by chunk_scheduler.propagate_dirty and replayed by iter_changes(). The value is
    # the presentation-vs-data verdict for that reason, decided once at origin by
    # AttributeSender.is_presentation_change and carried unchanged from there --
    # see only_presentation_changed().
    self._changes: dict[tuple[ChunkNoticeAlias, DagNode], bool] = {}
    self._dirty = True
    self._connections: DagConnections = DagConnections()
    self._propagator = weakref.ref(propagator)
    self._index: int = 0

    # Reverse index of the owner link, so the scheduler can walk ownership in both
    # directions without a global node registry. Created on demand: most nodes are
    # owned by something but own nothing themselves, and a WeakSet per node is real
    # allocation and GC pressure at the scale this graph reaches.
    self._owned: weakref.WeakSet[DagNode] | None = None
    self._graph_id: DagGraphID = DagGraphID()
    self._part_of_graph = True

dirty property writable ⚓︎

dirty

Whether this node needs solving; setting it True dirties everything downstream.

name property ⚓︎

name

The propagator's name, or its class name; used when debugging a solve.

propagator property ⚓︎

propagator

The propagator this node represents, or None once it is gone.

add_dependant ⚓︎

add_dependant(node)

Add a node that depends on this one (an output), which dirties that node.

Only the new dependant has something new to read. Dirtying this node instead re-ran it and every other branch below it too.

Parameters:

Name Type Description Default
node DagNode

The dependant node

required
Source code in usd_chunks/chunk_notice.py
def add_dependant(self, node: DagNode):
    """Add a node that depends on this one (an output), which dirties that node.

    Only the new dependant has something new to read. Dirtying this node instead re-ran
    it and every other branch below it too.

    Args:
        node (DagNode): The dependant node
    """
    self._connections.outputs[self.next_key(self._connections.outputs)] = node
    chunk_scheduler.topology_changed(self, node)
    # A reason, as propagate_dirty records one: with none, a display-only change reaching
    # the node in the same solve would make it look like it had nothing to cook.
    node._index += 1
    node._changes[(ChunkNoticeAlias.INPUT_CHANGED, self)] = False
    node.dirty = True

add_dependency ⚓︎

add_dependency(node, connect_reverse=True)

Add a dependency (an input) to this node, which dirties it.

Parameters:

Name Type Description Default
node DagNode

The new dependency to add

required
connect_reverse bool

Also add this node to the input's outputs. Defaults to True.

True

Returns:

Name Type Description
int int

The key the dependency was stored under

Source code in usd_chunks/chunk_notice.py
def add_dependency(self, node: DagNode, connect_reverse=True) -> int:
    """Add a dependency (an input) to this node, which dirties it.

    Args:
        node (DagNode): The new dependency to add
        connect_reverse (bool, optional): Also add this node to the input's outputs.
            Defaults to True.

    Returns:
        int: The key the dependency was stored under
    """
    key = self.next_key(self._connections.inputs)
    self._connections.inputs[key] = node
    self.set_graph_id(node)
    # Only self's depth (and its dependants'/owner's) can have moved -- node keeps
    # whatever depth it had, since gaining a dependant says nothing about its own
    # distance from the roots.
    chunk_scheduler.topology_changed(self)
    # A new chunk above self: what it and everything below it cooked on is gone.
    chunk_cook.inputs_rewired(self)

    if connect_reverse:
        node.add_dependant(self)
    else:
        self.dirty = True

    return key

dirty_dependants ⚓︎

dirty_dependants()

Mark every output and the owner dirty, transitively.

Each one records which change caused it. See chunk_scheduler.propagate_dirty.

Source code in usd_chunks/chunk_notice.py
def dirty_dependants(self):
    """Mark every output and the owner dirty, transitively.

    Each one records which change caused it. See chunk_scheduler.propagate_dirty.
    """
    chunk_scheduler.propagate_dirty(self)

disconnect ⚓︎

disconnect()

Drop every edge into and out of this node, on both sides.

Clearing only this node's own dicts leaves each peer still pointing back here, so a disconnected node stays reachable as somebody else's input or output. That was invisible while chunk-level edges were rarely populated, but request_delete calls this on any node with outputs -- a stale reverse link there resurrects the deleted chunk as a live dependency of its former successor.

Source code in usd_chunks/chunk_notice.py
def disconnect(self):
    """Drop every edge into and out of this node, on both sides.

    Clearing only this node's own dicts leaves each peer still pointing back here, so a
    disconnected node stays reachable as somebody else's input or output. That was
    invisible while chunk-level edges were rarely populated, but request_delete calls
    this on any node with outputs -- a stale reverse link there resurrects the deleted
    chunk as a live dependency of its former successor.
    """
    # Snapshot before mutating: the peer loops write to dicts these views come from, and
    # _connections.inputs/outputs are WeakValueDictionaries, which raise if they change
    # size mid-iteration.
    inputs = list(self._connections.inputs.values())
    outputs = list(self._connections.outputs.values())

    self._connections.inputs.clear()
    self._connections.outputs.clear()

    for node in inputs:
        node.remove_dependant(self)
    for node in outputs:
        node.remove_dependency(self, disconnect_reverse=False)

    chunk_scheduler.topology_changed()

get_graph_id ⚓︎

get_graph_id()

The identifier of the connected graph this node belongs to.

Source code in usd_chunks/chunk_notice.py
def get_graph_id(self):
    """The identifier of the connected graph this node belongs to."""
    return self._graph_id.get_identifier()

get_input ⚓︎

get_input(index)

Get the input stored under a key.

Parameters:

Name Type Description Default
index int

The key of the input to find

required

Raises:

Type Description
KeyError

If the key does not exist

Returns:

Name Type Description
DagNode DagNode

The found dag node

Source code in usd_chunks/chunk_notice.py
def get_input(self, index: int) -> DagNode:
    """Get the input stored under a key.

    Args:
        index (int): The key of the input to find

    Raises:
        KeyError: If the key does not exist

    Returns:
        DagNode: The found dag node
    """
    try:
        return self._connections.inputs[index]
    except KeyError:
        raise

get_inputs ⚓︎

get_inputs()

Get the input (dependency) nodes of this node.

Returns:

Type Description
Iterator[tuple[int, DagNode]]

Iterator[tuple[int, DagNode]]: (key, node) for each input

Source code in usd_chunks/chunk_notice.py
def get_inputs(self) -> Iterator[tuple[int, DagNode]]:
    """Get the input (dependency) nodes of this node.

    Returns:
        Iterator[tuple[int, DagNode]]: (key, node) for each input
    """
    return self._connections.inputs.items()

get_output ⚓︎

get_output(index)

Get the output stored under a key.

Parameters:

Name Type Description Default
index int

The key of the output to find

required

Raises:

Type Description
KeyError

If the key does not exist

Returns:

Name Type Description
DagNode DagNode

The found dag node

Source code in usd_chunks/chunk_notice.py
def get_output(self, index: int) -> DagNode:
    """Get the output stored under a key.

    Args:
        index (int): The key of the output to find

    Raises:
        KeyError: If the key does not exist

    Returns:
        DagNode: The found dag node
    """
    return self._connections.outputs[index]

get_outputs ⚓︎

get_outputs()

Get the output (dependant) nodes of this node.

Returns:

Type Description
Iterator[tuple[int, DagNode]]

Iterator[tuple[int, DagNode]]: (key, node) for each output

Source code in usd_chunks/chunk_notice.py
def get_outputs(self) -> Iterator[tuple[int, DagNode]]:
    """Get the output (dependant) nodes of this node.

    Returns:
        Iterator[tuple[int, DagNode]]: (key, node) for each output
    """
    return self._connections.outputs.items()

get_owner ⚓︎

get_owner()

Get the owner of this node: its 'parent', treated like an output.

The propagator, by contrast, is the ChunkNoticePropagator this node represents in the graph.

Returns:

Type Description
ChunkNoticePropagator | None

ChunkNoticePropagator | None: The owner if it exists, else None

Source code in usd_chunks/chunk_notice.py
def get_owner(self) -> ChunkNoticePropagator | None:
    """Get the owner of this node: its 'parent', treated like an output.

    The propagator, by contrast, is the ChunkNoticePropagator this node represents in the
    graph.

    Returns:
        ChunkNoticePropagator | None: The owner if it exists, else None
    """
    if owner := self._connections.owner:
        return owner()
    return None

get_owner_node ⚓︎

get_owner_node()

Get the owner's dag node: owner.get_dag_node().

Returns:

Type Description
DagNode | None

DagNode | None: The dag node of the owner, or None if there is no owner

Source code in usd_chunks/chunk_notice.py
def get_owner_node(self) -> DagNode | None:
    """Get the owner's dag node: owner.get_dag_node().

    Returns:
        DagNode | None: The dag node of the owner, or None if there is no owner
    """
    if owner := self.get_owner():
        return owner.get_dag_node()
    return None

get_sort_key ⚓︎

get_sort_key()

This node's position in the dependency order: the longest chain of dependencies ending here.

Derived from the graph on demand by chunk_scheduler rather than maintained on every connect.

Returns:

Name Type Description
int int

The sort key, 0 for a node with no dependencies

Source code in usd_chunks/chunk_notice.py
def get_sort_key(self) -> int:
    """This node's position in the dependency order: the longest chain of dependencies ending here.

    Derived from the graph on demand by chunk_scheduler rather than maintained on every
    connect.

    Returns:
        int: The sort key, 0 for a node with no dependencies
    """
    return chunk_scheduler.get_depth(self)

iter_changes ⚓︎

iter_changes()

The changes that dirtied this node, shallowest first.

Sorted by how often the source node was itself dirtied; ties keep the order the changes arrived in.

Yields:

Type Description
tuple[ChunkNoticeAlias, ChunkNoticePropagator | None]

(alias, propagator) for each change.

Source code in usd_chunks/chunk_notice.py
def iter_changes(
    self,
) -> Generator[tuple[ChunkNoticeAlias, ChunkNoticePropagator | None], None, StopIteration]:
    # Sorted by how often the source node was itself dirtied, so the shallowest
    # change is reported first; _changes is insertion-ordered, which makes the
    # tie-break between equally-dirtied sources the order they arrived in.
    """The changes that dirtied this node, shallowest first.

    Sorted by how often the source node was itself dirtied; ties keep the order the changes
    arrived in.

    Yields:
        (alias, propagator) for each change.
    """
    for alias, node in sorted(self._changes, key=lambda x: x[1]._index):
        yield alias, node.propagator
    return StopIteration()

next_key ⚓︎

next_key(items)

Get the next key for either inputs or outputs dictionaries. The result is safe to use as key for the dict.

Parameters:

Name Type Description Default
items ConnSetT

A dictionairy t find the next best key for

required

Raises:

Type Description
KeyError

No valid key was found

Returns:

Name Type Description
int int

A new valid key for the dict

Source code in usd_chunks/chunk_notice.py
def next_key(self, items: ConnSetT) -> int:
    """Get the next key for either inputs or outputs dictionaries. The result is safe to use as key for the dict.

    Args:
        items (ConnSetT): A dictionairy t find the next best key for

    Raises:
        KeyError: No valid key was found

    Returns:
        int: A new valid key for the dict
    """
    for i in range(len(items) + 1):
        if i not in items:
            return i
    raise KeyError("Somewthign went wrong")

only_presentation_changed ⚓︎

only_presentation_changed()

Whether every change that dirtied this node was presentation only.

That is, something nothing computes from. A chunk whose changes are all presentation must not re-cook.

The verdict is read back from what chunk_scheduler recorded when each change was propagated, not re-derived here. Both other ways of asking are lossy:

  • The aliases in _changes are only a proxy. A presentation_only param raises PARAM_CHANGED rather than STATE_CHANGED, so an alias test disagrees with AttributeSender.is_presentation_change in exactly that case.
  • Asking the sender again reads an old_value/value pair that has moved on since, and is only meaningful while the solve that recorded it is still running.

False when nothing was recorded, so a direct dirty solve -- execute-on-creation, which carries no propagated change -- still counts as real work and cooks.

Returns:

Name Type Description
bool bool

True if there is at least one recorded change and all of them are

bool

presentation only

Source code in usd_chunks/chunk_notice.py
def only_presentation_changed(self) -> bool:
    """Whether every change that dirtied this node was presentation only.

    That is, something nothing computes from. A chunk whose changes are all presentation
    must not re-cook.

    The verdict is read back from what chunk_scheduler recorded when each change was
    propagated, not re-derived here. Both other ways of asking are lossy:

    * The aliases in _changes are only a proxy. A `presentation_only` param raises
      PARAM_CHANGED rather than STATE_CHANGED, so an alias test disagrees with
      AttributeSender.is_presentation_change in exactly that case.
    * Asking the sender again reads an old_value/value pair that has moved on since,
      and is only meaningful while the solve that recorded it is still running.

    False when nothing was recorded, so a direct dirty solve -- execute-on-creation,
    which carries no propagated change -- still counts as real work and cooks.

    Returns:
        bool: True if there is at least one recorded change and all of them are
        presentation only
    """
    seen = False
    for (_alias, node), presentation in self._changes.items():
        # A dead propagator's reason is dropped, matching what iter_changes()'s
        # consumers already do: it can no longer describe anything.
        if node.propagator is None:
            continue
        if not presentation:
            return False
        seen = True
    return seen

remove_dependant ⚓︎

remove_dependant(node)

Remove a node that depends on this one (an output).

Parameters:

Name Type Description Default
node DagNode

The dependant node to remove

required

Returns:

Name Type Description
bool bool

True if node was an output and got removed

Source code in usd_chunks/chunk_notice.py
def remove_dependant(self, node: DagNode) -> bool:
    """Remove a node that depends on this one (an output).

    Args:
        node (DagNode): The dependant node to remove

    Returns:
        bool: True if node was an output and got removed
    """
    keys = [key for key, value in self._connections.outputs.items() if value is node]
    if not keys:
        return False

    for key in keys:
        del self._connections.outputs[key]
    # node is passed as well as self: the edge is being torn down from this side, so
    # node is already out of self's downstream closure by the time this runs.
    chunk_scheduler.topology_changed(self, node)
    return True

remove_dependency ⚓︎

remove_dependency(node, disconnect_reverse=True)

Remove a dependency (an input) from this node, which dirties it.

Losing an input changes what this node evaluates to. The counterpart to add_dependency; disconnect() drops every edge at once and is not a substitute when a single wire is detached.

Parameters:

Name Type Description Default
node DagNode

The dependency to remove

required
disconnect_reverse bool

If the input node should drop this node from its outputs. Defaults to True.

True

Returns:

Name Type Description
bool bool

True if node was an input and got removed

Source code in usd_chunks/chunk_notice.py
def remove_dependency(self, node: DagNode, disconnect_reverse=True) -> bool:
    """Remove a dependency (an input) from this node, which dirties it.

    Losing an input changes what this node evaluates to. The counterpart to add_dependency;
    disconnect() drops every edge at once and is not a substitute when a single wire is
    detached.

    Args:
        node (DagNode): The dependency to remove
        disconnect_reverse (bool, optional): If the input node should drop this node from
            its outputs. Defaults to True.

    Returns:
        bool: True if node was an input and got removed
    """
    # Keys are collected before deleting: _connections.inputs is a WeakValueDictionary,
    # so mutating it while iterating raises.
    keys = [key for key, value in self._connections.inputs.items() if value is node]
    if not keys:
        return False

    for key in keys:
        del self._connections.inputs[key]
    chunk_scheduler.topology_changed(self, node)
    chunk_cook.inputs_rewired(self)

    if disconnect_reverse:
        node.remove_dependant(self)

    self.dirty = True
    return True

set_graph_id ⚓︎

set_graph_id(node)

Merge this node's graph with node's, if both take part in a graph.

Parameters:

Name Type Description Default
node DagNode

The node being connected to.

required
Source code in usd_chunks/chunk_notice.py
def set_graph_id(self, node: DagNode):
    """Merge this node's graph with `node`'s, if both take part in a graph.

    Args:
        node: The node being connected to.
    """
    if not (node._part_of_graph and self._part_of_graph):
        return

    my_root = self._graph_id.root()
    other_root = node._graph_id.root()
    if my_root is other_root:
        # Already the same graph; linking again would create a cycle
        return
    other_root._store = my_root

set_owner ⚓︎

set_owner(owner, *, dirty=True)

Set the owner of this node.

The owner is treated like an output, with some semantic differences; see DagConnections.

Parameters:

Name Type Description Default
owner ChunkNoticePropagator | None

The owner propagator

required
dirty bool

Whether joining marks the owner dirty. A new child is new data for its owner; an attribute's own sender is not -- see AttributeSender.

True
Source code in usd_chunks/chunk_notice.py
def set_owner(self, owner: ChunkNoticePropagator | None, *, dirty: bool = True):
    """Set the owner of this node.

    The owner is treated like an output, with some semantic differences; see DagConnections.

    Args:
        owner (ChunkNoticePropagator | None): The owner propagator
        dirty (bool): Whether joining marks the owner dirty. A new child is new data for
            its owner; an attribute's own sender is not -- see AttributeSender.
    """
    if owner == self.get_owner():
        return

    assert isinstance(owner, ChunkNoticePropagator) or owner is None

    if (previous := self.get_owner_node()) and previous._owned is not None:
        previous._owned.discard(self)

    if owner is None:
        self._connections.owner = None
    else:
        self._connections.owner = weakref.ref(owner)

    # An owner takes the depth of the deepest thing it owns, so both the owner being
    # left and the one being joined have to be re-measured; self reaches the new one
    # through its own downstream closure.
    if previous is not None:
        chunk_scheduler.topology_changed(self, previous)
    elif self._is_isolated():
        # A node with no edges joining its first owner -- a param's attribute sender,
        # made the first time that attribute changes -- adds a leaf and moves nothing:
        # no path between other nodes, no depth (0 cannot deepen an owner).
        chunk_scheduler.leaf_joined(self)
    else:
        chunk_scheduler.topology_changed(self)

    if node := self.get_owner_node():
        if node._owned is None:
            node._owned = weakref.WeakSet()
        node._owned.add(self)
        if dirty:
            node.dirty = True
        node.set_graph_id(self)

should_solve ⚓︎

should_solve()

Whether this dirty node should solve.

A clean node never does. For a dirty one the check is whether it has outputs or an owner to propagate to -- but get_outputs() returns a WeakValueDictionary's items(), a generator, which is always truthy, so in practice every dirty node solves. Callers rely on that; it is not to be "fixed" in isolation.

Returns:

Name Type Description
bool bool

Whether the node should solve

Source code in usd_chunks/chunk_notice.py
def should_solve(self) -> bool:
    """Whether this dirty node should solve.

    A clean node never does. For a dirty one the check is whether it has outputs or an
    owner to propagate to -- but get_outputs() returns a WeakValueDictionary's items(), a
    generator, which is always truthy, so in practice every dirty node solves. Callers
    rely on that; it is not to be "fixed" in isolation.

    Returns:
        bool: Whether the node should solve
    """
    if not self.dirty:
        return False

    if self.get_outputs() or self.get_owner_node():
        return True
    return False

solve_outputs ⚓︎

solve_outputs()

Solve this node, then everything downstream of it and its owner.

This is the solve method clients should use, as it makes every dependent node solve once this one has. The solve starts at the dirty frontier upstream of this node, so a node whose own dependencies have not run yet still solves in the right order. See chunk_scheduler.solve.

Yields:

Name Type Description
DagNode DagNode

Every node solved, this one included

Source code in usd_chunks/chunk_notice.py
def solve_outputs(self) -> Generator[DagNode, None, None]:
    """Solve this node, then everything downstream of it and its owner.

    This is the solve method clients should use, as it makes every dependent node solve once
    this one has. The solve starts at the dirty frontier upstream of this node, so a node
    whose own dependencies have not run yet still solves in the right order. See
    chunk_scheduler.solve.

    Yields:
        DagNode: Every node solved, this one included
    """
    yield from chunk_scheduler.solve(self)

DependencyAddedNotice ⚓︎

DependencyAddedNotice(data=None)

Bases: ChunkNotice

Sent when add_dependency() is called. sender=dependent, data=input propagator.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

DependencyRemovedNotice ⚓︎

DependencyRemovedNotice(data=None)

Bases: ChunkNotice

Sent when remove_dependency() removed an input. sender=dependent, data=input propagator.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

GizmoChangedNotice ⚓︎

GizmoChangedNotice(data=None)

Bases: ChunkNotice

Sent when a gizmo drag moves.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

GizmoStartedNotice ⚓︎

GizmoStartedNotice(data=None)

Bases: ChunkNotice

Sent when a host starts dragging a gizmo.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

GizmoStoppedNotice ⚓︎

GizmoStoppedNotice(data=None)

Bases: ChunkNotice

Sent when a host stops dragging a gizmo.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

GroupChangeNotice ⚓︎

GroupChangeNotice(data=None)

Bases: ChunkNotice

Sent when a group or anything inside it changes; data is the group.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

InputChangedNotice ⚓︎

InputChangedNotice(data=None)

Bases: ChunkNotice

Sent when a dependency of a chunk object changes; data is the object.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

MenuActionNotice ⚓︎

MenuActionNotice(data=None)

Bases: ChunkNotice

Sent when a menu action should run.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

NoticeConnection ⚓︎

NoticeConnection(method=None, alias=ChunkNoticeAlias.NONE, sender=None, globally=False, owner=None)

A Tf.Notice listener with a simple client-facing interface, as ChunkNoticePropagators store them.

All references to external objects -- method, sender and owner -- are weakrefs, so the connection never takes ownership; properties give access to them. Because of this, connection.method, connection.owner or connection.sender may be None once collected. If any of the weakrefs dies, the connection is broken.

The owner passes an additional object to the call, enabling::

def func(obj: AClass, notice, sender):
    pass


class AClass:
    def __init__(self):
        NoticeConnection(func, owner=self)

as well as::

class AnotherClass:
    def func(self, notice, sender):
        pass


def bind(obj: AnotherClass):
    return NoticeConnection(obj.func, owner=obj)

If the owner implements get_stage() and get_edit_context(), the method runs inside that edit context, so all its edits land in that layer.

Attributes:

Name Type Description
alias ChunkNoticeAlias

The ChunkNoticeAlias of the notice to listen for

sender Any | None

The sender of the notice. When globally is True, this has no effect

globally bool

Listen for every notice of this alias, whatever its sender

owner ChunkNoticePropagator | None

An optional owner object. Usually 'self', when adding callbacks on a class

Source code in usd_chunks/chunk_notice.py
def __init__(
    self,
    method: Callable | None = None,
    alias: ChunkNoticeAlias = ChunkNoticeAlias.NONE,
    sender: Any | None = None,
    globally: bool = False,
    owner: ChunkNoticePropagator | None = None,
):
    self.alias: ChunkNoticeAlias = alias
    self.globally: bool = globally

    self._listener: Tf.Notice.Listener | None = None

    if method and method.__name__ == "<lambda>":
        self._method = method
    elif inspect.ismethod(method):
        self._method: Callable = weakref.WeakMethod(method, self._broke_callback())
    else:
        self._method: Callable = weakref.ref(method, self._broke_callback())

    self._sender: weakref.ReferenceType | None = weakref.ref(sender, self._broke_callback()) if sender else None
    self._owner: weakref.ReferenceType | None = weakref.ref(owner, self._broke_callback()) if owner else None

    self.connect()

owner property writable ⚓︎

owner

The owner passed to the callback, or None once collected.

sender property writable ⚓︎

sender

The sender listened to, or None once collected.

__del__ ⚓︎

__del__()

Revoke the listener when the connection is collected.

Source code in usd_chunks/chunk_notice.py
def __del__(self):
    """Revoke the listener when the connection is collected."""
    self.disconnect()

connect ⚓︎

connect(sender=None)

Build the Tf listener from this connection's settings.

Parameters:

Name Type Description Default
sender Any

Override the sender. Defaults to None.

None
Source code in usd_chunks/chunk_notice.py
def connect(self, sender=None):
    """Build the Tf listener from this connection's settings.

    Args:
        sender (Any, optional): Override the sender. Defaults to None.
    """
    notice = get_notice(self.alias)
    if not notice:
        logger.warning("Could not find appropriate notice to connect for alias %s", self.alias)
        return

    if self._listener is not None:
        self.disconnect()

    if sender is not None:
        self._sender = weakref.ref(sender, self._broke_callback())

    if self.globally:
        self._listener = _register_global(self.alias, notice, self)
    elif self.sender is None:
        self._listener = Tf.Notice.RegisterGlobally(notice, self.handle_callback)
    elif self.sender:
        self._listener = Tf.Notice.Register(notice, self.handle_callback, self.sender)

disconnect ⚓︎

disconnect()

Revoke the stored Tf listener.

Source code in usd_chunks/chunk_notice.py
def disconnect(self):
    """Revoke the stored Tf listener."""
    if self._listener is not None:
        self._listener.Revoke()
        self._listener = None

get_method ⚓︎

get_method()

Get the referenced method or function.

Returns:

Type Description
Callable | None

Callable | None: The callable if it is still alive, otherwise None

Source code in usd_chunks/chunk_notice.py
def get_method(self) -> Callable | None:
    """Get the referenced method or function.

    Returns:
        Callable | None: The callable if it is still alive, otherwise None
    """
    if not isinstance(self._method, weakref.ReferenceType):
        return self._method
    return self._method()

handle_callback ⚓︎

handle_callback(notice, sender=None, context=True, origin=None)

Forward a notice to the callback, if the method, sender and owner are still alive.

If the owner is valid and implements get_stage() and get_edit_context(), the method is called inside that edit context, so its stage edits land in the right layer.

The callback may declare either (notice, sender) -- matching Tf.Notice -- or (owner, notice, sender). Which one it gets is decided by its own signature, so both forms work whether the callback is a plain function or a bound method.

Parameters:

Name Type Description Default
notice Notice

The notice to forward

required
sender ChunkNoticePropagator

The sender of the original notice. Defaults to None.

None
context bool

Run inside the owner's edit context. Defaults to True.

True
origin _NoticeOrigin

Where the notice came from, when the caller has already worked it out for several listeners. Defaults to working it out.

None
Source code in usd_chunks/chunk_notice.py
def handle_callback(self, notice, sender=None, context=True, origin=None):
    """Forward a notice to the callback, if the method, sender and owner are still alive.

    If the owner is valid and implements get_stage() and get_edit_context(), the method is
    called inside that edit context, so its stage edits land in the right layer.

    The callback may declare either (notice, sender) -- matching Tf.Notice -- or
    (owner, notice, sender). Which one it gets is decided by its own signature, so both
    forms work whether the callback is a plain function or a bound method.

    Args:
        notice (Tf.Notice): The notice to forward
        sender (ChunkNoticePropagator, optional): The sender of the original notice. Defaults to None.
        context (bool, optional): Run inside the owner's edit context. Defaults to True.
        origin (_NoticeOrigin, optional): Where the notice came from, when the caller has
            already worked it out for several listeners. Defaults to working it out.
    """
    if not (meth := self.get_method()):
        return

    owner = self.owner
    if self._owner is not None and owner is None:
        # This connection was registered with an owner and that owner has since been
        # collected, so the subscriber no longer exists. Dispatching now would hand the
        # callback a dead owner; the connection is torn down via _connection_broke.
        return

    args = (owner, notice, sender) if self._wants_owner(meth) else (notice, sender)
    if owner:
        if origin is None:
            origin = _NoticeOrigin(notice)
        cooking = _executing_chunk
        if cooking is None or getattr(owner, "get_chunk", lambda: None)() is not cooking:
            # Another chunk is cooking, and its stage is the cook's (skip_cook): only what
            # that cook reads, and whatever is looked up there is charged to it. A Set
            # Camera refreshing its menu by a Traverse during an Add Variants cook made Add
            # Variants read the whole stage, so it cooked on every edit above it. The cook
            # stage's notice is a copy -- the scene's stage hears the same layer edit -- so
            # it is dropped, and the scene's is handled on the scene's stage. With no
            # chunk cooking, a cook stage is being opened: muting its hidden layers is
            # nobody's change, and every Set Camera and Set Variant rebuilt its menus
            # for it on every masked cook.
            if origin.cook:
                return
            if cooking is not None:
                with chunk_cook.outside_cook():
                    self._call_for_owner(owner, meth, args, origin, context)
                return
        self._call_for_owner(owner, meth, args, origin, context)
        return

    meth(*args)

trigger ⚓︎

trigger()

Call the callback directly with this connection's alias and sender.

No Tf.Notice is sent.

Source code in usd_chunks/chunk_notice.py
def trigger(self):
    """Call the callback directly with this connection's alias and sender.

    No Tf.Notice is sent.
    """
    self.handle_callback(get_notice(self.alias), self.sender)

ParamAddedNotice ⚓︎

ParamAddedNotice(data=None)

Bases: ChunkNotice

Sent when a param is added to a group or chunk; data is the param.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ParamChangeNotice ⚓︎

ParamChangeNotice(data=None)

Bases: ChunkNotice

Sent when a param changes; data is the param.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ParamRemovedNotice ⚓︎

ParamRemovedNotice(data=None)

Bases: ChunkNotice

Sent when a param is removed from a group or chunk; data is the param.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

PrimSelectionChangedNotice ⚓︎

PrimSelectionChangedNotice(data=None)

Bases: ChunkNotice

Sent when the host's prim selection changes; data is the selected prims.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

PropSelectionChangedNotice ⚓︎

PropSelectionChangedNotice(data=None)

Bases: ChunkNotice

Sent when the host's property selection changes; data is the property.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

RegistrySingleton ⚓︎

Bases: type

Metaclass that makes a class a process-wide singleton: every call returns the one instance.

ValueChangedNotice ⚓︎

ValueChangedNotice(data=None)

Bases: AttributeChangeNotice

Sent when a param's value changes.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

ViewportRendererSettingsChangedNotice ⚓︎

ViewportRendererSettingsChangedNotice(data=None)

Bases: ChunkNotice

Sent when the host's own UI (usdview's Hydra Settings) sets renderer settings on the viewport's delegate; data is (renderer plugin id, {setting key: value}). Not sent for settings a chunk set through ChunkScene.set_viewport_renderer_settings.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

WidgetChangedNotice ⚓︎

WidgetChangedNotice(data=None)

Bases: ChunkNotice

Sent when a param widget changes; data is the widget.

Source code in usd_chunks/chunk_notice.py
def __init__(self, data: Any = None):
    super().__init__()
    self.data = data

chunk_notice ⚓︎

chunk_notice(alias)

Decorator that registers a Tf.Notice class with the ChunkNoticeRegistry under an alias.

Once registered, get_notice(alias).Send() sends it.

Parameters:

Name Type Description Default
alias ChunkNoticeAlias

The alias which maps to the new Tf.Notice class

required

Returns:

Type Description

The class decorator.

Source code in usd_chunks/chunk_notice.py
def chunk_notice(alias: ChunkNoticeAlias):
    """Decorator that registers a Tf.Notice class with the ChunkNoticeRegistry under an alias.

    Once registered, ``get_notice(alias).Send()`` sends it.

    Args:
        alias (ChunkNoticeAlias): The alias which maps to the new Tf.Notice class

    Returns:
        The class decorator.
    """

    def _wrapper(cls):
        ChunkNoticeRegistry().register(alias, cls)
        Tf.Type.Define(cls)
        return cls

    return _wrapper

get_notice ⚓︎

get_notice(alias)

The Tf.Notice class registered for a ChunkNoticeAlias.

Parameters:

Name Type Description Default
alias ChunkNoticeAlias

The alias to look up

required

Returns:

Type Description
type[ChunkNotice]

type[ChunkNotice]: The notice class

Raises:

Type Description
ErrorException

If the alias has not been registered

Source code in usd_chunks/chunk_notice.py
def get_notice(alias: ChunkNoticeAlias) -> type[ChunkNotice]:
    """The Tf.Notice class registered for a ChunkNoticeAlias.

    Args:
        alias (ChunkNoticeAlias): The alias to look up

    Returns:
        type[ChunkNotice]: The notice class

    Raises:
        Tf.ErrorException: If the alias has not been registered
    """
    return ChunkNoticeRegistry().get_from_alias(alias)

is_notice_type ⚓︎

is_notice_type(notice, alias)

Check whether a notice is the class registered for an alias.

Parameters:

Name Type Description Default
notice Notice

The notice to check

required
alias ChunkNoticeAlias

The alias to compare against

required

Returns:

Name Type Description
bool TypeGuard[ChunkNotice]

True if get_notice(alias) is exactly the notice's type

Source code in usd_chunks/chunk_notice.py
def is_notice_type(notice: Tf.Notice, alias: ChunkNoticeAlias) -> TypeGuard[ChunkNotice]:
    """Check whether a notice is the class registered for an alias.

    Args:
        notice (Tf.Notice): The notice to check
        alias (ChunkNoticeAlias): The alias to compare against

    Returns:
        bool: True if get_notice(alias) is exactly the notice's type
    """
    return type(notice) is get_notice(alias)

send_notice ⚓︎

send_notice(alias, sender=None, data=None)

Send a notice of type alias, running the callbacks subscribed to it.

Parameters:

Name Type Description Default
alias ChunkNoticeAlias

The type of the notice to send

required
sender Any

The object to pass as sender. If None, the notice is sent globally. Defaults to None.

None
data Any

Any additional data to attach to the notice object. Defaults to None.

None

Returns:

Type Description
ChunkNotice | None

ChunkNotice | None: The sent notice, or None if the alias is not a ChunkNotice.

Source code in usd_chunks/chunk_notice.py
def send_notice(alias: ChunkNoticeAlias, sender: Any = None, data: Any = None) -> ChunkNotice | None:
    """Send a notice of type alias, running the callbacks subscribed to it.

    Args:
        alias (ChunkNoticeAlias): The type of the notice to send
        sender (Any, optional): The object to pass as sender. If None, the notice is sent
            globally. Defaults to None.
        data (Any, optional): Any additional data to attach to the notice object. Defaults to None.

    Returns:
        ChunkNotice | None: The sent notice, or None if the alias is not a ChunkNotice.
    """
    # Exception is handled upstream
    notice_class = get_notice(alias)

    if issubclass(notice_class, ChunkNotice):
        notice = notice_class(data)
    else:
        # notices not derived from ChunkNotice should not be sent
        return None

    try:
        if sender is None:
            notice.SendGlobally()
        else:
            notice.Send(sender)
    except Tf.ErrorException:
        logger.exception("Could not send notice %s", notice)
        return

    return notice

without_edit_context ⚓︎

without_edit_context(meth)

Mark a callback to run outside its owner's edit context.

For a callback that authors nothing itself, only hands on to others that each run in their own: resolving the context makes the owner's layer, which puts it on the stage.

Source code in usd_chunks/chunk_notice.py
def without_edit_context(meth):
    """Mark a callback to run outside its owner's edit context.

    For a callback that authors nothing itself, only hands on to others that each run in
    their own: resolving the context makes the owner's layer, which puts it on the stage.
    """
    meth._without_edit_context = True
    return meth