mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
version bump
This commit is contained in:
30
README.md
30
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.
|
||||
|
||||
@@ -161,6 +161,7 @@ class Calculator(GridView):
|
||||
|
||||
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 @@ class Calculator(GridView):
|
||||
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():
|
||||
|
||||
@@ -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")
|
||||
@@ -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 <willmcgugan@gmail.com>"]
|
||||
|
||||
@@ -44,14 +44,12 @@ class WindowView(View, layout=VerticalLayout):
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user