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 a "prevent" context manager #1866

Merged
merged 25 commits into from
Feb 24, 2023
Merged

Add a "prevent" context manager #1866

merged 25 commits into from
Feb 24, 2023

Conversation

willmcgugan
Copy link
Collaborator

Context manager to temporarily prevent a message from being sent.

@willmcgugan willmcgugan changed the title prevent implementation Add a "prevent" context manager Feb 23, 2023
@darrenburns
Copy link
Member

Not particularly bothered but I'll just mention that I think I prefer suppress as it makes me think of reducing/preventing the output of something from travelling further. prevent sounds like I'd be prevented from using the button.

e.g. suppress in the standard library doesn't prevent an exception, it stops it from travelling further; a suppressor on a gun stops the sound from travelling further; when you suppress speech you don't stop it from occurring but instead limit its reach.

@darrenburns
Copy link
Member

Oh, here we are preventing the message from being posted. Never mind then.

@darrenburns
Copy link
Member

Although, I do think prevent_message is a better name personally 😄 otherwise it's kind of like "prevent what?"

@willmcgugan
Copy link
Collaborator Author

Although, I do think prevent_message is a better name personally 😄 otherwise it's kind of like "prevent what?"

Does it make a difference that prevent takes message types as positional args. i.e. if you were to read this, would it be clear?

with input.prevent(Input.Changed):
    input.value = ''

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.

I like the idea and the implementation! I just left a couple of comments regarding nitpicks that are up for discussion and some tidying up.

docs/guide/events.md Outdated Show resolved Hide resolved
docs/examples/events/prevent.py Outdated Show resolved Hide resolved
docs/examples/events/prevent.py Outdated Show resolved Hide resolved
src/textual/dom.py Outdated Show resolved Hide resolved
src/textual/dom.py Outdated Show resolved Hide resolved
src/textual/message_pump.py Outdated Show resolved Hide resolved
src/textual/message_pump.py Outdated Show resolved Hide resolved
src/textual/message_pump.py Show resolved Hide resolved
src/textual/message_pump.py Show resolved Hide resolved
src/textual/message.py Show resolved Hide resolved
willmcgugan and others added 3 commits February 24, 2023 12:02
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>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
willmcgugan and others added 5 commits February 24, 2023 12:03
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>
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>
@willmcgugan willmcgugan merged commit 5f1ca95 into main Feb 24, 2023
@willmcgugan willmcgugan deleted the prevent-event branch February 24, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants