Setup a handler to be called when a trait changes. This is used to setup dynamic notifications of trait changes. Parameters ---------- handler : callable A callable that is called when a trait changes. Its signature should be ``handler(change
(
self,
handler: t.Callable[..., t.Any],
names: Sentinel | str | t.Iterable[Sentinel | str] = All,
type: Sentinel | str = "change",
)
| 1647 | self.observe(_callback_wrapper(handler), names=name) |
| 1648 | |
| 1649 | def observe( |
| 1650 | self, |
| 1651 | handler: t.Callable[..., t.Any], |
| 1652 | names: Sentinel | str | t.Iterable[Sentinel | str] = All, |
| 1653 | type: Sentinel | str = "change", |
| 1654 | ) -> None: |
| 1655 | """Setup a handler to be called when a trait changes. |
| 1656 | |
| 1657 | This is used to setup dynamic notifications of trait changes. |
| 1658 | |
| 1659 | Parameters |
| 1660 | ---------- |
| 1661 | handler : callable |
| 1662 | A callable that is called when a trait changes. Its |
| 1663 | signature should be ``handler(change)``, where ``change`` is a |
| 1664 | dictionary. The change dictionary at least holds a 'type' key. |
| 1665 | * ``type``: the type of notification. |
| 1666 | Other keys may be passed depending on the value of 'type'. In the |
| 1667 | case where type is 'change', we also have the following keys: |
| 1668 | * ``owner`` : the HasTraits instance |
| 1669 | * ``old`` : the old value of the modified trait attribute |
| 1670 | * ``new`` : the new value of the modified trait attribute |
| 1671 | * ``name`` : the name of the modified trait attribute. |
| 1672 | names : list, str, All |
| 1673 | If names is All, the handler will apply to all traits. If a list |
| 1674 | of str, handler will apply to all names in the list. If a |
| 1675 | str, the handler will apply just to that name. |
| 1676 | type : str, All (default: 'change') |
| 1677 | The type of notification to filter by. If equal to All, then all |
| 1678 | notifications are passed to the observe handler. |
| 1679 | """ |
| 1680 | for name in parse_notifier_name(names): |
| 1681 | self._add_notifiers(handler, name, type) |
| 1682 | |
| 1683 | def unobserve( |
| 1684 | self, |