Skip to content

Commit fe2c151

Browse files
Add Cmd+W close shortcut (on Mac) to more dialogs (#3905)
* Enable Cmd+W shortcut in "Edit Current" on Mac * Enable Cmd+W shortcut in "Fields" editor on Mac * Enable Cmd+W shortcut in "Cards" editing on Mac * Enable Cmd+W shortcut in "Sync" tab modal on Mac * Enable Cmd+W shortcut in "Custom Study" tab modal on Mac * Enable Cmd+W shortcut in Settings view on Mac * Enable Cmd+W shortcut in Export dialogs on Mac * Enable Cmd+W shortcut for getText dialog on Mac * Enable Cmd+W shortcut in "Change Deck" on Mac * Enable Cmd+W shortcut in Reposition dialog on Mac * Enable Cmd+W shortcut in "Grade Now" dialog on Mac * Enable Cmd+W shortcut in "Reset…" dialog on Mac * Remove duplicate camelCase variant of add_close_shortcut (dae) - The camelCase variant will remain accessible with a warning. - The removed setattr line is legacy cruft, and wasn't doing anything.
1 parent efaaae8 commit fe2c151

19 files changed

+39
-26
lines changed

qt/aqt/addons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from aqt.log import ADDON_LOGGER_PREFIX, find_addon_logger, get_addon_logs_folder
4141
from aqt.qt import *
4242
from aqt.utils import (
43-
addCloseShortcut,
43+
add_close_shortcut,
4444
askUser,
4545
disable_help_button,
4646
getFile,
@@ -829,7 +829,7 @@ def __init__(self, addonsManager: AddonManager) -> None:
829829
self.setAcceptDrops(True)
830830
self.redrawAddons()
831831
restoreGeom(self, "addons")
832-
addCloseShortcut(self)
832+
add_close_shortcut(self)
833833
gui_hooks.addons_dialog_will_show(self)
834834
self._onAddonSelectionChanged()
835835
self.show()

qt/aqt/browser/browser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from aqt.utils import (
5858
HelpPage,
5959
KeyboardModifiersPressed,
60+
add_close_shortcut,
6061
add_ellipsis_to_action_label,
6162
current_window,
6263
ensure_editor_saved,
@@ -1092,6 +1093,7 @@ def grade_now(self) -> None:
10921093
dialog.setWindowTitle(tr.actions_grade_now())
10931094
layout = QHBoxLayout()
10941095
dialog.setLayout(layout)
1096+
add_close_shortcut(dialog)
10951097

10961098
# Add grade buttons
10971099
for ease, label in [

qt/aqt/browser/card_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from anki.lang import without_unicode_isolation
1515
from aqt.qt import *
1616
from aqt.utils import (
17-
addCloseShortcut,
17+
add_close_shortcut,
1818
disable_help_button,
1919
qconnect,
2020
restoreGeom,
@@ -53,7 +53,7 @@ def _setup_ui(self, card_id: CardId | None) -> None:
5353
self.mw.garbage_collect_on_dialog_finish(self)
5454
disable_help_button(self)
5555
restoreGeom(self, self.GEOMETRY_KEY, default_size=(800, 800))
56-
addCloseShortcut(self)
56+
add_close_shortcut(self)
5757
setWindowIcon(self)
5858

5959
self.web: AnkiWebView | None = AnkiWebView(

qt/aqt/changenotetype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from aqt.operations.notetype import change_notetype_of_notes
1616
from aqt.qt import *
1717
from aqt.utils import (
18-
addCloseShortcut,
18+
add_close_shortcut,
1919
disable_help_button,
2020
restoreGeom,
2121
saveGeom,
@@ -49,7 +49,7 @@ def _setup_ui(self, notetype_id: NotetypeId) -> None:
4949
self.setMinimumSize(400, 300)
5050
disable_help_button(self)
5151
restoreGeom(self, self.TITLE, default_size=(800, 800))
52-
addCloseShortcut(self)
52+
add_close_shortcut(self)
5353

5454
self.web = AnkiWebView(kind=AnkiWebViewKind.CHANGE_NOTETYPE)
5555
self.web.setVisible(False)

qt/aqt/clayout.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from aqt.theme import theme_manager
2828
from aqt.utils import (
2929
HelpPage,
30+
add_close_shortcut,
3031
ask_user_dialog,
3132
askUser,
3233
disable_help_button,
@@ -90,6 +91,7 @@ def __init__(
9091
gui_hooks.card_layout_will_show(self)
9192
self.redraw_everything()
9293
restoreGeom(self, "CardLayout")
94+
add_close_shortcut(self)
9395
restoreSplitter(self.mainArea, "CardLayoutMainArea")
9496
self.setWindowModality(Qt.WindowModality.ApplicationModal)
9597
self.show()

qt/aqt/customstudy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from aqt.operations.scheduling import custom_study
1616
from aqt.qt import *
1717
from aqt.taglimit import TagLimit
18-
from aqt.utils import disable_help_button, tr
18+
from aqt.utils import add_close_shortcut, disable_help_button, tr
1919

2020
RADIO_NEW = 1
2121
RADIO_REV = 2
@@ -63,6 +63,7 @@ def __init__(
6363
self.form.setupUi(self)
6464
disable_help_button(self)
6565
self.setupSignals()
66+
add_close_shortcut(self)
6667
self.form.radioNew.click()
6768
self.open()
6869

qt/aqt/deckdescription.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from aqt.operations import QueryOp
1111
from aqt.operations.deck import update_deck_dict
1212
from aqt.qt import *
13-
from aqt.utils import addCloseShortcut, disable_help_button, restoreGeom, saveGeom, tr
13+
from aqt.utils import add_close_shortcut, disable_help_button, restoreGeom, saveGeom, tr
1414

1515

1616
class DeckDescriptionDialog(QDialog):
@@ -45,7 +45,7 @@ def _setup_ui(self) -> None:
4545
self.setMinimumWidth(400)
4646
disable_help_button(self)
4747
restoreGeom(self, self.TITLE)
48-
addCloseShortcut(self)
48+
add_close_shortcut(self)
4949

5050
box = QVBoxLayout()
5151

qt/aqt/deckoptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from aqt.qt import *
1414
from aqt.utils import (
1515
KeyboardModifiersPressed,
16-
addCloseShortcut,
16+
add_close_shortcut,
1717
disable_help_button,
1818
restoreGeom,
1919
saveGeom,
@@ -42,7 +42,7 @@ def _setup_ui(self) -> None:
4242
self.setMinimumWidth(400)
4343
disable_help_button(self)
4444
restoreGeom(self, self.TITLE, default_size=(800, 800))
45-
addCloseShortcut(self)
45+
add_close_shortcut(self)
4646

4747
self.web = AnkiWebView(kind=AnkiWebViewKind.DECK_OPTIONS)
4848
self.web.load_sveltekit_page(f"deck-options/{self._deck['id']}")

qt/aqt/editcurrent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from anki.errors import NotFoundError
1010
from aqt import gui_hooks
1111
from aqt.qt import *
12-
from aqt.utils import restoreGeom, saveGeom, tr
12+
from aqt.utils import add_close_shortcut, restoreGeom, saveGeom, tr
1313

1414

1515
class EditCurrent(QMainWindow):
@@ -36,6 +36,7 @@ def __init__(self, mw: aqt.AnkiQt) -> None:
3636
close_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Close)
3737
assert close_button is not None
3838
close_button.setShortcut(QKeySequence("Ctrl+Return"))
39+
add_close_shortcut(self)
3940
# qt5.14+ doesn't handle numpad enter on Windows
4041
self.compat_add_shorcut = QShortcut(QKeySequence("Ctrl+Enter"), self)
4142
qconnect(self.compat_add_shorcut.activated, close_button.click)

qt/aqt/exporting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from aqt.errors import show_exception
2020
from aqt.qt import *
2121
from aqt.utils import (
22+
add_close_shortcut,
2223
checkInvalidFilename,
2324
disable_help_button,
2425
getSaveFile,
@@ -46,6 +47,7 @@ def __init__(
4647
self.cids = cids
4748
disable_help_button(self)
4849
self.setup(did)
50+
add_close_shortcut(self)
4951
self.exec()
5052

5153
def setup(self, did: DeckId | None) -> None:

qt/aqt/fields.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from aqt.schema_change_tracker import ChangeTracker
1616
from aqt.utils import (
1717
HelpPage,
18+
add_close_shortcut,
1819
askUser,
1920
disable_help_button,
2021
getOnlyText,
@@ -50,6 +51,7 @@ def __init__(
5051
without_unicode_isolation(tr.fields_fields_for(val=self.model["name"]))
5152
)
5253

54+
add_close_shortcut(self)
5355
disable_help_button(self)
5456
help_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help)
5557
assert help_button is not None

qt/aqt/import_export/exporting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from aqt.progress import ProgressUpdate
2828
from aqt.qt import *
2929
from aqt.utils import (
30+
add_close_shortcut,
3031
checkInvalidFilename,
3132
disable_help_button,
3233
getSaveFile,
@@ -53,6 +54,7 @@ def __init__(
5354
self.nids = nids
5455
disable_help_button(self)
5556
self.setup(did)
57+
add_close_shortcut(self)
5658
self.open()
5759

5860
def setup(self, did: DeckId | None) -> None:

qt/aqt/import_export/import_dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import aqt.main
1313
import aqt.operations
1414
from aqt.qt import *
15-
from aqt.utils import addCloseShortcut, disable_help_button, restoreGeom, saveGeom, tr
15+
from aqt.utils import add_close_shortcut, disable_help_button, restoreGeom, saveGeom, tr
1616
from aqt.webview import AnkiWebView, AnkiWebViewKind
1717

1818

@@ -62,7 +62,7 @@ def _setup_ui(self) -> None:
6262
self.setMinimumSize(*self.MIN_SIZE)
6363
disable_help_button(self)
6464
restoreGeom(self, self.args.title, default_size=self.DEFAULT_SIZE)
65-
addCloseShortcut(self)
65+
add_close_shortcut(self)
6666

6767
self.web: AnkiWebView | None = AnkiWebView(kind=self.args.kind)
6868
self.web.setVisible(False)

qt/aqt/operations/scheduling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from anki.scheduler.v3 import Scheduler as V3Scheduler
2525
from aqt.operations import CollectionOp
2626
from aqt.qt import *
27-
from aqt.utils import disable_help_button, getText, tooltip, tr
27+
from aqt.utils import add_close_shortcut, disable_help_button, getText, tooltip, tr
2828

2929

3030
def set_due_date_dialog(
@@ -104,6 +104,7 @@ def forget_cards(
104104

105105
dialog = QDialog(parent)
106106
disable_help_button(dialog)
107+
add_close_shortcut(dialog)
107108
form = aqt.forms.forget.Ui_Dialog()
108109
form.setupUi(dialog)
109110

@@ -153,6 +154,7 @@ def reposition_new_cards_dialog(
153154

154155
dialog = QDialog(parent)
155156
disable_help_button(dialog)
157+
add_close_shortcut(dialog)
156158
dialog.setWindowModality(Qt.WindowModality.WindowModal)
157159
form = aqt.forms.reposition.Ui_Dialog()
158160
form.setupUi(dialog)

qt/aqt/preferences.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from aqt.theme import Theme
2323
from aqt.utils import (
2424
HelpPage,
25+
add_close_shortcut,
2526
askUser,
2627
disable_help_button,
2728
is_win,
@@ -64,6 +65,7 @@ def __init__(self, mw: AnkiQt) -> None:
6465
self.setup_profile()
6566
self.setup_global()
6667
self.setup_configurable_answer_keys()
68+
add_close_shortcut(self)
6769
self.show()
6870

6971
def setup_configurable_answer_keys(self):

qt/aqt/stats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from aqt.qt import *
1717
from aqt.theme import theme_manager
1818
from aqt.utils import (
19-
addCloseShortcut,
19+
add_close_shortcut,
2020
disable_help_button,
2121
getSaveFile,
2222
maybeHideClose,
@@ -69,7 +69,7 @@ def __init__(self, mw: aqt.main.AnkiQt) -> None:
6969
assert b is not None
7070
b.setAutoDefault(False)
7171
maybeHideClose(self.form.buttonBox)
72-
addCloseShortcut(self)
72+
add_close_shortcut(self)
7373
gui_hooks.stats_dialog_will_show(self)
7474
self.form.web.hide_while_preserving_layout()
7575
self.show()
@@ -182,7 +182,7 @@ def __init__(self, mw: aqt.main.AnkiQt) -> None:
182182
qconnect(f.year.clicked, lambda: self.changePeriod(1))
183183
qconnect(f.life.clicked, lambda: self.changePeriod(2))
184184
maybeHideClose(self.form.buttonBox)
185-
addCloseShortcut(self)
185+
add_close_shortcut(self)
186186
gui_hooks.stats_dialog_old_will_show(self)
187187
self.show()
188188
self.refresh()

qt/aqt/studydeck.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from aqt.utils import (
1717
HelpPage,
1818
HelpPageArgument,
19+
add_close_shortcut,
1920
disable_help_button,
2021
openHelp,
2122
restoreGeom,
@@ -52,6 +53,7 @@ def __init__(
5253
gui_hooks.state_did_reset.append(self.onReset)
5354
self.geomKey = f"studyDeck-{geomKey}"
5455
restoreGeom(self, self.geomKey)
56+
add_close_shortcut(self)
5557
disable_help_button(self)
5658
if not cancel:
5759
self.form.buttonBox.removeButton(

qt/aqt/sync.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
qconnect,
2929
)
3030
from aqt.utils import (
31+
add_close_shortcut,
3132
ask_user_dialog,
3233
disable_help_button,
3334
show_warning,
@@ -380,6 +381,7 @@ def get_id_and_pass_from_user(
380381
qconnect(bb.accepted, diag.accept)
381382
qconnect(bb.rejected, diag.reject)
382383
vbox.addWidget(bb)
384+
add_close_shortcut(diag)
383385
diag.setLayout(vbox)
384386
diag.adjustSize()
385387
diag.show()

qt/aqt/utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ def getText(
560560
d = GetTextDialog(
561561
parent, prompt, help=help, edit=edit, default=default, title=title, **kwargs
562562
)
563+
add_close_shortcut(d)
563564
d.setWindowModality(Qt.WindowModality.WindowModal)
564565
if geomKey:
565566
restoreGeom(d, geomKey)
@@ -988,14 +989,6 @@ def maybeHideClose(bbox: QDialogButtonBox) -> None:
988989
bbox.removeButton(b)
989990

990991

991-
def addCloseShortcut(widg: QDialog) -> None:
992-
if not is_mac:
993-
return
994-
shortcut = QShortcut(QKeySequence("Ctrl+W"), widg)
995-
qconnect(shortcut.activated, widg.reject)
996-
setattr(widg, "_closeShortcut", shortcut)
997-
998-
999992
def add_close_shortcut(widg: QWidget) -> None:
1000993
if not is_mac:
1001994
return

0 commit comments

Comments
 (0)