diff --git a/README.md b/README.md index 1aa8202bbd..393ff01125 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,14 @@ You can install Textual via pip (`pip install textual`), or by checking out the poetry install ``` +## Examples + +Until I've written the documentation, the examples are the best way to learn Textual. Run any of the Python files in [examples](https://github.com/willmcgugan/textual/tree/main/examples) and read the code to see how it works. + ## Building Textual applications +_This guide is a work in progress_ + Let's look at the simplest Textual app which does _something_: ```python @@ -59,15 +65,15 @@ class ColorChanger(App): ColorChanger.run(log="textual.log") ``` -This example also handles key events, and will set `App.background` if the key is a digit. So pressing the keys 0 to 9 will change the background color to the corresponding [ansi colors](https://rich.readthedocs.io/en/latest/appendix/colors.html). +This example also handles key events, and will set `App.background` if the key is a digit. So pressing the keys 0 to 9 will change the background color to the corresponding [ansi color](https://rich.readthedocs.io/en/latest/appendix/colors.html). -Note that we didn't need to explicitly refresh the screen or draw anything. Setting the `background` attribute is enough for Textual to update the visuals. This is an example of _reactivity_ in Textual. +Note that we didn't need to explicitly refresh the screen or draw anything. Setting the `background` attribute is enough for Textual to update the visuals. This is an example of _reactivity_ in Textual. To make changes to the terminal interface you modify the _state_ and let Textual update the visuals. -### Widgets +## Widgets To make more interesting apps you will need to make use of _widgets_, which are independent user interface elements. Textual comes with a (growing) library of widgets, but you can also develop your own. -Let's look at an app which contains widgets. We will be using the built in `Placeholder` widget which you can use to design application layouts before you implement the real content. They are also very useful for testing. +Let's look at an app which contains widgets. We will be using the built in `Placeholder` widget which you can use to design application layouts before you implement the real content. They are very useful for testing. ```python from textual import events @@ -113,6 +119,22 @@ If you move the mouse over the terminal you will notice that widgets receive mou The dock layout feature is good enough for most purposes. For more sophisticated layouts we can use the grid API. See the [calculator.py](https://github.com/willmcgugan/textual/blob/main/examples/calculator.py) example which makes use of Grid. +### Creating Widgets + +_TODO_ + +### Actions + +_TODO_ + +### Events + +_TODO_ + +### Timers and Intervals + +_TODO_ + ## Developer VLog Since Textual is a visual medium, I'll be documenting new features and milestones here. diff --git a/examples/calculator.py b/examples/calculator.py index 474b2f4c14..4114773040 100644 --- a/examples/calculator.py +++ b/examples/calculator.py @@ -161,6 +161,7 @@ async def message_button_pressed(self, message: ButtonPressed) -> None: def do_math() -> None: """Does the math: LEFT OPERATOR RIGHT""" + self.log(self.left, self.operator, self.right) try: if self.operator == "+": self.left += self.right @@ -172,7 +173,8 @@ def do_math() -> None: self.left *= self.right self.display = str(self.left) self.value = "" - except ZeroDivisionError: + self.log("=", self.left) + except Exception: self.display = "Error" if button_name.isdigit(): diff --git a/examples/vertical.py b/examples/vertical.py deleted file mode 100644 index 2f43a4f334..0000000000 --- a/examples/vertical.py +++ /dev/null @@ -1,19 +0,0 @@ -from textual import events -from textual.app import App - -from textual.views import WindowView -from textual.widgets import Placeholder - - -class MyApp(App): - async def on_mount(self, event: events.Mount) -> None: - window1 = WindowView(Placeholder(height=20)) - # window2 = WindowView(Placeholder(height=20)) - - # window1.scroll_x = -10 - # window1.scroll_y = 5 - - await self.view.dock(window1, edge="left") - - -MyApp.run(log="textual.log") diff --git a/pyproject.toml b/pyproject.toml index 0221da8e86..2c7a41a8ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual" -version = "0.1.8" +version = "0.1.9" homepage = "https://github.com/willmcgugan/textual" description = "Text User Interface using Rich" authors = ["Will McGugan "] diff --git a/src/textual/views/_window_view.py b/src/textual/views/_window_view.py index f44cff150d..710109ac10 100644 --- a/src/textual/views/_window_view.py +++ b/src/textual/views/_window_view.py @@ -44,14 +44,12 @@ async def watch_virtual_size(self, size: Size) -> None: await self.emit(WindowChange(self)) async def watch_scroll_x(self, value: int) -> None: + self.layout.require_update() self.refresh(layout=True) async def watch_scroll_y(self, value: int) -> None: - self.refresh(layout=True) - - async def message_update(self, message: UpdateMessage) -> None: self.layout.require_update() - await self.root_view.refresh_layout() + self.refresh(layout=True) async def on_resize(self, event: events.Resize) -> None: await self.emit(WindowChange(self))