monitor module#
Callbacks on changes to a runtime design’s layout.
Reached through RuntimeDesign.layout.monitor. Changes are reported however
they were made: by requests, in the UI, or by other clients. User events,
subclasses of UserEvent, are application-defined events sent with
RuntimeDesign.layout.emit or by other clients (such as UI hooks).
- type JSON = str | int | float | bool | None | list[JSON] | dict[str, JSON]#
A JSON-compatible value.
- class UserEvent(data=None, objects=())[source]#
Bases:
objectBase for application-defined layout events.
Subclass it to define a kind of event; the subclass’s fully qualified name identifies the kind on the wire, so events of different applications do not collide. An event carries JSON-compatible
dataand a sequence of layoutobjects(components, ports, routes, vias, …), whichdatamay refer to by index. A subclass may parse both into its own fields, and may override thedataandobjectsproperties, which are what is sent.A received event is constructed as
cls(data, objects), so a subclass must accept those two arguments positionally, and call this__init__.>>> class Highlight(UserEvent): ... def __init__(self, data: Mapping[str, JSON], objects: Sequence[object | None]): ... super().__init__(data, objects) ... self.color = data["color"] >>> await design.layout.emit(Highlight({"color": "red"}, [c.u1]))
- Parameters:
- class Changes[T](added=(), changed=(), removed=())[source]#
Bases:
Generic[T]Objects of one kind added, changed, or removed by one change to the layout. Removed objects are no longer in the design tree. An object the runtime replaces when it changes (a via, a control point, an area region’s feature) is reported as removed, and its replacement as added.
- class Monitor(remove)[source]#
Bases:
objectA registered callback. Unregister it with
close(), or by using it as a context manager.>>> with design.layout.monitor.placements(moved): ... ...
- Parameters:
remove (Callable[[], None])
- class LayoutMonitor(monitors)[source]#
Bases:
objectRegisters callbacks run on changes to a runtime design’s layout.
Callbacks run on the runtime’s event loop as changes arrive, after the whole change has been applied to
design.root, and receive objects of the current tree (a capture replaces it). A callback returning an awaitable has it run as a task. A callback must not block: blocking calls on a sync design (requests, capture) raise when made from one. Exceptions raised by a callback are logged.- Parameters:
monitors (_Monitors)
- placements(callback)[source]#
Run
callbackwith the instances whose placement changed.Each moved instance is reported, including those anchored to a moved one; circuits are reported when they move as a whole.
- routes(callback)[source]#
Run
callbackwith the routes the runtime made, rerouted (routed or blocked), or removed.
- vias(callback)[source]#
Run
callbackwith the vias the runtime added, moved, or removed. A via placed in code is not reported.
- controls(callback)[source]#
Run
callbackwith the control points the runtime added, changed, or removed. A control point placed in code is not reported.- Return type:
- Returns:
The registration; close it to stop.
- Parameters:
callback (Callable[[Changes[ControlPoint]], object])
- regions(callback)[source]#
Run
callbackwith the area regions the runtime added, changed, or removed: a feature per region, and for a copper pour region aPourper layer (changed when its rank changes; seepours()for its copper).
- pours(callback)[source]#
Run
callbackwith the pours whose copper the runtime computed (changed, or added for a pour the design did not have), or removed. A pour removed with its area region is reported byregions().
- user_event_proto(event, rmap)[source]#
The wire form of
event.- Raises:
TypeError – if
datais not JSON-compatible.ValueError – if an object has no runtime ID.
- Return type:
UserEvent- Parameters:
event (UserEvent)
rmap (ReverseMapper)