spacr.qt.menus¶
Assign explicit Qt menu roles, and name the macOS application menu.
On macOS, Qt may relocate actions according to text such as “Preferences” or “Quit”. Explicit roles prevent translated or renamed actions from moving to the wrong system-menu slot. Other platforms retain their normal menu layout.
The menu those actions are relocated INTO is named after the application, so
this module also owns naming the application – before the QApplication
exists, which is the only moment early enough for macOS to read it.
Functions¶
|
Configure the Qt application and organization names. |
|
Set the application-menu title for an unbundled macOS launch. |
|
Give every action in |
|
Assign a macOS menu role and return |
Module Contents¶
- spacr.qt.menus.name_the_application(name: str = APPLICATION_NAME, organization: str = ORGANIZATION_NAME) → Tuple[str, str][source]¶
Configure the Qt application and organization names.
Call this function before constructing
QApplicationso the macOS application menu and Qt window-title fallbacks receive the configured name.- Parameters:
name – Application and display name.
organization – Organization name used by
QSettings.
- Returns:
Effective
(applicationName, applicationDisplayName)values.
- spacr.qt.menus.name_the_macos_application_menu(name: str = APPLICATION_NAME) → bool[source]¶
Set the application-menu title for an unbundled macOS launch.
macOS derives this title from
CFBundleNamerather than Qt’sapplicationName. Packaged applications already provide the bundle value and are left unchanged.- Parameters:
name – Application-menu title.
- Returns:
Trueif the bundle value was updated; otherwiseFalse.
- spacr.qt.menus.pin_menu_roles(actions: Iterable[Any], preferences: Any | None = None, quit_action: Any | None = None, about: Any | None = None) → None[source]¶
Give every action in
actionsan explicit role.Everything gets
NoRoleexcept the three named, so adding a menu item later cannot accidentally claim the Preferences slot by being called something reasonable.- Parameters:
actions – every action on the menu bar.
preferences – the action that really is Preferences, if any.
quit_action – the action that really is Quit, if any.
about – the action that really is About, if any.
- spacr.qt.menus.set_menu_role(action: Any, role: str = 'none') → Any[source]¶
Assign a macOS menu role and return
action.- Parameters:
action (PySide6.QtGui.QAction) – Action whose role is assigned.
role ({'none', 'preferences', 'quit', 'about'}, default='none') – Target system-menu role.
'none'keeps the action in its menu.
- Returns:
PySide6.QtGui.QAction – The input action.
- Raises:
ValueError – If
roleis not supported.
Nested helpers¶
- name_the_macos_application_menu.send(receiver, selector, *args, argtypes=())¶
One typed
objc_msgSendcall. Untyped calls corrupt the ABI.spacr/qt/menus.py:127