Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 6, 2021
1 parent 2ded0fa commit 07f95f9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion examples/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
19 changes: 0 additions & 19 deletions examples/vertical.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
6 changes: 2 additions & 4 deletions src/textual/views/_window_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 07f95f9

Please sign in to comment.