madgui.util.signal module

This module provides a very lightweight alternative for Qt’s signals that is easier to use in a non-GUI environment since it doesn’t require creating and initializing QApplication first, nor deriving from QObject.

Classes

Signal([doc])

Decorator for lightweight signals to be used in a class context.

class madgui.util.signal.Signal(doc='')[source]

Bases: object

Decorator for lightweight signals to be used in a class context.

Use as follows:

>>> class Car:
...     gear_changed = Signal()
>>> car = Car()
>>> car.gear_changed.connect(lambda gear: print("New gear:", gear))
>>> car.gear_changed.emit(12)
New gear: 12

This works similar to pyqtSignal, but always uses the same connection mode for all connected handlers. This can be either:

  • direct mode: immediately calls all handlers

  • queued mode: schedules handlers for another main loop iteration

Default is direct mode.

Note that direct mode is similar to Qt.DirectConnection and queued mode similar to Qt.QueuedConnection, but differs in that it merges multiple subsequent signal emissions into one (as long as the event has not been processed).