Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for custom app menu items on macOS #1736

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

Open
camdarley wants to merge 1 commit into r0x0r:master
base: master
Choose a base branch
Loading
from camdarley:feature/app-menu-items

Conversation

Copy link
Contributor

@camdarley camdarley commented Oct 14, 2025
edited
Loading

Description

This PR implements support for adding custom menu items to the macOS application menu (the first menu in the menu bar that displays the app name).

Implementation

Custom items are added using the special __app__ menu title:

app_menu = Menu('__app__', [
 MenuAction('Preferences...', open_preferences),
 MenuSeparator(),
 MenuAction('Check for Updates', check_updates),
 MenuAction('License Information', show_license)
])
webview.create_window('App', menu=[app_menu, file_menu])

Behavior

macOS (Cocoa)

Custom items are inserted into the application menu between "About" and "Services", surrounded by separators:

About App Name
─────────────
Preferences... ← custom
─────────────
Check for Updates ← custom 
License Information ← custom
─────────────
Services
Hide/Show All/Quit

Other Platforms

Menus with title __app__ are silently ignored (no error, no rendering).

Changes

  • cocoa.py: Process __app__ menus and insert items into app menu
    • Modified _add_app_menu() to accept optional custom items
    • Modified _recreate_menus() to filter and extract __app__ menu items
    • Refactored menu item processing into reusable _process_menu_items() method
  • gtk.py, qt.py, winforms.py: Added checks to ignore __app__ menus
  • examples/app_menu_test.py: Comprehensive example demonstrating the feature

Testing

Run the example on macOS:

python examples/app_menu_test.py

The application menu should display custom items between "About" and "Services".

Related Issue

Implements the feature request discussed in: #1725

Implements the ability to add custom menu items to the macOS application
menu (the first menu in the menu bar) using the special '__app__' menu title.
Custom items are placed between "About" and "Services" menu items,
surrounded by separators. On non-macOS platforms, '__app__' menus are
silently ignored.
Usage:
 app_menu = Menu('__app__', [
 MenuAction('Preferences...', open_preferences),
 MenuSeparator(),
 MenuAction('Check for Updates', check_updates)
 ])
 webview.create_window('App', menu=[app_menu, file_menu])
Changes:
- cocoa.py: Process '__app__' menus and insert items into app menu
- gtk.py, qt.py, winforms.py: Ignore '__app__' menus on other platforms
- Added comprehensive example: examples/app_menu_test.py
Copy link
Owner

r0x0r commented Oct 14, 2025

Please integrate app menu example into examples/menu.py, but otherwise looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /