Make add cards dialog a main window (#1486)

Closes #980.
This commit is contained in:
RumovZ 2021-11-14 02:33:59 +01:00 committed by GitHub
parent 5f05eeb922
commit 63316f763d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 458 additions and 85 deletions

View File

@ -19,9 +19,7 @@ from aqt.qt import *
from aqt.sound import av_player from aqt.sound import av_player
from aqt.utils import ( from aqt.utils import (
HelpPage, HelpPage,
addCloseShortcut,
askUser, askUser,
disable_help_button,
downArrow, downArrow,
openHelp, openHelp,
restoreGeom, restoreGeom,
@ -33,17 +31,16 @@ from aqt.utils import (
) )
class AddCards(QDialog): class AddCards(QMainWindow):
def __init__(self, mw: AnkiQt) -> None: def __init__(self, mw: AnkiQt) -> None:
QDialog.__init__(self, None, Qt.WindowType.Window) super().__init__(None, Qt.WindowType.Window)
mw.garbage_collect_on_dialog_finish(self) self._close_event_has_cleaned_up = False
self.mw = mw self.mw = mw
self.col = mw.col self.col = mw.col
form = aqt.forms.addcards.Ui_Dialog() form = aqt.forms.addcards.Ui_Dialog()
form.setupUi(self) form.setupUi(self)
self.form = form self.form = form
self.setWindowTitle(tr.actions_add()) self.setWindowTitle(tr.actions_add())
disable_help_button(self)
self.setMinimumHeight(300) self.setMinimumHeight(300)
self.setMinimumWidth(400) self.setMinimumWidth(400)
self.setup_choosers() self.setup_choosers()
@ -54,7 +51,6 @@ class AddCards(QDialog):
self._last_added_note: Optional[Note] = None self._last_added_note: Optional[Note] = None
gui_hooks.operation_did_execute.append(self.on_operation_did_execute) gui_hooks.operation_did_execute.append(self.on_operation_did_execute)
restoreGeom(self, "add") restoreGeom(self, "add")
addCloseShortcut(self)
gui_hooks.add_cards_did_init(self) gui_hooks.add_cards_did_init(self)
self.show() self.show()
@ -264,10 +260,20 @@ class AddCards(QDialog):
return True return True
def reject(self) -> None: def keyPressEvent(self, evt: QKeyEvent) -> None:
self.ifCanClose(self._reject) 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() av_player.stop_and_clear_queue()
self.editor.cleanup() self.editor.cleanup()
self.notetype_chooser.cleanup() self.notetype_chooser.cleanup()
@ -276,7 +282,9 @@ class AddCards(QDialog):
self.mw.maybeReset() self.mw.maybeReset()
saveGeom(self, "add") saveGeom(self, "add")
aqt.dialogs.markClosed("AddCards") 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 ifCanClose(self, onOk: Callable) -> None:
def afterSave() -> None: def afterSave() -> None:
@ -290,7 +298,7 @@ class AddCards(QDialog):
def closeWithCallback(self, cb: Callable[[], None]) -> None: def closeWithCallback(self, cb: Callable[[], None]) -> None:
def doClose() -> None: def doClose() -> None:
self._reject() self._close()
cb() cb()
self.ifCanClose(doClose) self.ifCanClose(doClose)

View File

@ -1,106 +1,471 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Dialog</class> <class>Dialog</class>
<widget class="QDialog" name="Dialog"> <widget class="QMainWindow" name="Dialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>453</width> <width>750</width>
<height>366</height> <height>493</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="minimumSize">
<string>actions_add</string> <size>
<width>400</width>
<height>400</height>
</size>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="icons.qrc"> <iconset>
<normaloff>:/icons/anki.png</normaloff>:/icons/anki.png</iconset> <normaloff>:/icons/anki.png</normaloff>:/icons/anki.png</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="QWidget" name="centralwidget">
<property name="spacing"> <layout class="QVBoxLayout" name="verticalLayout_3">
<number>3</number> <property name="spacing">
<number>12</number>
</property>
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="modelArea" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="deckArea" native="true"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="fieldsArea" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>26</height>
</rect>
</property> </property>
<property name="leftMargin"> </widget>
<number>12</number> <action name="actionReschedule">
<property name="text">
<string notr="true">QT_ACCEL_RESCHEDULE</string>
</property> </property>
<property name="topMargin"> </action>
<number>6</number> <action name="actionSelectAll">
<property name="text">
<string>qt_accel_select_all</string>
</property> </property>
<property name="rightMargin"> <property name="shortcut">
<number>12</number> <string notr="true">Ctrl+Alt+A</string>
</property> </property>
<property name="bottomMargin"> </action>
<number>12</number> <action name="actionUndo">
<property name="text">
<string>qt_accel_undo</string>
</property> </property>
<item> <property name="shortcut">
<layout class="QHBoxLayout" name="horizontalLayout"> <string notr="true">Ctrl+Z</string>
<property name="spacing"> </property>
<number>6</number> </action>
</property> <action name="actionInvertSelection">
<property name="bottomMargin"> <property name="text">
<number>0</number> <string>qt_accel_invert_selection</string>
</property> </property>
<item> <property name="shortcut">
<widget class="QWidget" name="modelArea" native="true"> <string notr="true">Ctrl+Alt+S</string>
<property name="minimumSize"> </property>
<size> </action>
<width>0</width> <action name="actionFind">
<height>10</height> <property name="text">
</size> <string>qt_accel_find</string>
</property> </property>
</widget> <property name="shortcut">
</item> <string notr="true">Ctrl+F</string>
<item> </property>
<widget class="QWidget" name="deckArea" native="true"/> </action>
</item> <action name="actionNote">
</layout> <property name="text">
</item> <string>qt_accel_note</string>
<item> </property>
<widget class="QWidget" name="fieldsArea" native="true"> <property name="shortcut">
<property name="sizePolicy"> <string notr="true">Ctrl+Shift+N</string>
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> </property>
<horstretch>0</horstretch> </action>
<verstretch>10</verstretch> <action name="actionNextCard">
</sizepolicy> <property name="text">
</property> <string>qt_accel_next_card</string>
<property name="autoFillBackground"> </property>
<bool>true</bool> <property name="shortcut">
</property> <string notr="true">Ctrl+N</string>
</widget> </property>
</item> </action>
<item> <action name="actionPreviousCard">
<widget class="QDialogButtonBox" name="buttonBox"> <property name="text">
<property name="orientation"> <string>qt_accel_previous_card</string>
<enum>Qt::Horizontal</enum> </property>
</property> <property name="shortcut">
<property name="standardButtons"> <string notr="true">Ctrl+P</string>
<set>QDialogButtonBox::NoButton</set> </property>
</property> </action>
</widget> <action name="actionGuide">
</item> <property name="text">
</layout> <string>qt_accel_guide</string>
</property>
<property name="shortcut">
<string notr="true">F1</string>
</property>
</action>
<action name="actionChangeModel">
<property name="text">
<string>browsing_change_note_type2</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+M</string>
</property>
</action>
<action name="actionSelectNotes">
<property name="text">
<string>qt_accel_select_notes</string>
</property>
</action>
<action name="actionFindReplace">
<property name="text">
<string>qt_accel_find_and_replace</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Alt+F</string>
</property>
</action>
<action name="actionSidebarFilter">
<property name="text">
<string>qt_accel_filter</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+F</string>
</property>
</action>
<action name="actionCardList">
<property name="text">
<string>browsing_card_list</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+L</string>
</property>
</action>
<action name="actionFindDuplicates">
<property name="text">
<string>qt_accel_find_duplicates</string>
</property>
</action>
<action name="actionReposition">
<property name="text">
<string>browsing_reposition</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+S</string>
</property>
</action>
<action name="actionFirstCard">
<property name="text">
<string>browsing_first_card</string>
</property>
<property name="shortcut">
<string notr="true">Home</string>
</property>
</action>
<action name="actionLastCard">
<property name="text">
<string>browsing_last_card</string>
</property>
<property name="shortcut">
<string notr="true">End</string>
</property>
</action>
<action name="actionClose">
<property name="text">
<string>actions_close</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+W</string>
</property>
</action>
<action name="action_Info">
<property name="text">
<string>qt_accel_info</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+I</string>
</property>
</action>
<action name="actionAdd_Tags">
<property name="text">
<string>browsing_add_tags2</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+A</string>
</property>
</action>
<action name="actionRemove_Tags">
<property name="text">
<string>browsing_remove_tags</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Alt+Shift+A</string>
</property>
</action>
<action name="actionToggle_Suspend">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>browsing_toggle_suspend</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+J</string>
</property>
</action>
<action name="actionDelete">
<property name="text">
<string>actions_delete</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Del</string>
</property>
</action>
<action name="actionAdd">
<property name="text">
<string>browsing_add_notes</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+E</string>
</property>
</action>
<action name="actionChange_Deck">
<property name="text">
<string>browsing_change_deck2</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+D</string>
</property>
</action>
<action name="actionRed_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_red</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+1</string>
</property>
</action>
<action name="actionOrange_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_orange</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+2</string>
</property>
</action>
<action name="actionGreen_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_green</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+3</string>
</property>
</action>
<action name="actionBlue_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_blue</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+4</string>
</property>
</action>
<action name="actionSidebar">
<property name="text">
<string>browsing_sidebar</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+R</string>
</property>
</action>
<action name="actionClear_Unused_Tags">
<property name="text">
<string>browsing_clear_unused_tags</string>
</property>
</action>
<action name="actionManage_Note_Types">
<property name="text">
<string>browsing_manage_note_types</string>
</property>
</action>
<action name="actionToggle_Mark">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>browsing_toggle_mark</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+K</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>qt_accel_export_notes</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+E</string>
</property>
</action>
<action name="actionCreateFilteredDeck">
<property name="text">
<string>qt_misc_create_filtered_deck</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+G</string>
</property>
</action>
<action name="action_set_due_date">
<property name="text">
<string>qt_accel_set_due_date</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+D</string>
</property>
</action>
<action name="action_forget">
<property name="text">
<string>qt_accel_forget</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Alt+N</string>
</property>
</action>
<action name="action_toggle_mode">
<property name="text">
<string>browsing_toggle_showing_cards_notes</string>
</property>
<property name="shortcut">
<string notr="true">Alt+T</string>
</property>
</action>
<action name="actionRedo">
<property name="text">
<string>qt_accel_redo</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+Z</string>
</property>
</action>
<action name="actionPink_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_pink</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+5</string>
</property>
</action>
<action name="actionTurquoise_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_turquoise</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+6</string>
</property>
</action>
<action name="actionPurple_Flag">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>actions_flag_purple</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+7</string>
</property>
</action>
</widget> </widget>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>actionClose</sender>
<signal>rejected()</signal> <signal>triggered()</signal>
<receiver>Dialog</receiver> <receiver>Dialog</receiver>
<slot>reject()</slot> <slot>close()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>301</x> <x>-1</x>
<y>-1</y> <y>-1</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>374</x>
<y>274</y> <y>199</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>