mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add some more hints about type hinting
Also add a couple more useful links in the area I'm editing.
This commit is contained in:
@@ -8,7 +8,7 @@ class SelectionListApp(App[None]):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield SelectionList[int](
|
||||
yield SelectionList[int]( # (1)!
|
||||
Selection("Falken's Maze", 0, True),
|
||||
Selection("Black Jack", 1),
|
||||
Selection("Gin Rummy", 2),
|
||||
|
||||
@@ -7,7 +7,7 @@ class SelectionListApp(App[None]):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield SelectionList[int](
|
||||
yield SelectionList[int]( # (1)!
|
||||
("Falken's Maze", 0, True),
|
||||
("Black Jack", 1),
|
||||
("Gin Rummy", 2),
|
||||
|
||||
@@ -7,10 +7,31 @@ A widget for showing a vertical list check boxes.
|
||||
- [x] Focusable
|
||||
- [ ] Container
|
||||
|
||||
## Typing
|
||||
|
||||
The `SelectionList` control is a
|
||||
[`Generic`](https://docs.python.org/3/library/typing.html#typing.Generic),
|
||||
which allows you to set the type of the
|
||||
[selection values][textual.widgets.selection_list.Selection.value]. For instance, if
|
||||
the data type for your values is an integer, you would type the widget as
|
||||
follows:
|
||||
|
||||
```python
|
||||
selections = [("First", 1), ("Second", 2)]
|
||||
my_selection_list: SelectionList[int] = SelectionList[int](selections)
|
||||
```
|
||||
|
||||
!!! note
|
||||
|
||||
Typing is entirely optional.
|
||||
|
||||
If you aren't familiar with typing or don't want to worry about it right now, feel free to ignore it.
|
||||
|
||||
## Examples
|
||||
|
||||
A selection list is designed to be built up of single-line prompts (which
|
||||
can be Rich renderables) and an associated unique value.
|
||||
can be [Rich renderables](/guide/widgets/#rich-renderables)) and an
|
||||
associated unique value.
|
||||
|
||||
### Selections as tuples
|
||||
|
||||
@@ -29,6 +50,8 @@ optionally contain a flag for the initial selected state of the option.
|
||||
--8<-- "docs/examples/widgets/selection_list_tuples.py"
|
||||
~~~
|
||||
|
||||
1. Note that the `SelectionList` is typed as `int`, for the type of the vlaues.
|
||||
|
||||
=== "selection_list.css"
|
||||
|
||||
~~~python
|
||||
@@ -51,6 +74,8 @@ Alternatively, selections can be passed in as
|
||||
--8<-- "docs/examples/widgets/selection_list_selections.py"
|
||||
~~~
|
||||
|
||||
1. Note that the `SelectionList` is typed as `int`, for the type of the vlaues.
|
||||
|
||||
=== "selection_list.css"
|
||||
|
||||
~~~python
|
||||
|
||||
Reference in New Issue
Block a user