simvx.core.signals¶
Signal and Connection classes: observable event dispatcher.
Leaf module: it imports only diagnostics eagerly, and reads
Node.dev_warnings through a deferred import. Used by Property descriptors,
Selection, UndoStack, EventBus, and any node-attached signal.
Module Contents¶
Classes¶
Handle returned by |
|
Observable event dispatcher with optional type metadata. |
API¶
- class simvx.core.signals.Connection(signal: simvx.core.signals.Signal, fn: collections.abc.Callable)[source]¶
Handle returned by
Signal.connect(), which disconnects the callback it holds.For bound methods on Nodes (objects exposing
_outgoing_connections), the callback is held weakly and the connection auto-cleans when the node is destroyed: matching Godot 4’s signal lifecycle. Other callables (lambdas, free functions, methods on non-Node objects) keep a strong reference.Initialization
- __slots__¶
(‘_signal’, ‘_fn’, ‘_weak’, ‘_connected’)
- class simvx.core.signals.Signal(*types: type)[source]¶
Observable event dispatcher with optional type metadata.
Used as a class attribute,
Signalis a non-data descriptor: each instance accessing it lazily gets its own Signal copy stored inobj.__dict__. Class-level access (Cls.signal_name) returns the declaration itself, which no instance ever emits.Example::
class Player(Node): health_changed = Signal(int) # typed: emits one int p1, p2 = Player(), Player() p1.health_changed.connect(on_p1) # instance-scoped p1.health_changed.emit(50) # only p1 listeners fireemitis the one way to fire a signal. To forward one signal into another, connect the other’semit:a.connect(b.emit).Initialization
- __slots__¶
(‘_callbacks’, ‘_types’, ‘_name’)
- __get__(obj: object, objtype: type | None = None) simvx.core.signals.Signal[source]¶
- connect(fn: collections.abc.Callable, *, once: bool = False) simvx.core.signals.Connection[source]¶
Subscribe a callback. Returns a Connection handle.
Args: fn: Callback to invoke on emit. To forward into another signal, pass its bound
emit; aSignalitself is refused. once: If True, auto-disconnect after first emit.Raises: TypeError:
fnis aSignalrather than a callable.
- emit(*args, **kwargs)[source]¶
Emit the signal, calling all connected callbacks with the given arguments.
The loop runs over a snapshot, so a callback that connects another callback mid-emit does not reach it in this emit, and one that disconnects a later callback stops it at once: disconnecting removes the connection from
_callbacksand marks it, and the loop skips a marked one. A connection whose weak target was garbage-collected is marked as it is reached and pruned after the loop.
- disconnect_from_module(module_name: str) int[source]¶
Drop all connections whose callback is defined in
module_name.Used by the hot-reload system to release references to old-module code (lambdas, free functions, methods) before reload, so the old module can be garbage-collected.
Returns the number of connections dropped.