Merge branch 'main' of github.com:willmcgugan/textual into datatable-cell-keys

This commit is contained in:
Darren Burns
2023-02-06 12:46:07 +00:00
86 changed files with 2564 additions and 676 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Header, Footer, Label, Input
class InputWidthAutoApp(App[None]):
CSS = """
Input.auto {
width: auto;
max-width: 100%;
}
"""
def compose(self) -> ComposeResult:
yield Header()
yield Input(placeholder="This has auto width", classes="auto")
yield Footer()
if __name__ == "__main__":
InputWidthAutoApp().run()

View File

@@ -0,0 +1,45 @@
from textual.app import App
from textual.widgets import Label, Static
from rich.panel import Panel
class LabelWrap(App):
CSS = """Screen {
align: center middle;
}
#l_data {
border: blank;
background: lightgray;
}
#s_data {
border: blank;
background: lightgreen;
}
#p_data {
border: blank;
background: lightgray;
}"""
def __init__(self):
super().__init__()
self.data = (
"Apple Banana Cherry Mango Fig Guava Pineapple:"
"Dragon Unicorn Centaur Phoenix Chimera Castle"
)
def compose(self):
yield Label(self.data, id="l_data")
yield Static(self.data, id="s_data")
yield Label(Panel(self.data), id="p_data")
def on_mount(self):
self.dark = False
if __name__ == "__main__":
app = LabelWrap()
app.run()

View File

@@ -0,0 +1,29 @@
from textual.app import App
from textual.containers import Grid
from textual.widgets import Label
class ProgrammaticScrollbarGutterChange(App[None]):
CSS = """
Grid { grid-size: 2 2; scrollbar-size: 5 5; }
Label { width: 100%; height: 100%; background: red; }
"""
def compose(self):
yield Grid(
Label("one"),
Label("two"),
Label("three"),
Label("four"),
)
def on_key(self, event):
if event.key == "s":
self.query_one(Grid).styles.scrollbar_gutter = "stable"
app = ProgrammaticScrollbarGutterChange()
if __name__ == "__main__":
app().run()

View File

@@ -179,6 +179,16 @@ def test_nested_auto_heights(snap_compare):
assert snap_compare("snapshot_apps/nested_auto_heights.py", press=["1", "2", "_"])
def test_programmatic_scrollbar_gutter_change(snap_compare):
"""Regression test for #1607 https://github.com/Textualize/textual/issues/1607
See also tests/css/test_programmatic_style_changes.py for other related regression tests.
"""
assert snap_compare(
"snapshot_apps/programmatic_scrollbar_gutter_change.py", press=["s"]
)
# --- Other ---
@@ -193,3 +203,14 @@ def test_demo(snap_compare):
press=["down", "down", "down"],
terminal_size=(100, 30),
)
def test_label_widths(snap_compare):
"""Test renderable widths are calculate correctly."""
assert snap_compare(SNAPSHOT_APPS_DIR / "label_widths.py")
def test_auto_width_input(snap_compare):
assert snap_compare(
SNAPSHOT_APPS_DIR / "auto_width_input.py", press=["tab", *"Hello"]
)