mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Add callback and non-blocking option to StudyDeck (#1643)
* Callback for StudyDeck, use with onModelChange * Add types to callback function * Rationalise types * Update CONTRIBUTORS * Fix type hints I'm still getting to grips with the type hints! * Consistency with callback checks * | not supported for type hints on 3.9
This commit is contained in:
parent
1e59ad6200
commit
533735506c
3 changed files with 22 additions and 11 deletions
|
@ -93,6 +93,7 @@ qxo <49526356@qq.com>
|
|||
Spooghetti420 <github.com/spooghetti420>
|
||||
Danish Prakash <github.com/danishprakash>
|
||||
Araceli Yanez <github.com/aracelix>
|
||||
Sam Bradshaw <samjr.bradshaw@gmail.com>
|
||||
|
||||
********************
|
||||
|
||||
|
|
|
@ -79,7 +79,18 @@ class ModelChooser(QHBoxLayout):
|
|||
def nameFunc() -> list[str]:
|
||||
return [nt.name for nt in self.deck.models.all_names_and_ids()]
|
||||
|
||||
ret = StudyDeck(
|
||||
def callback(ret: StudyDeck) -> None:
|
||||
if not ret.name:
|
||||
return
|
||||
m = self.deck.models.by_name(ret.name)
|
||||
self.deck.conf["curModel"] = m["id"]
|
||||
cdeck = self.deck.decks.current()
|
||||
cdeck["mid"] = m["id"]
|
||||
self.deck.decks.save(cdeck)
|
||||
gui_hooks.current_note_type_did_change(current)
|
||||
self.mw.reset()
|
||||
|
||||
StudyDeck(
|
||||
self.mw,
|
||||
names=nameFunc,
|
||||
accept=tr.actions_choose(),
|
||||
|
@ -90,16 +101,8 @@ class ModelChooser(QHBoxLayout):
|
|||
buttons=[edit],
|
||||
cancel=True,
|
||||
geomKey="selectModel",
|
||||
callback=callback,
|
||||
)
|
||||
if not ret.name:
|
||||
return
|
||||
m = self.deck.models.by_name(ret.name)
|
||||
self.deck.conf["curModel"] = m["id"]
|
||||
cdeck = self.deck.decks.current()
|
||||
cdeck["mid"] = m["id"]
|
||||
self.deck.decks.save(cdeck)
|
||||
gui_hooks.current_note_type_did_change(current)
|
||||
self.mw.reset()
|
||||
|
||||
def updateModels(self) -> None:
|
||||
self.models.setText(self.deck.models.current()["name"].replace("&", "&&"))
|
||||
|
|
|
@ -36,6 +36,7 @@ class StudyDeck(QDialog):
|
|||
dyn: bool = False,
|
||||
buttons: Optional[list[Union[str, QPushButton]]] = None,
|
||||
geomKey: str = "default",
|
||||
callback: Union[Callable, None] = None,
|
||||
) -> None:
|
||||
QDialog.__init__(self, parent or mw)
|
||||
self.mw = mw
|
||||
|
@ -87,7 +88,11 @@ class StudyDeck(QDialog):
|
|||
self.show()
|
||||
# redraw after show so position at center correct
|
||||
self.redraw("", current)
|
||||
self.exec()
|
||||
self.callback = callback
|
||||
if callback:
|
||||
self.open()
|
||||
else:
|
||||
self.exec()
|
||||
|
||||
def eventFilter(self, obj: QObject, evt: QEvent) -> bool:
|
||||
if isinstance(evt, QKeyEvent) and evt.type() == QEvent.Type.KeyPress:
|
||||
|
@ -152,6 +157,8 @@ class StudyDeck(QDialog):
|
|||
showInfo(tr.decks_please_select_something())
|
||||
return
|
||||
self.name = self.names[self.form.list.currentRow()]
|
||||
if self.callback:
|
||||
self.callback(self)
|
||||
QDialog.accept(self)
|
||||
|
||||
def reject(self) -> None:
|
||||
|
|
Loading…
Reference in a new issue