From 65601196ee152b6d94edad6c01dcc390f95e5b69 Mon Sep 17 00:00:00 2001 From: Sam Penny <33956017+sam1penny@users.noreply.github.com> Date: Wed, 31 Aug 2022 11:09:09 +0100 Subject: [PATCH] add shortcut to close addcards window (#2031) --- qt/aqt/addcards.py | 2 ++ qt/aqt/utils.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 5b25dc9ba..ef8a11500 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -21,6 +21,7 @@ from aqt.qt import * from aqt.sound import av_player from aqt.utils import ( HelpPage, + add_close_shortcut, askUser, downArrow, openHelp, @@ -48,6 +49,7 @@ class AddCards(QMainWindow): self.setup_choosers() self.setupEditor() self.setupButtons() + add_close_shortcut(self) self._load_new_note() self.history: list[NoteId] = [] self._last_added_note: Optional[Note] = None diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index b067c1b3e..89ea157e7 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -848,6 +848,13 @@ def addCloseShortcut(widg: QDialog) -> None: setattr(widg, "_closeShortcut", shortcut) +def add_close_shortcut(widg: QWidget) -> None: + if not is_mac: + return + shortcut = QShortcut(QKeySequence("Ctrl+W"), widg) + qconnect(shortcut.activated, widg.close) + + def downArrow() -> str: if is_win: return "▼"