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

Extend decorator on to specify non-control attributes to match. #2484

Closed
rodrigogiraoserrao opened this issue May 4, 2023 · 1 comment · Fixed by #2498
Closed

Extend decorator on to specify non-control attributes to match. #2484

rodrigogiraoserrao opened this issue May 4, 2023 · 1 comment · Fixed by #2498
Assignees
Labels
enhancement New feature or request Task

Comments

@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented May 4, 2023

By default, the decorator on accepts a selector that applies to the attribute control of the message.

We want on to grow **kwargs so that we can specify arbitrary selectors for arbitrary attributes of the messages we handle.

E.g., to handle the message Tabs.TabActivated, we may want @on(Tabs.TabActivated, tab="#first-tab") to handle the activation of the tab #first-tab.

EDIT: instead of matching arbitrary attributes of the message, we can only try to match attributes that have been whitelisted in the message's classvar ON_MATCHABLE_ATTRIBUTES.

@rodrigogiraoserrao rodrigogiraoserrao self-assigned this May 4, 2023
@rodrigogiraoserrao rodrigogiraoserrao added enhancement New feature or request Task labels May 4, 2023
rodrigogiraoserrao added a commit that referenced this issue May 5, 2023
rodrigogiraoserrao added a commit that referenced this issue May 5, 2023
[skip ci]
Related issues: #2484.
willmcgugan added a commit that referenced this issue May 8, 2023
* Add tests for #2484.

* Implement @on extension.

[skip ci]
Related issues: #2484.

* Changelog.

* Add missing @on test.

* Remove debug prints.

* Document changes.

* Update tests.

Test now fully works, as of #2490.

* Cache parsed selectors.

* Streamline exit condition.

* Fix typing.

* More succint wording.

* Document 'on' kwargs.

* Update src/textual/_on.py

Co-authored-by: Will McGugan <[email protected]>

* Update docs/guide/events.md

Co-authored-by: Will McGugan <[email protected]>

* Change 'on' API.

* Remove example code.

* Address feedback.

* Update src/textual/_on.py

Co-authored-by: Will McGugan <[email protected]>

* Address review feedback.

* Fix #2499.

* don't require control to be manually specified

* update docstring

* deleted words

---------

Co-authored-by: Will McGugan <[email protected]>
@github-actions
Copy link

github-actions bot commented May 8, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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 a pull request may close this issue.

1 participant