Skip to content

Editor

Sub classes

Name Children Inherits
TextEditor
promptantic.textual.editors
Typed input: text, numbers, or free JSON.
    BooleanEditor
    promptantic.textual.editors
    A switch; a three-way select when ``null`` is allowed too.
      ChoiceEditor
      promptantic.textual.editors
      A select of the allowed values; just the value when there's only one (``const``).
        MultiChoiceEditor
        promptantic.textual.editors
        Pick several of a fixed set (a unique list of choices).
          NullEditor
          promptantic.textual.editors
          Nothing to enter: the value is ``null``.
            ListEditor
            promptantic.textual.editors
            Items of one kind (add / remove), or the fixed positions of a tuple.
              MapEditor
              promptantic.textual.editors
              Free keys with values of one kind (``dict[str, X]``).
                ObjectEditor
                promptantic.textual.editors
                Named fields; nested objects fold (the outermost one doesn't).
                  UnionEditor
                  promptantic.textual.editors
                  Pick the kind first, then fill that kind's editor.

                    Base classes

                    Name Children Inherits
                    Widget
                    textual.widget
                    A Widget is the base class for Textual widgets.

                    ⋔ Inheritance diagram

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

                    🛈 DocStrings

                    Bases: Widget

                    Base of all editors: a node, its path in the value, and an error line.

                    Source code in src/promptantic/textual/editors.py
                    class Editor(Widget):
                        """Base of all editors: a node, its path in the value, and an error line."""
                    
                        DEFAULT_CSS = """
                        Editor { height: auto; }
                        Editor > .pa-errors { color: $text-error; height: auto; }
                        Editor > .pa-errors.-empty { display: none; }
                        """
                    
                        def __init__(self, node: FormNode, path: Path, initial: Any, register: Registry) -> None:
                            super().__init__()
                            self.node = node
                            self.path = path
                            self.initial = initial
                            self._register = register
                    
                        def on_mount(self) -> None:
                            self._register(self.path, self)
                    
                        def errors_widget(self) -> Static:
                            return Static("", classes="pa-errors -empty")
                    
                        def get_value(self) -> Any | Unset:
                            """The value entered so far (:data:`UNSET`: nothing).
                    
                            Raises:
                                FieldError: Input that can't become a value (e.g. text in a number field).
                            """
                            raise NotImplementedError
                    
                        def show_errors(self, messages: list[str]) -> None:
                            errors = self.query_children(".pa-errors").first(Static)
                            errors.update("\n".join(messages))
                            errors.set_class(not messages, "-empty")
                    
                        def check(self) -> None:
                            """Show what's wrong with this field alone (on every change)."""
                            try:
                                value = self.get_value()
                            except FieldError as exc:
                                self.show_errors([str(exc)])
                                return
                            self.show_errors([] if value is UNSET else field_errors(self.node, value))
                    

                    check

                    check() -> None
                    

                    Show what's wrong with this field alone (on every change).

                    Source code in src/promptantic/textual/editors.py
                    def check(self) -> None:
                        """Show what's wrong with this field alone (on every change)."""
                        try:
                            value = self.get_value()
                        except FieldError as exc:
                            self.show_errors([str(exc)])
                            return
                        self.show_errors([] if value is UNSET else field_errors(self.node, value))
                    

                    get_value

                    get_value() -> Any | Unset
                    

                    The value entered so far (:data:UNSET: nothing).

                    Raises:

                    Type Description
                    FieldError

                    Input that can't become a value (e.g. text in a number field).

                    Source code in src/promptantic/textual/editors.py
                    def get_value(self) -> Any | Unset:
                        """The value entered so far (:data:`UNSET`: nothing).
                    
                        Raises:
                            FieldError: Input that can't become a value (e.g. text in a number field).
                        """
                        raise NotImplementedError
                    

                    :fa-brands-github: Show source on GitHub