Skip to content

BooleanEditor

Base classes

Name Children Inherits
Editor
promptantic.textual.editors
Base of all editors: a node, its path in the value, and an error line.

⋔ Inheritance diagram

graph TD
  1305497219["editors.BooleanEditor"]
  2997256436["editors.Editor"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  2751680898["builtins.object"]
  2997256436 --> 1305497219
  4188532303 --> 2997256436
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

🛈 DocStrings

Bases: Editor

A switch; a three-way select when null is allowed too.

Source code in src/promptantic/textual/editors.py
class BooleanEditor(Editor):
    """A switch; a three-way select when ``null`` is allowed too."""

    node: BooleanNode
    _OPTIONS: ClassVar = [("Yes", True), ("No", False)]

    def compose(self) -> ComposeResult:
        if self.node.nullable:
            value = self.initial if isinstance(self.initial, bool) else Select.NULL
            yield Select(self._OPTIONS, value=value, prompt="(none)", compact=True)
        else:
            yield Switch(value=self.initial is True)
        yield self.errors_widget()

    def get_value(self) -> Any | Unset:
        if self.node.nullable:
            value = self.query_one(Select).value
            return None if value is Select.NULL else value
        return self.query_one(Switch).value

:fa-brands-github: Show source on GitHub