matplotlib / matplotlib/matplotlib
[MNT]: macOS backend lacks standard keyboard shortcuts
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 23.2k
- Fork
- 8.5k
- Merge medio
- 1g 6h
- PR unite (30g)
- 66
Descrizione
### Summary
A longstanding issue that I've had with matplotlib is the lack of support for standard macOS keyboard shortcuts:
| Command | Shortcut |
|-|-|
| Quit | Command-Q |
| Minimize window | Command-M |
| Switch windows | Command-Grave
Shift-Command-Grave |
| Hide all windows | Command-H |
| Hide other windows | Command-Shift-H |
And when dealing with text input (the save dialog):
| Command | Shortcut |
|-|-|
| Cut | Command-X |
| Copy | Command-C |
| Paste | Command-V |
| Select All | Command-A |
| Undo | Command-Z |
| Redo | Shift-Command-Z |
In addition, macOS Sequoia also added several keyboard shortcuts for dealing with tiling window management.
On macOS, most of these shortcuts are driven by menu items in the main menu bar. The matplotlib macOS backend sets up the shared `NSApplication` instance when it calls `+[NSApplication sharedInstance]`; however, it never fills the `NSApplication.mainMenu` property with a main menu.
Similarly, as `NSApplication.windowsMenu` is never set, macOS doesn't add the applicable menu items or shortcuts for dealing with the tiling window manager.
I'd like to address this by creating a main menu when the macOS backend is used.
There are several ways to solve this, and I'd like some guidance so I don't step on any toes :)
1) I can create the main menu programmatically in `_macosx.m`. This is likely the most straightforward approach, but it would involve a lot of hardcoded strings for menu titles in the `.m` file and ultimately lack localization support.
From an architectural perspective, it seems like existing titles/tooltips are hardcoded at the Python layer, shipped to the backend, which then converts it into UI buttons. That's doable as well, but is a lot of complexity.
2) Create a standard `MainMenu.xib` file that would be edited as a standalone file with Xcode. Invoke `ibtool` from the build system to generate a `.nib` file, package that at a similar level to existing image files, then load this from `_macosx.m`. This would require maintainers to use the Xcode app for editing the main menu, which might be a deal-breaker for some.
3) Create a new Xcode project for macOS UI assets. For now, this would be the main menu xib. In the future, it could be localized UI strings, images, icons, etc. Have the project generate a `.bundle` with compiled `.nibs` / `.car` / `.strings` / etc.
This is likely overkill for now, but could simplify asset creation in the future as Apple pushes for even more UI variants to apps (light / dark / tinted / glass / *sigh*). Xcode can generate those variants automatically and also generate compatible versions for previous macOS releases.
I'm fine with any of these approaches.
There's also the approach of doing all of this without a main menu, but I think that would be harder to maintain in the future as it's not what macOS expects.
### Proposed fix
_No response_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia nel backend macOS, in _macosx.m, dove viene creata l’istanza condivisa di NSApplication, e analizza come vengono gestiti attualmente mainMenu e windowsMenu. Confronta gli approcci praticabili per i menu e gli asset descritti nell’issue, quindi verifica che le scorciatoie standard di macOS per le finestre e la modifica del testo funzionino quando viene utilizzato il backend.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- macos, objective-c, python
- Ambito
- backend, desktop
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100