From 2055a8996f94f3270a225f773e9f8b15305db4c7 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 24 Apr 2023 13:13:11 +0100 Subject: [PATCH] Move the tutorial over to using ScrollableContainer --- docs/examples/tutorial/stopwatch.py | 6 +++--- docs/examples/tutorial/stopwatch02.py | 6 +++--- docs/examples/tutorial/stopwatch03.py | 6 +++--- docs/examples/tutorial/stopwatch04.py | 6 +++--- docs/examples/tutorial/stopwatch05.py | 6 +++--- docs/examples/tutorial/stopwatch06.py | 6 +++--- docs/tutorial.md | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/examples/tutorial/stopwatch.py b/docs/examples/tutorial/stopwatch.py index ffb87ea4c..af3c3503c 100644 --- a/docs/examples/tutorial/stopwatch.py +++ b/docs/examples/tutorial/stopwatch.py @@ -1,9 +1,9 @@ from time import monotonic from textual.app import App, ComposeResult -from textual.containers import Container +from textual.containers import ScrollableContainer from textual.reactive import reactive -from textual.widgets import Button, Header, Footer, Static +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -83,7 +83,7 @@ class StopwatchApp(App): """Called to add widgets to the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch(), id="timers") + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch(), id="timers") def action_add_stopwatch(self) -> None: """An action to add a timer.""" diff --git a/docs/examples/tutorial/stopwatch02.py b/docs/examples/tutorial/stopwatch02.py index 8baa3831e..5937cd805 100644 --- a/docs/examples/tutorial/stopwatch02.py +++ b/docs/examples/tutorial/stopwatch02.py @@ -1,6 +1,6 @@ from textual.app import App, ComposeResult -from textual.containers import Container -from textual.widgets import Button, Header, Footer, Static +from textual.containers import ScrollableContainer +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -27,7 +27,7 @@ class StopwatchApp(App): """Create child widgets for the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch()) + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch()) def action_toggle_dark(self) -> None: """An action to toggle dark mode.""" diff --git a/docs/examples/tutorial/stopwatch03.py b/docs/examples/tutorial/stopwatch03.py index 0c455fecb..8e1fcfb14 100644 --- a/docs/examples/tutorial/stopwatch03.py +++ b/docs/examples/tutorial/stopwatch03.py @@ -1,6 +1,6 @@ from textual.app import App, ComposeResult -from textual.containers import Container -from textual.widgets import Button, Header, Footer, Static +from textual.containers import ScrollableContainer +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -28,7 +28,7 @@ class StopwatchApp(App): """Create child widgets for the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch()) + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch()) def action_toggle_dark(self) -> None: """An action to toggle dark mode.""" diff --git a/docs/examples/tutorial/stopwatch04.py b/docs/examples/tutorial/stopwatch04.py index 2394fd20c..36acc023c 100644 --- a/docs/examples/tutorial/stopwatch04.py +++ b/docs/examples/tutorial/stopwatch04.py @@ -1,6 +1,6 @@ from textual.app import App, ComposeResult -from textual.containers import Container -from textual.widgets import Button, Header, Footer, Static +from textual.containers import ScrollableContainer +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -35,7 +35,7 @@ class StopwatchApp(App): """Create child widgets for the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch()) + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch()) def action_toggle_dark(self) -> None: """An action to toggle dark mode.""" diff --git a/docs/examples/tutorial/stopwatch05.py b/docs/examples/tutorial/stopwatch05.py index 6543ac5eb..fee7691d4 100644 --- a/docs/examples/tutorial/stopwatch05.py +++ b/docs/examples/tutorial/stopwatch05.py @@ -1,9 +1,9 @@ from time import monotonic from textual.app import App, ComposeResult -from textual.containers import Container +from textual.containers import ScrollableContainer from textual.reactive import reactive -from textual.widgets import Button, Header, Footer, Static +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -55,7 +55,7 @@ class StopwatchApp(App): """Create child widgets for the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch()) + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch()) def action_toggle_dark(self) -> None: """An action to toggle dark mode.""" diff --git a/docs/examples/tutorial/stopwatch06.py b/docs/examples/tutorial/stopwatch06.py index 84e862f98..b78864c87 100644 --- a/docs/examples/tutorial/stopwatch06.py +++ b/docs/examples/tutorial/stopwatch06.py @@ -1,9 +1,9 @@ from time import monotonic from textual.app import App, ComposeResult -from textual.containers import Container +from textual.containers import ScrollableContainer from textual.reactive import reactive -from textual.widgets import Button, Header, Footer, Static +from textual.widgets import Button, Footer, Header, Static class TimeDisplay(Static): @@ -78,7 +78,7 @@ class StopwatchApp(App): """Called to add widgets to the app.""" yield Header() yield Footer() - yield Container(Stopwatch(), Stopwatch(), Stopwatch()) + yield ScrollableContainer(Stopwatch(), Stopwatch(), Stopwatch()) def action_toggle_dark(self) -> None: """An action to toggle dark mode.""" diff --git a/docs/tutorial.md b/docs/tutorial.md index 604398b1d..b69defb5c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -157,7 +157,7 @@ Let's add those to the app. Just a skeleton for now, we will add the rest of the --8<-- "docs/examples/tutorial/stopwatch02.py" ``` -We've imported two new widgets in this code: `Button`, which creates a clickable button, and `Static` which is a base class for a simple control. We've also imported `Container` from `textual.containers` which (as the name suggests) is a `Widget` which contains other widgets. +We've imported two new widgets in this code: `Button`, which creates a clickable button, and `Static` which is a base class for a simple control. We've also imported `ScrollableContainer` from `textual.containers` which (as the name suggests) is a `Widget` which contains other widgets. We've defined an empty `TimeDisplay` widget by extending `Static`. We will flesh this out later. @@ -174,7 +174,7 @@ The Button constructor takes a label to be displayed in the button (`"Start"`, ` To add widgets to our application we first need to yield them from the app's `compose()` method: -The new line in `StopwatchApp.compose()` yields a single `Container` object which will create a scrolling list of stopwatches. When classes contain other widgets (like `Container`) they will typically accept their child widgets as positional arguments. We want to start the app with three stopwatches, so we construct three `Stopwatch` instances and pass them to the container's constructor. +The new line in `StopwatchApp.compose()` yields a single `ScrollableContainer` object which will create a scrolling list of stopwatches. When classes contain other widgets (like `ScrollableContainer`) they will typically accept their child widgets as positional arguments. We want to start the app with three stopwatches, so we construct three `Stopwatch` instances and pass them to the container's constructor. ### The unstyled app @@ -438,7 +438,7 @@ Let's use these methods to implement adding and removing stopwatches to our app. Here's a summary of the changes: -- The `Container` object in `StopWatchApp` grew a `"timers"` ID. +- The `ScrollableContainer` object in `StopWatchApp` grew a `"timers"` ID. - Added `action_add_stopwatch` to add a new stopwatch. - Added `action_remove_stopwatch` to remove a stopwatch. - Added keybindings for the actions.