add_event_handler#

ReferenceIndices.add_event_handler(handler, event='indices')[source]#

Register an event handler that is called whenever the indices change.

Parameters:
  • handler (Callable) – callback function, must take a tuple of int as the only argument. This tuple will be the indices

  • event (str, "indices") – the only supported valid is “indices”

Example

def my_handler(indices):
    print(indices)
    # example prints: {"t": 100, "z": 15} if the index has 2 reference spaces "t" and "z"

# create an NDWidget
ndw = NDWidget(...)

# add event handler
ndw.indices.add_event_handler(my_handler)