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

Improve support for overriding default menu items #2636

Merged
merged 15 commits into from
Jun 12, 2024

Conversation

freakboy3742
Copy link
Member

Derived from #2244.

Some features related to the default menu items:

  • Commands can now be defined with an ID, and retrieved by that ID
  • The generic system commands that Toga support (About, Visit Homepage, Exit and Preferences) have constants that are used as IDs
  • A generic "wrap this function as a handler" method has been added, removing the need to explicitly re-define a menu command method that adds a single "command" argument that is then ignored.
  • The App interface has a new preferences() method. If the user overrides this method, it will be used as the implementation of the Preferences menu item; if undefined, the menu item will still exist, but will be disabled. This isn't a full implementation of Settings API for Toga #90, but it does provide the ability for users to hook into the menu item.
  • Handler methods now return their results. This isn't really useful at runtime, but it simplifies a lot of testing cases as you now have direct access to the underlying return results.

When combined with #2619, an app is able to delete or modify all the default menu items by a clear reference. The only exception to this are the ones on the Cocoa backend that are "window system related" (e.g., Hide, Close Window, Cut and Paste) which are included to provide basic window management, and shouldn't require any user override.

Refs #90.

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

docs/reference/api/app.rst Outdated Show resolved Hide resolved
docs/reference/api/resources/command.rst Outdated Show resolved Hide resolved
core/src/toga/app.py Outdated Show resolved Hide resolved
core/src/toga/handlers.py Show resolved Hide resolved
@@ -22,8 +26,43 @@ def __init__(self, interface):

def create(self):
self._action("create App")
self.create_app_commands()
Copy link
Member

Choose a reason for hiding this comment

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

#2619 has caused a merge conflict on this file.

This line in particular seems inconsistent with #2619, which moved the create_app_commands out of the backends and into _startup.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah - this was the part I mentioned yesterday about PRs starting to step on each other.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I've removed the redundant line.

core/tests/command/test_commandset.py Show resolved Hide resolved
core/src/toga/command.py Outdated Show resolved Hide resolved
@freakboy3742 freakboy3742 merged commit 29a0adb into beeware:main Jun 12, 2024
31 of 34 checks passed
@freakboy3742 freakboy3742 deleted the default_menu_items branch June 12, 2024 22:30
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.

2 participants