def connect(self, event, func=None):
if event not in self._callbacks:<EOL><INDENT>raise ValueError("<STR_LIT>".format(event))<EOL><DEDENT>if func is None:<EOL><INDENT>return partial(self.connect, event)<EOL><DEDENT>self._callbacks[event].append(func)<EOL>return func<EOL>
Connect a callback to a `Cursor` event; return the callback.

Two events can be connected to:

- callbacks connected to the ``"add"`` event are called when a
  `Selection` is added, with that selection as only argument;
- callbacks connected to the ``"remove"`` event are called when a
  `Selection` is removed, with that selection as only argument.

This method can also be used as a decorator::

    @cursor.connect("add")
    def on_add(sel):
        ...

Examples of callbacks::

    # Change the annotation text and alignment:
    lambda sel: sel.annotation.set(
        text=sel.artist.get_label(),  # or use e.g. sel.target.index
        ha="center", va="bottom")

    # Make label non-draggable:
    lambda sel: sel.draggable(False)