simvx.core.signals¶
Signal and Connection classes: observable event dispatcher.
Leaf module with no engine dependencies. 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. |
Data¶
API¶
- simvx.core.signals.log¶
‘getLogger(…)’
- class simvx.core.signals.Connection(signal: simvx.core.signals.Signal, fn: collections.abc.Callable)[source]¶
Handle returned by
Signal.connect(). Can disconnect and acts as a callable proxy.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 shared signal: useful for global event hubs likeNode.script_error_raised.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(50) # only p1 listeners fireInitialization
- __slots__¶
(‘_callbacks’, ‘_types’, ‘_name’)
- classmethod __class_getitem__(params) simvx.core.signals.Signal[source]¶
Bracket syntax:
Signal[int],Signal[int, str].
- 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. once: If True, auto-disconnect after first emit.
- __call__(*args, **kwargs)[source]¶
Emit the signal, calling all connected callbacks with the given arguments.
Connections whose weak target was garbage-collected are skipped and pruned from
_callbacksafter the dispatch loop. A callback that disconnects another callback mid-emit only marks the peer_connected=False: the live list still holds it, so an unconditional rebuild after dispatch keeps the invariant that_callbacksonly ever contains connected entries.
- 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.
- emit¶
None