mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
refresh add cards window & model chooser on gui reset
This commit is contained in:
parent
1001d6b7af
commit
636a661569
2 changed files with 14 additions and 6 deletions
|
@ -12,6 +12,7 @@ from anki.utils import stripHTML, parseTags
|
|||
from ankiqt.ui.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter
|
||||
from ankiqt import ui
|
||||
from anki.sound import clearAudioQueue
|
||||
from anki.hooks import addHook, removeHook
|
||||
|
||||
class FocusButton(QPushButton):
|
||||
def focusInEvent(self, evt):
|
||||
|
@ -36,12 +37,13 @@ class AddCards(QDialog):
|
|||
self.addChooser()
|
||||
self.addButtons()
|
||||
self.setupStatus()
|
||||
self.modelChanged(self.parent.deck.currentModel)
|
||||
self.modelChanged()
|
||||
self.addedItems = 0
|
||||
self.forceClose = False
|
||||
restoreGeom(self, "add")
|
||||
restoreSplitter(self.dialog.splitter, "add")
|
||||
self.show()
|
||||
addHook('guiReset', self.modelChanged)
|
||||
ui.dialogs.open("AddCards", self)
|
||||
|
||||
def setupEditor(self):
|
||||
|
@ -52,8 +54,7 @@ class AddCards(QDialog):
|
|||
def addChooser(self):
|
||||
self.modelChooser = ui.modelchooser.ModelChooser(self,
|
||||
self.parent,
|
||||
self.parent.deck,
|
||||
self.modelChanged)
|
||||
self.parent.deck)
|
||||
self.dialog.modelArea.setLayout(self.modelChooser)
|
||||
|
||||
def helpRequested(self):
|
||||
|
@ -97,7 +98,7 @@ class AddCards(QDialog):
|
|||
browser.updateSearch()
|
||||
browser.onFact()
|
||||
|
||||
def modelChanged(self, model):
|
||||
def modelChanged(self):
|
||||
oldFact = self.editor.fact
|
||||
# create a new fact
|
||||
fact = self.parent.deck.newFact()
|
||||
|
@ -176,6 +177,7 @@ question or answer on all cards."""), parent=self)
|
|||
QDialog.reject(self)
|
||||
|
||||
def onClose(self):
|
||||
removeHook('guiReset', self.modelChanged)
|
||||
# stop anything playing
|
||||
clearAudioQueue()
|
||||
if (self.forceClose or self.editor.fieldsAreBlank() or
|
||||
|
|
|
@ -9,10 +9,11 @@ from anki import stdmodels
|
|||
from anki.models import *
|
||||
from ankiqt import ui
|
||||
import ankiqt.forms
|
||||
from anki.hooks import addHook, removeHook
|
||||
|
||||
class ModelChooser(QHBoxLayout):
|
||||
|
||||
def __init__(self, parent, main, deck, onChangeFunc, cards=True, label=True):
|
||||
def __init__(self, parent, main, deck, onChangeFunc=None, cards=True, label=True):
|
||||
QHBoxLayout.__init__(self)
|
||||
self.parent = parent
|
||||
self.main = main
|
||||
|
@ -54,6 +55,7 @@ class ModelChooser(QHBoxLayout):
|
|||
self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange)
|
||||
self.addWidget(self.cards)
|
||||
self.drawCardModels()
|
||||
addHook('guiReset', self.onModelEdited)
|
||||
|
||||
def show(self):
|
||||
for i in range(self.count()):
|
||||
|
@ -68,6 +70,9 @@ class ModelChooser(QHBoxLayout):
|
|||
onFinish=self.onModelEdited)
|
||||
|
||||
def onModelEdited(self):
|
||||
# hack
|
||||
from ankiqt import mw
|
||||
self.deck = mw.deck
|
||||
self.drawModels()
|
||||
self.changed(self.deck.currentModel)
|
||||
|
||||
|
@ -79,7 +84,8 @@ class ModelChooser(QHBoxLayout):
|
|||
|
||||
def changed(self, model):
|
||||
self.deck.addModel(model)
|
||||
self.onChangeFunc(model)
|
||||
if self.onChangeFunc:
|
||||
self.onChangeFunc(model)
|
||||
self.drawCardModels()
|
||||
|
||||
def drawModels(self):
|
||||
|
|
Loading…
Reference in a new issue