events module#

Event System#

This module declares the JITX event system for triggering behavior at specific points during design processing and instantiation.

class Event[source]#

Bases: Generic

Events can be used to trigger various behavior throughout your design, such as verifying a particular condition after the design has been fully instantiated.

Some events are predefined and will be triggered automatically by the framework, and user defined events have to be triggered manually. Subclass this class to create a user defined event.

classmethod on(method)[source]#

Register a method to be called when this event fires. The method should accept an instance of the event as argument.

The method will be called with the context set to the same context that was enabled when the method was registered.

>>> class MyComponent(Component):
        @Design.Initialized.on
        def on_initialized(self, init: Design.Initialized):
            ... # do something after initialization
Parameters:

method (Callable[[Any, Self], T] | Callable[[Self], T] | Callable[[], T])

fire()[source]#

Fire this event.

Note that firing predefined events when they’re not expected may cause unpredictable results as internal infrastructure may rely on them.

>>> @dataclass
... class MyEvent(Event):
        some_field: str
>>> class MyComponent(Component):
...     @MyEvent.on
...     def my_event_handler(self, myevent):
...         print(f"Hello {myevent.some_field}!")
...
...     @Design.Initialized.on
...     def on_initialized(self):
...         MyEvent("World").fire()
class EventContext(events=<factory>)[source]#

Bases: Context

Context for managing event handlers during design processing.

Parameters:

events (dict[type[Event], list[tuple[Callable, Frame]]])

events: dict[type[Event], list[tuple[Callable, Frame]]]#