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

Connection

Handle returned by Signal.connect(), which disconnects the callback it holds.

Signal

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’)

disconnect()[source]

Disconnect this callback from the signal.

property connected: bool[source]
__bool__()[source]
__repr__()[source]
class simvx.core.signals.Signal(*types: type)[source]

Observable event dispatcher with optional type metadata.

Used as a class attribute, Signal is a non-data descriptor: each instance accessing it lazily gets its own Signal copy stored in obj.__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 fire

emit is the one way to fire a signal. To forward one signal into another, connect the other’s emit: a.connect(b.emit).

Initialization

__slots__

(‘_callbacks’, ‘_types’, ‘_name’)

__set_name__(owner, name)[source]
__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; a Signal itself is refused. once: If True, auto-disconnect after first emit.

Raises: TypeError: fn is a Signal rather than a callable.

disconnect(fn_or_conn)[source]

Remove a previously connected callback or Connection.

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 _callbacks and 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.

clear()[source]

Remove all connected callbacks.

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.

__repr__()[source]