-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add documentation and examples DigitDisplay widget
- Loading branch information
1 parent
73bd532
commit 0eff2d5
Showing
4 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Input | ||
from textual.widgets import DigitDisplay | ||
|
||
|
||
class MyApp(App): | ||
BINDINGS = [] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Input(placeholder="Type something:") | ||
yield DigitDisplay("") | ||
|
||
def on_input_changed(self, event: Input.Changed) -> None: | ||
display: DigitDisplay = self.query_one(DigitDisplay) | ||
display.digits = "".join(d for d in event.value if d in DigitDisplay.supported_digits) | ||
|
||
|
||
if __name__ == "__main__": | ||
app = MyApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# DigitDisplay | ||
|
||
A widget to display digits and basic arithmetic operators using Unicode blocks. | ||
|
||
- [ ] Focusable | ||
- [ ] Container | ||
|
||
## Examples | ||
|
||
=== "Static example" | ||
|
||
```{.textual path="docs/examples/widgets/digit_display.py"} | ||
``` | ||
|
||
=== "digit_display.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/digit_display.py" | ||
``` | ||
|
||
=== "Reacting to an input" | ||
|
||
```{.textual path="docs/examples/widgets/digit_display_reacting.py"} | ||
``` | ||
|
||
=== "digit_display_reacting.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/digit_display_reacting.py" | ||
``` | ||
|
||
## Reactive attributes | ||
|
||
| Name | Type | Default | Description | | ||
| ------ | ------ | ------- | ---------------------------------------------- | | ||
| `digits` | `str` | `""` | Use this to update the digits to be displayed. | | ||
|
||
|
||
## Read-only attributes | ||
|
||
| Name | Type | Description | | ||
| ------ | ------ | ----------------------------------------- | | ||
| `supported_digits` | `frozenset[str]` | Contains the list of supported digits/characters. | ||
|
||
## Messages | ||
|
||
This widget sends no messages. | ||
|
||
|
||
## Bindings | ||
|
||
This widget defines no bindings. | ||
|
||
|
||
## Component classes | ||
|
||
This widget provides no component classes. | ||
|
||
|
||
--- | ||
|
||
|
||
::: textual.widgets.DigitDisplay | ||
options: | ||
heading_level: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters