Virtual module#

SunFlare virtual module.

This module implements the communication mechanism between the controller layer and the view layer.

It achieves this by using the psygnal library.

The module exposes the following:

  • the psygnal.Signal class;

  • the VirtualBus class;

  • the ModuleVirtualBus class;

  • the slot decorator.

psygnal.Signal is the main communication mechanism between controllers and the view layer.

It provides a syntax similar to the Qt signal/slot mechanism, i.e.

class MyController:
    sigMySignal = Signal()


def a_slot():
    print("My signal was emitted!")


ctrl = MyController()
ctrl.sigMySignal.connect(my_slot)
  • The VirtualBus class is the base class for building virtual communication buses. It must be re-implemented by users that wish to create new modules for RedSun.

  • The ModuleVirtualBus class is a pre-defined bus that acts as the main communication mechanism between modules. Different modules can share information by emitting signals on this bus and connecting to them.

  • The slot decorator is used to mark a function as a slot. In practice, it provides no benefit at runtime; it’s used to facilitate code readability.

# slot will mark the function as a slot
@slot
def my_slot():
    print("My slot was called!")
class sunflare.virtual.VirtualBus#

Bases: Loggable

VirtualBus abstract base class. Supports logging via Loggable.

The VirtualBus is a mechanism to exchange data between different parts of the system.

It can be used to emit notifications, as well as carry information to other plugins and/or different RedSun modules.

VirtualBus’ signals are implemented using the psygnal library; they can be dynamically registered as class attributes, and accessed as a read-only dictionary.

register_signals(owner, only=None)#

Register the signals of an object in the virtual bus.

Parameters:
  • owner (object) – The instance whose class’s signals are to be cached.

  • only (iterable of str, optional) – A list of signal names to cache. If not provided, all signals in the class will be cached automatically by inspecting the class attributes.

Return type:

None

Notes

This method inspects the attributes of the owner’s class to find psygnal.Signal descriptors. For each such descriptor, it retrieves the SignalInstance from the owner using the descriptor protocol and stores it in the registry.

final class sunflare.virtual.ModuleVirtualBus#

Bases: VirtualBus

Inter-module virtual bus.

Communication between modules passes via this virtual bus. There can be only one instance of this class within a RedSun application.

sunflare.virtual.slot(func: F) F#
sunflare.virtual.slot(*, private: bool) Callable[[F], F]

Decorate a function as a slot.

Parameters:
  • func (F, optional) – The function to decorate. If not provided, the decorator must be applied with arguments.

  • private (bool, optional) – Mark the slot as private. Default is False.

Returns:

Either the decorated function or a callable decorator.

Return type:

Union[F, Callable[[F], F]]