-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DigitDisplay widget #2995
Closed
Closed
Add DigitDisplay widget #2995
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c7b729c
add DigitDisplay for digits and basic arithmetic operators
eliasdorneles 8276758
add documentation and examples DigitDisplay widget
eliasdorneles a519225
DigitDisplay: followup on PR review
eliasdorneles 982d244
DigitDisplay: more followup on PR comments
eliasdorneles a5dbe53
fix DigitDisplay content width calculation
eliasdorneles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,24 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Label | ||
from textual.widgets import DigitDisplay | ||
|
||
|
||
class MyApp(App): | ||
BINDINGS = [] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Label("Digits: 0123456789") | ||
yield DigitDisplay("0123456789") | ||
|
||
punctuation = " .+,XYZ^*/-=" | ||
yield Label("Punctuation: " + punctuation) | ||
yield DigitDisplay(punctuation) | ||
|
||
equation = "x = y^2 + 3.14159*y + 10" | ||
yield Label("Equation: " + equation) | ||
yield DigitDisplay(equation) | ||
|
||
|
||
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
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,71 @@ | ||
# DigitDisplay | ||
|
||
A widget to display digits and basic arithmetic operators using Unicode blocks. | ||
|
||
- [ ] Focusable | ||
- [ ] Container | ||
|
||
## Examples | ||
rodrigogiraoserrao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
### Static display example | ||
|
||
=== "Screenshot" | ||
|
||
```{.textual path="docs/examples/widgets/digit_display.py"} | ||
``` | ||
|
||
=== "digit_display.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/digit_display.py" | ||
``` | ||
|
||
|
||
### Reacting to an input | ||
|
||
=== "Screenshot" | ||
|
||
```{.textual path="docs/examples/widgets/digit_display_reacting.py" press="1,2,3"} | ||
``` | ||
|
||
=== "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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: I took the liberty to add this snippet, which let you do things like:
make PYTEST_ARGS="-k digit_display" test-snapshot-update
while developing.Let me know if you prefer that I remove this.