-
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 Checkbox
, RadioButton
and RadioSet
#1872
Merged
Merged
Changes from 107 commits
Commits
Show all changes
113 commits
Select commit
Hold shift + click to select a range
6982805
Initial planning of the class hierarchy for toggle widgets
davep 2ee1a24
Add a couple of missing types
davep 22a4772
Add return information to the render docstring
davep de04be1
Add a toggle method
davep 279e2fc
Improve the types of the parts that make up the renderable
davep 9053f73
Move Checkbox and RadioButton out into their own files
davep d4b61e2
Give the Checkbox a docstring
davep c114c87
Add a placeholder docstring to the radio button
davep 9dea934
Add some default styling to the toggle button classes
davep 47550a6
Allow placing the label before the button
davep ae7f1b4
Simplify the rendering
davep 5c9ed14
Add a reminder about handling a disabled keyword
davep a6389f1
Add a base changed message for toggle boxes
davep 5e3ed65
Add a Checkbox-specific Changed message
davep 3df4634
Add a RadioButtons-specific Changed message
davep 41ce300
Add notes about the desire to not hard-code the namespaces
davep 6f4dde4
Merge branch 'main' into toggle-boxen
davep 7da9cbe
Add some initial component classes
davep fb32e53
Swap the checkbox to using an actual check mark
davep 122457a
Swap the radio button to using a circular character for the inner
davep bf727fc
Add a selected message to the toggle button
davep 594c1fa
Start fleshing out a RadioSet widget
davep cd3a47b
Swap to using a button change event for radio switching
davep f97194a
Add missing type annotation
davep 9e6cb76
Add missing type annotation
davep 791bf12
Add missing type annotation
davep 6eb2fde
Add the usual set of widget parameters to the RadioSet
davep 063e815
Add a preflight check that all buttons are of a type we can handle
davep 54d59ef
Further explain why we keep an internal list of buttons
davep 8d63af1
Ensure a button is pressed on startup
davep fe1261c
Tidy up a comment
davep 3ee35f6
Add properties for getting the current pressed button
davep adca897
Add a RadioSet.Changed message
davep ef0ef58
Merge branch 'main' into toggle-boxen
davep 0a2781f
Merge branch 'main' into toggle-boxen
davep ef70ef9
Add support for disabled on the checkbox and radioset
davep 3d759d6
WiP revamping of how checkboxes and radio buttons look
davep 6c3232e
Don't allow a radio button to be turned off
davep 461d628
Start toggling an on class on the toggle boxes
davep d5f4ae1
Have the radio set work more around DOM queries
davep ec5d566
Drop support for a Selected message on the toggle boxes
davep 621f542
Remove unnecessary import
davep 526e7a9
Remove unnecessary import
davep f94313f
Drop support for individual on/off inner characters for the buttons
davep ec698bc
Simplify the naming of the component classes
davep cbd0cfd
Merge branch 'main' into toggle-boxen
davep f8f3691
Add required import
davep 277412b
Simplify the styling of the button
davep ada24c9
Simplify the setting of the button characters
davep 5c89efc
Simplify the setting and handling of the label
davep 724fef7
Sort the list of component classes in the docstring
davep 8506f79
Simplify the setting of the button characters
davep 5743148
Fix -light-mode not being set on startup if not in dark mode
davep 23cc1da
Bring the button_first setting internal
davep 7ee970e
Support richer labels
davep 8bcee3f
More style changing to the toggle buttons
davep 0358d74
Tweak the buttons in light mode
davep 967773f
More tidying of the button styles
davep 9f9fe6f
Docstring tidy
davep 18705b4
Merge branch 'main' into toggle-boxen
davep 9dd66fc
Tidy some documentation in the base toggle box class
davep 91199fd
Make the label available but read-only
davep 1b2f5a1
Stop wrapping the spacer as Text
davep 789e051
Don't react on initial set
davep 177aae6
Don't force a radio set to have at least one button on on start
davep a32a9fa
Reduce the calls to Text when building the button
davep 2fbb64c
Add methods for getting the width and height of the widget
davep 46018c3
Add missing import
davep 73cb4c5
Turn off wrapping and add ellipsis to the overall widget
davep ceade8a
Ensure we're only working with the first line of the label
davep af3c5f1
Ensure that toggle buttons are width auto
davep 1c05f79
Add some default styling to a radio set
davep 99341a9
Rename the file that holds ToggleButton
davep f52aac4
Initial work on adding toggle buttons to the documentation
davep affb3b6
Type-tidy the radio set event handling
davep 652d449
Type-tidy the radio set button query
davep 6233ae3
Extend and improve the RadioSet docstrings
davep 66af586
Add a missing
davep 3fd3d27
Add the widget reference for Checkbox
davep 4f75a39
Fix copy/paste-o in the checkbox reference
davep 01215a1
Tweak the style of the box in the example for checkbox
davep 87bd610
Swap the checkbox example to the newer compose approach
davep a3d50d9
Revert example code to composing the old way
davep a821b2f
Add width reference documentation for radio buttons
davep 316faf9
Add width reference documentation for radio set
davep 307b178
Give radio button its own example code now
davep 837d56f
Provide a default label for the toggle buttons
davep 0520856
Prevent the initial Changed event when initial value is True
davep cfe7be3
Some initial Checkbox unit testing
davep 7c6522e
Add initial radio button tests
davep 2362662
Add CSS class tests for check boxes and radio buttons
davep d341b8b
Fix a couple of copy/paste-o docstrings
davep 8d726fb
Ensure the pressed button index is correct in the message
davep 719c831
Add some unit testing for RadioSet
davep 24ce819
Add snapshot tests for the toggle button examples
davep f0a6771
Update the ChangeLog and the roadmap
davep e6e46d0
Merge branch 'main' into toggle-boxen
davep 3de871f
Use prevent to stop the Changed event on initial value setting
davep f436489
Rework the layout of the radio set example
davep 23c0587
Rework the layout of the radio button example
davep 6d0fc04
Rework the layout of the checkbox example
davep 17bc19e
Ensure multiple buttons can't be on on startup
davep 7f90e4e
Add a test for adding multiple on buttons to a radioset
davep db9b9e1
Fix a typo
davep 445e29f
Improve the wording of a test description
davep 7bfed01
Improve the wording of a test description
davep 8c5fb38
Merge branch 'main' into toggle-boxen
davep b5c028c
Fix a docstring typo
davep dec9a77
Fix a docstring typo
davep 47eb9f0
Typo fix
davep 201ab4e
Move RadioSet.Changed near the top of the class
davep d8ae11d
Drop a vestigial cast
davep df6f7bd
Don't bubble up any Changed event when stopping all-off on radio set
davep 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: textual.widgets.Checkbox |
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 @@ | ||
::: textual.widgets.RadioButton |
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 @@ | ||
::: textual.widgets.RadioSet |
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 @@ | ||
::: textual.widgets._toggle_button.ToggleButton |
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,11 @@ | ||
Screen { | ||
align: center middle; | ||
} | ||
|
||
Vertical { | ||
width: auto; | ||
height: auto; | ||
border: solid $primary; | ||
background: $panel; | ||
padding: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Vertical | ||
from textual.widgets import Checkbox | ||
|
||
|
||
class CheckboxApp(App[None]): | ||
CSS_PATH = "checkbox.css" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Vertical(): | ||
yield Checkbox("Arrakis :sweat:") | ||
yield Checkbox("Caladan") | ||
yield Checkbox("Chusuk") | ||
yield Checkbox("[b]Giedi Prime[/b]") | ||
yield Checkbox("[magenta]Ginaz[/]") | ||
yield Checkbox("Grumman", True) | ||
yield Checkbox("Kaitain", id="initial_focus") | ||
yield Checkbox("Novebruns", True) | ||
|
||
def on_mount(self): | ||
self.query_one("#initial_focus", Checkbox).focus() | ||
|
||
|
||
if __name__ == "__main__": | ||
CheckboxApp().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,7 @@ | ||
Screen { | ||
align: center middle; | ||
} | ||
|
||
RadioSet { | ||
width: 50%; | ||
} |
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,27 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import RadioButton, RadioSet | ||
|
||
|
||
class RadioChoicesApp(App[None]): | ||
CSS_PATH = "radio_button.css" | ||
|
||
def compose(self) -> ComposeResult: | ||
with RadioSet(): | ||
yield RadioButton("Battlestar Galactica") | ||
yield RadioButton("Dune 1984") | ||
yield RadioButton("Dune 2021", id="focus_me") | ||
yield RadioButton("Serenity", value=True) | ||
yield RadioButton("Star Trek: The Motion Picture") | ||
yield RadioButton("Star Wars: A New Hope") | ||
yield RadioButton("The Last Starfighter") | ||
yield RadioButton( | ||
"Total Recall :backhand_index_pointing_right: :red_circle:" | ||
) | ||
yield RadioButton("Wing Commander") | ||
|
||
def on_mount(self) -> None: | ||
self.query_one("#focus_me", RadioButton).focus() | ||
|
||
|
||
if __name__ == "__main__": | ||
RadioChoicesApp().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,12 @@ | ||
Screen { | ||
align: center middle; | ||
} | ||
|
||
Horizontal { | ||
align: center middle; | ||
height: auto; | ||
} | ||
|
||
RadioSet { | ||
width: 45%; | ||
} |
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,43 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Horizontal | ||
from textual.widgets import RadioButton, RadioSet | ||
|
||
|
||
class RadioChoicesApp(App[None]): | ||
CSS_PATH = "radio_set.css" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Horizontal(): | ||
# A RadioSet built up from RadioButtons. | ||
with RadioSet(): | ||
yield RadioButton("Battlestar Galactica") | ||
yield RadioButton("Dune 1984") | ||
yield RadioButton("Dune 2021") | ||
yield RadioButton("Serenity", value=True) | ||
yield RadioButton("Star Trek: The Motion Picture") | ||
yield RadioButton("Star Wars: A New Hope") | ||
yield RadioButton("The Last Starfighter") | ||
yield RadioButton( | ||
"Total Recall :backhand_index_pointing_right: :red_circle:", | ||
id="focus_me", | ||
) | ||
yield RadioButton("Wing Commander") | ||
# A RadioSet built up from a collection of strings. | ||
yield RadioSet( | ||
"Amanda", | ||
"Connor MacLeod", | ||
"Duncan MacLeod", | ||
"Heather MacLeod", | ||
"Joe Dawson", | ||
"Kurgan, [bold italic red]The[/]", | ||
"Methos", | ||
"Rachel Ellenstein", | ||
"Ramírez", | ||
) | ||
|
||
def on_mount(self) -> None: | ||
self.query_one("#focus_me", RadioButton).focus() | ||
|
||
|
||
if __name__ == "__main__": | ||
RadioChoicesApp().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,59 @@ | ||
# Checkbox | ||
|
||
A simple checkbox width which stores a boolean value. | ||
davep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- [x] Focusable | ||
- [ ] Container | ||
|
||
## Example | ||
|
||
The example below shows check boxes in various states. | ||
|
||
=== "Output" | ||
|
||
```{.textual path="docs/examples/widgets/checkbox.py"} | ||
``` | ||
|
||
=== "checkbox.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/checkbox.py" | ||
``` | ||
|
||
=== "checkbox.css" | ||
|
||
```sass | ||
--8<-- "docs/examples/widgets/checkbox.css" | ||
``` | ||
|
||
## Reactive Attributes | ||
|
||
| Name | Type | Default | Description | | ||
|---------|--------|---------|----------------------------| | ||
| `value` | `bool` | `False` | The value of the checkbox. | | ||
|
||
## Bindings | ||
|
||
The checkbox widget defines directly the following bindings: | ||
|
||
::: textual.widgets._toggle_button.ToggleButton.BINDINGS | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
|
||
## Component Classes | ||
|
||
The checkbox widget provides the following component classes: | ||
|
||
::: textual.widgets._toggle_button.ToggleButton.COMPONENT_CLASSES | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
|
||
## Messages | ||
|
||
### ::: textual.widgets.Checkbox.Changed | ||
|
||
## See Also | ||
|
||
- [Checkbox](../api/checkbox.md) code reference |
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,62 @@ | ||
# RadioButton | ||
|
||
A simple radio button which stores a boolean value. | ||
|
||
- [x] Focusable | ||
- [ ] Container | ||
|
||
A radio button is best used with others inside a [`RadioSet`](./radioset.md). | ||
|
||
## Example | ||
|
||
The example below shows radio buttons, used within a [`RadioSet`](./radioset.md). | ||
|
||
=== "Output" | ||
|
||
```{.textual path="docs/examples/widgets/radio_button.py"} | ||
``` | ||
|
||
=== "radio_button.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/radio_button.py" | ||
``` | ||
|
||
=== "radio_button.css" | ||
|
||
```sass | ||
--8<-- "docs/examples/widgets/radio_button.css" | ||
``` | ||
|
||
## Reactive Attributes | ||
|
||
| Name | Type | Default | Description | | ||
|---------|--------|---------|--------------------------------| | ||
| `value` | `bool` | `False` | The value of the radio button. | | ||
|
||
## Bindings | ||
|
||
The radio button widget defines directly the following bindings: | ||
|
||
::: textual.widgets._toggle_button.ToggleButton.BINDINGS | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
|
||
## Component Classes | ||
|
||
The radio button widget provides the following component classes: | ||
|
||
::: textual.widgets._toggle_button.ToggleButton.COMPONENT_CLASSES | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
|
||
## Messages | ||
|
||
### ::: textual.widgets.RadioButton.Changed | ||
|
||
## See Also | ||
|
||
- [RadioButton](../api/radiobutton.md) code reference | ||
- [RadioSet](./radioset.md) |
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,37 @@ | ||
# RadioSet | ||
|
||
A container widget that groups [`RadioButton`](./radiobutton.md)s together. | ||
|
||
- [ ] Focusable | ||
- [x] Container | ||
|
||
## Example | ||
|
||
The example below shows two radio sets, one built using a collection of | ||
[radio buttons](./radiobutton.md), the other a collection of simple strings. | ||
|
||
=== "Output" | ||
|
||
```{.textual path="docs/examples/widgets/radio_set.py"} | ||
``` | ||
|
||
=== "radio_set.py" | ||
|
||
```python | ||
--8<-- "docs/examples/widgets/radio_set.py" | ||
``` | ||
|
||
=== "radio_set.css" | ||
|
||
```sass | ||
--8<-- "docs/examples/widgets/radio_set.css" | ||
``` | ||
|
||
## Messages | ||
|
||
### ::: textual.widgets.RadioSet.Changed | ||
|
||
## See Also | ||
|
||
- [RadioSet](../api/radioset.md) code reference | ||
- [RadioButton](./radiobutton.md) |
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
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.
Such meta. Wow.