diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 9f80d1d73..7e1509a3e 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -19,9 +19,7 @@ from aqt.qt import * from aqt.sound import av_player from aqt.utils import ( HelpPage, - addCloseShortcut, askUser, - disable_help_button, downArrow, openHelp, restoreGeom, @@ -33,17 +31,16 @@ from aqt.utils import ( ) -class AddCards(QDialog): +class AddCards(QMainWindow): def __init__(self, mw: AnkiQt) -> None: - QDialog.__init__(self, None, Qt.WindowType.Window) - mw.garbage_collect_on_dialog_finish(self) + super().__init__(None, Qt.WindowType.Window) + self._close_event_has_cleaned_up = False self.mw = mw self.col = mw.col form = aqt.forms.addcards.Ui_Dialog() form.setupUi(self) self.form = form self.setWindowTitle(tr.actions_add()) - disable_help_button(self) self.setMinimumHeight(300) self.setMinimumWidth(400) self.setup_choosers() @@ -54,7 +51,6 @@ class AddCards(QDialog): self._last_added_note: Optional[Note] = None gui_hooks.operation_did_execute.append(self.on_operation_did_execute) restoreGeom(self, "add") - addCloseShortcut(self) gui_hooks.add_cards_did_init(self) self.show() @@ -264,10 +260,20 @@ class AddCards(QDialog): return True - def reject(self) -> None: - self.ifCanClose(self._reject) + def keyPressEvent(self, evt: QKeyEvent) -> None: + if evt.key() == Qt.Key.Key_Escape: + self.close() + else: + super().keyPressEvent(evt) - def _reject(self) -> None: + def closeEvent(self, evt: QCloseEvent) -> None: + if self._close_event_has_cleaned_up: + evt.accept() + return + self.ifCanClose(self._close) + evt.ignore() + + def _close(self) -> None: av_player.stop_and_clear_queue() self.editor.cleanup() self.notetype_chooser.cleanup() @@ -276,7 +282,9 @@ class AddCards(QDialog): self.mw.maybeReset() saveGeom(self, "add") aqt.dialogs.markClosed("AddCards") - QDialog.reject(self) + self._close_event_has_cleaned_up = True + self.mw.deferred_delete_and_garbage_collect(self) + self.close() def ifCanClose(self, onOk: Callable) -> None: def afterSave() -> None: @@ -290,7 +298,7 @@ class AddCards(QDialog): def closeWithCallback(self, cb: Callable[[], None]) -> None: def doClose() -> None: - self._reject() + self._close() cb() self.ifCanClose(doClose) diff --git a/qt/aqt/forms/addcards.ui b/qt/aqt/forms/addcards.ui index 5f48fbcf4..81d8ad4b2 100644 --- a/qt/aqt/forms/addcards.ui +++ b/qt/aqt/forms/addcards.ui @@ -1,106 +1,471 @@ Dialog - + 0 0 - 453 - 366 + 750 + 493 - - actions_add + + + 400 + 400 + - + :/icons/anki.png:/icons/anki.png - - - 3 + + + + 12 + + + 12 + + + 6 + + + 12 + + + 12 + + + + + 6 + + + 0 + + + + + + 0 + 10 + + + + + + + + + + + + + + 0 + 10 + + + + true + + + + + + + QDialogButtonBox::NoButton + + + + + + + + + 0 + 0 + 750 + 26 + - - 12 + + + + QT_ACCEL_RESCHEDULE - - 6 + + + + qt_accel_select_all - - 12 + + Ctrl+Alt+A - - 12 + + + + qt_accel_undo - - - - 6 - - - 0 - - - - - - 0 - 10 - - - - - - - - - - - - - - 0 - 10 - - - - true - - - - - - - Qt::Horizontal - - - QDialogButtonBox::NoButton - - - - + + Ctrl+Z + + + + + qt_accel_invert_selection + + + Ctrl+Alt+S + + + + + qt_accel_find + + + Ctrl+F + + + + + qt_accel_note + + + Ctrl+Shift+N + + + + + qt_accel_next_card + + + Ctrl+N + + + + + qt_accel_previous_card + + + Ctrl+P + + + + + qt_accel_guide + + + F1 + + + + + browsing_change_note_type2 + + + Ctrl+Shift+M + + + + + qt_accel_select_notes + + + + + qt_accel_find_and_replace + + + Ctrl+Alt+F + + + + + qt_accel_filter + + + Ctrl+Shift+F + + + + + browsing_card_list + + + Ctrl+Shift+L + + + + + qt_accel_find_duplicates + + + + + browsing_reposition + + + Ctrl+Shift+S + + + + + browsing_first_card + + + Home + + + + + browsing_last_card + + + End + + + + + actions_close + + + Ctrl+W + + + + + qt_accel_info + + + Ctrl+Shift+I + + + + + browsing_add_tags2 + + + Ctrl+Shift+A + + + + + browsing_remove_tags + + + Ctrl+Alt+Shift+A + + + + + true + + + browsing_toggle_suspend + + + Ctrl+J + + + + + actions_delete + + + Ctrl+Del + + + + + browsing_add_notes + + + Ctrl+E + + + + + browsing_change_deck2 + + + Ctrl+D + + + + + true + + + actions_flag_red + + + Ctrl+1 + + + + + true + + + actions_flag_orange + + + Ctrl+2 + + + + + true + + + actions_flag_green + + + Ctrl+3 + + + + + true + + + actions_flag_blue + + + Ctrl+4 + + + + + browsing_sidebar + + + Ctrl+Shift+R + + + + + browsing_clear_unused_tags + + + + + browsing_manage_note_types + + + + + true + + + browsing_toggle_mark + + + Ctrl+K + + + + + qt_accel_export_notes + + + Ctrl+Shift+E + + + + + qt_misc_create_filtered_deck + + + Ctrl+G + + + + + qt_accel_set_due_date + + + Ctrl+Shift+D + + + + + qt_accel_forget + + + Ctrl+Alt+N + + + + + browsing_toggle_showing_cards_notes + + + Alt+T + + + + + qt_accel_redo + + + Ctrl+Shift+Z + + + + + true + + + actions_flag_pink + + + Ctrl+5 + + + + + true + + + actions_flag_turquoise + + + Ctrl+6 + + + + + true + + + actions_flag_purple + + + Ctrl+7 + + - - buttonBox - - buttonBox - rejected() + actionClose + triggered() Dialog - reject() + close() - 301 + -1 -1 - 286 - 274 + 374 + 199