dummy.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. Dummy layout. Used when somebody creates an `Application` without specifying a
  3. `Layout`.
  4. """
  5. from __future__ import annotations
  6. from prompt_toolkit.formatted_text import HTML
  7. from prompt_toolkit.key_binding import KeyBindings
  8. from prompt_toolkit.key_binding.key_processor import KeyPressEvent
  9. from .containers import Window
  10. from .controls import FormattedTextControl
  11. from .dimension import D
  12. from .layout import Layout
  13. __all__ = [
  14. "create_dummy_layout",
  15. ]
  16. E = KeyPressEvent
  17. def create_dummy_layout() -> Layout:
  18. """
  19. Create a dummy layout for use in an 'Application' that doesn't have a
  20. layout specified. When ENTER is pressed, the application quits.
  21. """
  22. kb = KeyBindings()
  23. @kb.add("enter")
  24. def enter(event: E) -> None:
  25. event.app.exit()
  26. control = FormattedTextControl(
  27. HTML("No layout specified. Press <reverse>ENTER</reverse> to quit."),
  28. key_bindings=kb,
  29. )
  30. window = Window(content=control, height=D(min=1))
  31. return Layout(container=window, focused_element=window)