Repository: matplotlib/matplotlib
File: lib/matplotlib/widgets.py (Python)

Code before:
        When the user hits enter or leaves the submission box, call this
        *func* with event.

        A connection id is returned which can be used to disconnect.
        """
        return self._observers.connect('submit', lambda text: func(text))

    def disconnect(self, cid):
        """Remove the observer with connection id *cid*."""
        self._observers.disconnect(cid)


def _calculate_widget_button_layout(ax, labels, label_props, layout):
    """
    Calculate positions for button widgets (RadioButtons, CheckButtons).

    Parameters
    ----------
    ax : `~matplotlib.axes.Axes`
        The Axes to calculate positions for.
    labels : list of str
        The button labels.
    label_props : iterable of dict
        Text properties for each label (from _expand_text_props).
    layout : None or "vertical" or "horizontal" or (int, int)
        Same layout argument as in `.widgets.RadioButtons`.

    Returns
    -------
    button_xs : list of float
        X coordinates for buttons in axes coordinates.
    button_ys : list of float
        Y coordinates for buttons in axes coordinates.
    label_xs : list of float
        X coordinates for labels in axes coordinates.
    label_ys : list of float
        Y coordinates for labels in axes coordinates.
    """
    n_labels = len(labels)

    if layout is None:
        # Legacy behavior: simple vertical layout with fixed positions
        ys = np.linspace(1, 0, n_labels + 2)[1:-1]
        button_xs = [0.15] * n_labels
        button_ys = list(ys)
        label_xs = [0.25] * n_labels
        label_ys = list(ys)
        return button_xs, button_ys, label_xs, label_ys

    # New layout algorithm with text measurement
    # Parse layout parameter

Review comment (suggestion):
```suggestion
        Same layout argument as in `.widgets.RadioButtons`
```
Why are you specifically calling out RadioButtons if it's also true of CheckButtons

Code after:
                text = (text[:self.cursor_index] + key +
                        text[self.cursor_index:])
                self.cursor_index += 1
            elif key == "right":
                if self.cursor_index != len(text):
                    self.cursor_index += 1
            elif key == "left":
                if self.cursor_index != 0:
                    self.cursor_index -= 1
            elif key == "home":
                self.cursor_index = 0
            elif key == "end":
                self.cursor_index = len(text)
            elif key == "backspace":
                if self.cursor_index != 0:
                    text = (text[:self.cursor_index - 1] +
                            text[self.cursor_index:])
                    self.cursor_index -= 1
            elif key == "delete":
                if self.cursor_index != len(self.text):
                    text = (text[:self.cursor_index] +
                            text[self.cursor_index + 1:])
            self.text_disp.set_text(text)
            self._rendercursor()
            if self.eventson:
                self._observers.process('change', self.text)
                if key in ["enter", "return"]:
                    self._observers.process('submit', self.text)

    def set_val(self, val):
        newval = str(val)
        if self.text == newval:
            return
        self.text_disp.set_text(newval)
        self._rendercursor()
        if self.eventson:
            self._observers.process('change', self.text)
            self._observers.process('submit', self.text)

    def begin_typing(self):
        self.capturekeystrokes = True
        # Disable keypress shortcuts, which may otherwise cause the figure to
        # be saved, closed, etc., until the user stops typing.  The way to
        # achieve this depends on whether toolmanager is in use.
        stack = ExitStack()  # Register cleanup actions when user stops typing.
        self._on_stop_typing = stack.close
        toolmanager = getattr(
            self.ax.get_figure(root=True).canvas.manager, "toolmanager", None)
        if toolmanager is not None:
            # If using toolmanager, lock keypresses, and plan to release the
            # lock when typing stops.