Merge branch 'main' into placeholder

This commit is contained in:
Rodrigo Girão Serrão
2022-11-18 15:21:40 +00:00
committed by GitHub
58 changed files with 1381 additions and 799 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
.widget {
background: olivedrab;
width: 10;
margin: 1;
}
#dock-1 {
dock: left;
background: dodgerblue;
width: 5;
}
#dock-2 {
dock: left;
background: mediumvioletred;
margin: 3;
width: 20;
}
#horizontal {
width: auto;
height: auto;
background: darkslateblue;
}

View File

@@ -0,0 +1,22 @@
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Static
class HorizontalAutoWidth(App):
"""
Checks that the auto width of the parent Horizontal is correct.
"""
def compose(self) -> ComposeResult:
yield Horizontal(
Static("Docked left 1", id="dock-1"),
Static("Docked left 2", id="dock-2"),
Static("Widget 1", classes="widget"),
Static("Widget 2", classes="widget"),
id="horizontal",
)
app = HorizontalAutoWidth(css_path="horizontal_auto_width.css")
if __name__ == '__main__':
app.run()

View File

@@ -0,0 +1,36 @@
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer
class KeyDisplayApp(App):
"""Tests how keys are displayed in the Footer, and ensures
that overriding the key_displays works as expected.
Exercises both the built-in Textual key display replacements,
and user supplied replacements.
Will break when we update the Footer - but we should add a similar
test (or updated snapshot) for the updated Footer."""
BINDINGS = [
Binding("question_mark", "question", "Question"),
Binding("ctrl+q", "quit", "Quit app"),
Binding("escape", "escape", "Escape"),
Binding("a", "a", "Letter A"),
]
def compose(self) -> ComposeResult:
yield Footer()
def get_key_display(self, key: str) -> str:
key_display_replacements = {
"escape": "Escape!",
"ctrl+q": "^q",
}
display = key_display_replacements.get(key)
if display:
return display
return super().get_key_display(key)
app = KeyDisplayApp()
if __name__ == '__main__':
app.run()

View File

@@ -2,9 +2,11 @@ from pathlib import Path
import pytest
# These paths should be relative to THIS directory.
WIDGET_EXAMPLES_DIR = Path("../../docs/examples/widgets")
LAYOUT_EXAMPLES_DIR = Path("../../docs/examples/guide/layout")
STYLES_EXAMPLES_DIR = Path("../../docs/examples/styles")
SNAPSHOT_APPS_DIR = Path("./snapshot_apps")
# --- Layout related stuff ---
@@ -29,6 +31,10 @@ def test_horizontal_layout(snap_compare):
assert snap_compare(LAYOUT_EXAMPLES_DIR / "horizontal_layout.py")
def test_horizontal_layout_width_auto_dock(snap_compare):
assert snap_compare(SNAPSHOT_APPS_DIR / "horizontal_auto_width.py")
def test_vertical_layout(snap_compare):
assert snap_compare(LAYOUT_EXAMPLES_DIR / "vertical_layout.py")
@@ -117,3 +123,9 @@ def test_css_property(file_name, snap_compare):
def test_multiple_css(snap_compare):
# Interaction between multiple CSS files and app-level/classvar CSS
assert snap_compare("snapshot_apps/multiple_css/multiple_css.py")
# --- Other ---
def test_key_display(snap_compare):
assert snap_compare(SNAPSHOT_APPS_DIR / "key_display.py")