Skip to content
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 113 commits into from
Feb 27, 2023
Merged

Conversation

davep
Copy link
Contributor

@davep davep commented Feb 23, 2023

Adds the following widgets:

  • Checkbox
  • RadioButton
  • RadioSet

Before this I had an action_toggle, which did the work, and also an on_click
which called on it. It seems a bit OTT to add a toggle method too, to then
especially make the other two methods call on this. But my thinking here is
that the developer will be more likely to go looking for a method to do the
toggle, and less likely to go looking for an action, etc.

Also this is more in keeping with the Switch widget's interface.
This will need fleshing out more before a bit later on.
This won't be the final form, I feel this is a good point to start to think
about making standard styles for this sort of thing in Textual, but this
here helps me see what's going on.
With an eye on applying component styles soon.
This might be enough actually, still need to think on this some more. There
is another issue to think though here too. I'm leaning heavily on a base
"toggle" button class from which the checkbox and the radio button derive.
This makes a lot of sense -- they're so similar that it doesn't really make
sense to do it another way.

But... component classes lean on a common prefix; and I can't see an obvious
way of declaring component classes based off the owning class name; not at
the moment anyway. Perhaps I can make that work.
While the user will often want to know when the value of a toggle button has
changed, it will be useful for them to also optionally know which toggle
button has caused a change to happen. This will become handy when we do a
radio set control.
Much more to do with this, but I just wanted to get a feel for the core
working.
This means that a developer can toggle any of the buttons in the set under
the hood and the set should respond accordingly.
@davep davep marked this pull request as ready for review February 27, 2023 10:15
docs/widgets/checkbox.md Outdated Show resolved Hide resolved
src/textual/widgets/_radio_button.py Outdated Show resolved Hide resolved
src/textual/widgets/_radio_set.py Outdated Show resolved Hide resolved
src/textual/widgets/_radio_set.py Outdated Show resolved Hide resolved
src/textual/widgets/_radio_set.py Outdated Show resolved Hide resolved
src/textual/widgets/_toggle_button.py Show resolved Hide resolved
src/textual/widgets/_radio_set.py Outdated Show resolved Hide resolved
src/textual/widgets/_radio_set.py Show resolved Hide resolved
src/textual/widgets/_radio_set.py Outdated Show resolved Hide resolved
src/textual/widgets/_radio_set.py Show resolved Hide resolved
davep and others added 6 commits February 27, 2023 13:35
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
As requested in Textualize#1872 (comment)

Personally my preference tends to run to having inner-classes defined close
to where they're used, but I can't think of a good reason not to do it this
way either.
Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking my comments into consideration.
Merge away! 🚀

@davep
Copy link
Contributor Author

davep commented Feb 27, 2023

Thanks for taking my comments into consideration.

Thanks for reading over it and catching the goofs!

@davep davep merged commit 9f77208 into Textualize:main Feb 27, 2023
@davep davep deleted the toggle-boxen branch February 27, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkbox and radio buttons It would be nice if Checkbox instances could be disabled (while still visible)
4 participants