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

Implement property for Command.action. #2433

Merged
merged 7 commits into from
Mar 1, 2024

Conversation

cvwillegen
Copy link
Contributor

I added a property handler for action, so that it is possible to specify what a Command does after it's been created.

Sometimes, you want to make the action depend on the current state of your application, and having global variables to indicate that state may not always be possible.

With this change, you can change the action to be another closure. But, because the handler needs to be wrapped in a wrapped_handler, doing this from you app looks ugly:

self.removepodcast.action = wrapped_handler(self.removepodcast.action, self.showRemovePodcast(main_list_box, podcast_id)

After this change, it looks like this:

self.removepodcast.action = self.showRemovePodcast(main_list_box, podcast_id)

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 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 the PR! A couple of minor suggestions inline; but this looks like an obvious oversight in the API, so we should definitely fix it.

core/src/toga/command.py Outdated Show resolved Hide resolved
changes/2433.feature.rst Outdated Show resolved Hide resolved
docs/reference/api/resources/command.rst Outdated Show resolved Hide resolved
@@ -63,6 +63,29 @@ def test_create():
)


def test_change_action():
Copy link
Member

Choose a reason for hiding this comment

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

This test is a little odd; it's only really validating that the action can be cleared, which I think would have always been true.

@freakboy3742 freakboy3742 merged commit 84206a9 into beeware:main Mar 1, 2024
34 checks passed
@cvwillegen cvwillegen deleted the command-action-property branch March 1, 2024 05:12
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.

None yet

2 participants