You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/devtools.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ If you combine the `run` command with the `--dev` switch your app will run in *d
44
44
textual run --dev my_app.py
45
45
```
46
46
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.
48
48
49
49
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.
Copy file name to clipboardExpand all lines: docs/guide/events.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ We've used event handler methods in many of the examples in this guide. This cha
4
4
5
5
## Messages
6
6
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.
8
8
9
9
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.
10
10
11
11
## Message Queue
12
12
13
13
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.
14
14
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.
16
16
17
17
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.
18
18
@@ -28,7 +28,7 @@ The widget's task will pick the first message from the queue (a key event for th
28
28
--8<-- "docs/images/events/queue.excalidraw.svg"
29
29
</div>
30
30
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.
32
32
33
33
!!! note
34
34
@@ -75,7 +75,7 @@ As before, the event bubbles to its parent (the App class).
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.
79
79
80
80
### Stopping bubbling
81
81
@@ -110,7 +110,7 @@ The message class is defined within the widget class itself. This is not strictl
110
110
111
111
## Sending events
112
112
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.
114
114
115
115
There are other ways of sending (posting) messages, which you may need to use less frequently.
116
116
@@ -127,7 +127,7 @@ Most of the logic in a Textual app will be written in message handlers. Let's ex
127
127
Textual uses the following scheme to map messages classes on to a Python method.
128
128
129
129
- 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 `"_"`
131
131
- Add the name of the class converted from CamelCase to snake_case.
132
132
133
133
<divclass="excalidraw">
@@ -156,7 +156,7 @@ This pattern is a convenience that saves writing out a parameter that may not be
156
156
157
157
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.
158
158
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.
Copy file name to clipboardExpand all lines: docs/tutorial.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ Let's examine `stopwatch01.py` in more detail.
108
108
--8<--"docs/examples/tutorial/stopwatch01.py"
109
109
```
110
110
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.
112
112
113
113
The following lines define the app itself:
114
114
@@ -165,7 +165,7 @@ The Stopwatch widget class also extends `Static`. This class has a `compose()` m
165
165
166
166
#### The buttons
167
167
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:
169
169
170
170
-`id` is an identifier we can use to tell the buttons apart in code and apply styles. More on that later.
171
171
-`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 {
233
233
layout: horizontal;
234
234
background: $boost;
235
235
height: 5;
236
-
padding: 1;
237
236
margin: 1;
237
+
min-width: 50;
238
+
padding: 1;
238
239
}
239
240
```
240
241
@@ -249,8 +250,9 @@ Here's how this CSS code changes how the `Stopwatch` widget is displayed.
249
250
-`layout: horizontal` aligns child widgets horizontally from left to right.
250
251
-`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)`.
251
252
-`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.
253
253
-`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.
254
256
255
257
256
258
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
288
290
289
291
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.
290
292
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.
292
294
293
295
### Dynamic CSS
294
296
@@ -333,7 +335,7 @@ The following code will start or stop the stopwatches in response to clicking a
333
335
--8<--"docs/examples/tutorial/stopwatch04.py"
334
336
```
335
337
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.
337
339
338
340
If you run `stopwatch04.py` now you will be able to toggle between the two states by clicking the first button:
0 commit comments