Skip to content

Commit 5cb5dd8

Browse files
authored
Merge branch 'main' into unmount
2 parents 4bce831 + 7b31f63 commit 5cb5dd8

File tree

22 files changed

+800
-213
lines changed

22 files changed

+800
-213
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ assignees: ''
77

88
---
99

10-
Textual is currently in active development. I will try to keep the sample functional, but I make no guarantee anything will run right now.
10+
Please give a brief but clear explanation of what the issue is. Let us know what the behaviour you expect is, and what is actually happening. Let us know what operating system you are running on, and what terminal you are using.
1111

12-
Unless this is a blatant bug, you might want to open a discussion for now.
12+
Feel free to add screenshots and/or videos. These can be very helpful!
13+
14+
If you can, include a complete working example that demonstrates the bug. Please check it can run without modifications.

.github/workflows/pythonpackage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
11-
python-version: ["3.7", "3.8", "3.9", "3.10"]
11+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1212
defaults:
1313
run:
1414
shell: bash
@@ -20,9 +20,9 @@ jobs:
2020
python-version: ${{ matrix.python-version }}
2121
architecture: x64
2222
- name: Install and configure Poetry
23-
uses: snok/install-poetry@v1.1.6
23+
uses: snok/install-poetry@v1.3.3
2424
with:
25-
version: 1.1.6
25+
version: 1.2.2
2626
virtualenvs-in-project: true
2727
- name: Install dependencies
2828
run: poetry install --extras "dev"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ venv.bak/
116116

117117
# Snapshot testing report output directory
118118
tests/snapshot_tests/output
119+
120+
# Sandbox folder - convenient place for us to develop small test apps without leaving the repo
121+
sandbox/

docs/examples/tutorial/stopwatch03.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Stopwatch {
22
layout: horizontal;
33
background: $boost;
44
height: 5;
5-
padding: 1;
65
margin: 1;
6+
min-width: 50;
7+
padding: 1;
78
}
89

910
TimeDisplay {

docs/examples/tutorial/stopwatch04.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Stopwatch {
22
layout: horizontal;
33
background: $boost;
44
height: 5;
5-
min-width: 50;
65
margin: 1;
6+
min-width: 50;
77
padding: 1;
88
}
99

docs/examples/widgets/data_table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ def on_mount(self) -> None:
2626
table.add_rows(rows)
2727

2828

29-
app = TableApp()
29+
if __name__ == "__main__":
30+
app = TableApp()
31+
app.run()

docs/guide/devtools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If you combine the `run` command with the `--dev` switch your app will run in *d
4444
textual run --dev my_app.py
4545
```
4646

47-
One of the the features of *dev* mode is live editing of CSS files: any changes to your CSS will be reflected in the terminal a few milliseconds later.
47+
One of the features of *dev* mode is live editing of CSS files: any changes to your CSS will be reflected in the terminal a few milliseconds later.
4848

4949
This is a great feature for iterating on your app's look and feel. Open the CSS in your editor and have your app running in a terminal. Edits to your CSS will appear almost immediately after you save.
5050

docs/guide/events.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ We've used event handler methods in many of the examples in this guide. This cha
44

55
## Messages
66

7-
Events are a particular kind of *message* sent by Textual in response to input and other state changes. Events are reserved for use by Textual but you can also create custom messages for the purpose of coordinating between widgets in your app.
7+
Events are a particular kind of *message* sent by Textual in response to input and other state changes. Events are reserved for use by Textual, but you can also create custom messages for the purpose of coordinating between widgets in your app.
88

99
More on that later, but for now keep in mind that events are also messages, and anything that is true of messages is true of events.
1010

1111
## Message Queue
1212

1313
Every [App][textual.app.App] and [Widget][textual.widget.Widget] object contains a *message queue*. You can think of a message queue as orders at a restaurant. The chef takes an order and makes the dish. Orders that arrive while the chef is cooking are placed in a line. When the chef has finished a dish they pick up the next order in the line.
1414

15-
Textual processes messages in the same way. Messages are picked off a queue and processed (cooked) by a handler method. This guarantees messages and events are processed even if your code can not handle them right way.
15+
Textual processes messages in the same way. Messages are picked off a queue and processed (cooked) by a handler method. This guarantees messages and events are processed even if your code can not handle them right away.
1616

1717
This processing of messages is done within an asyncio Task which is started when you mount the widget. The task monitors a queue for new messages and dispatches them to the appropriate handler when they arrive.
1818

@@ -28,7 +28,7 @@ The widget's task will pick the first message from the queue (a key event for th
2828
--8<-- "docs/images/events/queue.excalidraw.svg"
2929
</div>
3030

31-
When the `on_key` method returns, Textual will get the next event from the the queue and repeat the process for the remaining keys. At some point the queue will be empty and the widget is said to be in an *idle* state.
31+
When the `on_key` method returns, Textual will get the next event from the queue and repeat the process for the remaining keys. At some point the queue will be empty and the widget is said to be in an *idle* state.
3232

3333
!!! note
3434

@@ -75,7 +75,7 @@ As before, the event bubbles to its parent (the App class).
7575
--8<-- "docs/images/events/bubble3.excalidraw.svg"
7676
</div>
7777

78-
The App class is always the root of the DOM, so there is no where for the event to bubble to.
78+
The App class is always the root of the DOM, so there is nowhere for the event to bubble to.
7979

8080
### Stopping bubbling
8181

@@ -110,7 +110,7 @@ The message class is defined within the widget class itself. This is not strictl
110110

111111
## Sending events
112112

113-
In the previous example we used [emit()][textual.message_pump.MessagePump.emit] to send an event to it's parent. We could also have used [emit_no_wait()][textual.message_pump.MessagePump.emit_no_wait] for non async code. Sending messages in this way allows you to write custom widgets without needing to know in what context they will be used.
113+
In the previous example we used [emit()][textual.message_pump.MessagePump.emit] to send an event to its parent. We could also have used [emit_no_wait()][textual.message_pump.MessagePump.emit_no_wait] for non async code. Sending messages in this way allows you to write custom widgets without needing to know in what context they will be used.
114114

115115
There are other ways of sending (posting) messages, which you may need to use less frequently.
116116

@@ -127,7 +127,7 @@ Most of the logic in a Textual app will be written in message handlers. Let's ex
127127
Textual uses the following scheme to map messages classes on to a Python method.
128128

129129
- Start with `"on_"`.
130-
- Add the messages namespace (if any) converted from CamelCase to snake_case plus an underscore `"_"`
130+
- Add the messages' namespace (if any) converted from CamelCase to snake_case plus an underscore `"_"`
131131
- Add the name of the class converted from CamelCase to snake_case.
132132

133133
<div class="excalidraw">
@@ -156,7 +156,7 @@ This pattern is a convenience that saves writing out a parameter that may not be
156156

157157
Message handlers may be coroutines. If you prefix your handlers with the `async` keyword, Textual will `await` them. This lets your handler use the `await` keyword for asynchronous APIs.
158158

159-
If your event handlers are coroutines it will allow multiple events to be processed concurrently, but bear in mind an individual widget (or app) will not be able to pick up a new message from its message queue until the handler has returned. This is rarely a problem in practice; as long has handlers return within a few milliseconds the UI will remain responsive. But slow handlers might make your app hard to use.
159+
If your event handlers are coroutines it will allow multiple events to be processed concurrently, but bear in mind an individual widget (or app) will not be able to pick up a new message from its message queue until the handler has returned. This is rarely a problem in practice; as long as handlers return within a few milliseconds the UI will remain responsive. But slow handlers might make your app hard to use.
160160

161161
!!! info
162162

docs/guide/reactivity.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ If you click the buttons in the above example it will show the current count. Wh
165165

166166
## Watch methods
167167

168-
Watch methods are another superpower. Textual will call watch methods when reactive attributes are modified. Watch methods begin with `watch_` followed by the name of the attribute. If the watch method accepts a positional argument, it will be called with the new assigned value. If the watch method accepts *two* positional arguments, it will be called with both the *old* value and the *new* value.
168+
Watch methods are another superpower.
169+
Textual will call watch methods when reactive attributes are modified.
170+
Watch methods begin with `watch_` followed by the name of the attribute.
171+
If the watch method accepts a positional argument, it will be called with the new assigned value.
172+
If the watch method accepts *two* positional arguments, it will be called with both the *old* value and the *new* value.
169173

170174
The following app will display any color you type in to the input. Try it with a valid color in Textual CSS. For example `"darkorchid"` or `"#52de44"`.
171175

@@ -192,6 +196,12 @@ The following app will display any color you type in to the input. Try it with a
192196

193197
The color is parsed in `on_input_submitted` and assigned to `self.color`. Because `color` is reactive, Textual also calls `watch_color` with the old and new values.
194198

199+
### When are watch methods called?
200+
201+
Textual only calls watch methods if the value of a reactive attribute _changes_.
202+
If the newly assigned value is the same as the previous value, the watch method is not called.
203+
You can override this behaviour by passing `always_update=True` to `reactive`.
204+
195205
## Compute methods
196206

197207
Compute methods are the final superpower offered by the `reactive` descriptor. Textual runs compute methods to calculate the value of a reactive attribute. Compute methods begin with `compute_` followed by the name of the reactive value.

docs/tutorial.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Let's examine `stopwatch01.py` in more detail.
108108
--8<-- "docs/examples/tutorial/stopwatch01.py"
109109
```
110110

111-
The first line imports the Textual `App` class, which we will use as the base class for our App. The second line imports two builtin widgets: `Footer` which shows a bar at the bottom of the screen with current keys, and `Header` which shows a title and the current time at the top of the screen. Widgets are re-usable components responsible for managing a part of the screen. We will cover how to build widgets in this tutorial.
111+
The first line imports the Textual `App` class, which we will use as the base class for our App. The second line imports two builtin widgets: `Footer` which shows a bar at the bottom of the screen with bound keys, and `Header` which shows a title at the top of the screen. Widgets are re-usable components responsible for managing a part of the screen. We will cover how to build widgets in this tutorial.
112112

113113
The following lines define the app itself:
114114

@@ -165,7 +165,7 @@ The Stopwatch widget class also extends `Static`. This class has a `compose()` m
165165

166166
#### The buttons
167167

168-
The Button constructor takes a label to be displayed in the button (`"Start"`, `"Stop"`, or `"Reset"`). Additionally some of the buttons set the following parameters:
168+
The Button constructor takes a label to be displayed in the button (`"Start"`, `"Stop"`, or `"Reset"`). Additionally, some of the buttons set the following parameters:
169169

170170
- `id` is an identifier we can use to tell the buttons apart in code and apply styles. More on that later.
171171
- `variant` is a string which selects a default style. The "success" variant makes the button green, and the "error" variant makes it red.
@@ -233,8 +233,9 @@ Stopwatch {
233233
layout: horizontal;
234234
background: $boost;
235235
height: 5;
236-
padding: 1;
237236
margin: 1;
237+
min-width: 50;
238+
padding: 1;
238239
}
239240
```
240241

@@ -249,8 +250,9 @@ Here's how this CSS code changes how the `Stopwatch` widget is displayed.
249250
- `layout: horizontal` aligns child widgets horizontally from left to right.
250251
- `background: $boost` sets the background color to `$boost`. The `$` prefix picks a pre-defined color from the builtin theme. There are other ways to specify colors such as `"blue"` or `rgb(20,46,210)`.
251252
- `height: 5` sets the height of our widget to 5 lines of text.
252-
- `padding: 1` sets a padding of 1 cell around the child widgets.
253253
- `margin: 1` sets a margin of 1 cell around the `Stopwatch` widget to create a little space between widgets in the list.
254+
- `min-width: 50` sets the minimum width of our widget to 50 cells.
255+
- `padding: 1` sets a padding of 1 cell around the child widgets.
254256

255257

256258
Here's the rest of `stopwatch03.css` which contains further declaration blocks:
@@ -288,7 +290,7 @@ The last 3 blocks have a slightly different format. When the declaration begins
288290

289291
The buttons have a `dock` style which aligns the widget to a given edge. The start and stop buttons are docked to the left edge, while the reset button is docked to the right edge.
290292

291-
You may have noticed that the stop button (`#stop` in the CSS) has `display: none;`. This tells Textual to not show the button. We do this because we don't want to display the stop button when the timer is *not* running. Similarly we don't want to show the start button when the timer is running. We will cover how to manage such dynamic user interfaces in the next section.
293+
You may have noticed that the stop button (`#stop` in the CSS) has `display: none;`. This tells Textual to not show the button. We do this because we don't want to display the stop button when the timer is *not* running. Similarly, we don't want to show the start button when the timer is running. We will cover how to manage such dynamic user interfaces in the next section.
292294

293295
### Dynamic CSS
294296

@@ -333,7 +335,7 @@ The following code will start or stop the stopwatches in response to clicking a
333335
--8<-- "docs/examples/tutorial/stopwatch04.py"
334336
```
335337

336-
The `on_button_pressed` method is an *event handler*. Event handlers are methods called by Textual in response to an *event* such as a key press, mouse click, etc. Event handlers begin with `on_` followed by the name of the event they will handler. Hence `on_button_pressed` will handle the button pressed event.
338+
The `on_button_pressed` method is an *event handler*. Event handlers are methods called by Textual in response to an *event* such as a key press, mouse click, etc. Event handlers begin with `on_` followed by the name of the event they will handle. Hence `on_button_pressed` will handle the button pressed event.
337339

338340
If you run `stopwatch04.py` now you will be able to toggle between the two states by clicking the first button:
339341

0 commit comments

Comments
 (0)