-
Notifications
You must be signed in to change notification settings - Fork 780
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
Promote disabled to Widget
level
#1785
Merged
Merged
Conversation
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 seems to be a hangover from the early days of the development of `Input`, and the styles do nothing as there's nothing else in the `Input` code that makes use of the class that's involved. Removed in anticipation of Textualize#1748 taking care of this.
f495870 got a little too carried away.
This doesn't go close to what Textualize#1748 is intending to do, but moves `disabled` to where I want it and keeps `Button` working as before.
Note that this doesn't touch the application of stylesheets yet, in terms of things like specificity; this just makes sure that the classes exist and can be seen.
There was no need to default to None and then convert to a bool, defaulting to False is just fine.
It's done as an internal, but can be called from child classes of course. This is intended to be a single central method of asking the app to update styles while also not caring if there is no active app available just yet.
I was going too early with setting this; it needs to happen after pretty much everything else is set up *and* after the super's __init__ has been called.
There's still a bit to do here, but this migrates the main work up to the `Widget`. At this point `Button` is pretty much built expressed as a function of what `Widget` provides in terms of things being disabled. Focus can still move into disabled controls (or in this case right now, into a disabled `Button`). The next step is to add something that works alongside `can_focus` to say if a control is currently capable of receiving focus (in other words, it's `not disabled and can_focus`).
Don't use comments as version control! Or, really, I don't need this note to self any more about the code as it's being handled elsewhere.
Some hangover from the work to migrate `disabled` out of `Button` and into `Widget`, that I forgot to remove.
We want to maintain `can_focus` as "this is a thing that can, at some point, receive focus, assuming it isn't disabled". So `can_focus` is now very much about the ability to receive focus at all. The new `focusable` property becomes about "can this widget receive focus right now?". [This is a rewording of a previous commit -- I get the wrong thing]
Some hangover from the work to migrate `disabled` out of `Button` and into `Widget`, that I forgot to remove.
Rather than it being about widgets where `can_focus` is `True`, have it be about widgets that are currently able to receive focus. Before this change widgets with a positive `can_focus` but which were disabled would still end up in the chain.
willmcgugan
reviewed
Feb 16, 2023
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.
Looks good, some minor requests
See Textualize#1785 (comment) for the background.
It's not specific to Button now.
I typo. Co-authored-by: Rodrigo Girão Serrão <[email protected]>
davep
changed the title
[WiP] Promote disabled to
Promote disabled to Feb 16, 2023
Widget
levelWidget
level
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.
I added a bunch of questions but I found no blockers.
Co-authored-by: Rodrigo Girão Serrão <[email protected]>
Re: the docstrings that are missing in total, I've added #1811. |
rodrigogiraoserrao
approved these changes
Feb 16, 2023
willmcgugan
approved these changes
Feb 21, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently the only interactive widget in Textual that supports
disabled
is theButton
. Really this should be something that can be set on any interactive widget (Input
,Tree
,DataTable
, etc...). Moreover, ideally it should be something that can be set on any widget and it and all children will be disabled.This PR seeks to implement this. Key changes include:
disabled
property and related code is removed fromButton
.disabled
property is added toWidget
.:enabled
pseudoclass is added to CSS.:disabled
pseudoclass is added to CSS._self_or_ancestors_disabled
internal property is added toWidget
.focusable
property is added toWidget
-- to befocusable
a widget needs to havecan_focus
set toTrue
and_self_or_ancestors_disabled
needs to beFalse
.watch_disabled
watcher is added toWidget
, which updates the styles of the current widget and all of its children.focus_chain
is now built from widgets that arefocusable
rather than those wherecan_focus
isTrue
.set_focus
has been changed to only allow focus to be set iffocusable
isTrue
(before it was ifcan_focus
isTrue
)._self_or_ancestors_disabled
state into account when dealing with mouse events (in other words, if a widget is in any way disabled, it won't receive mouse events).*:disabled
style is added toApp.DEFAULT_CSS
which applies disabled styling to all disabled widgets.disabled
keyword argument has been added to all the main "interactive" widgets.If you need a standalone test application for this see this one here in my sandbox.