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.ui.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter
|
||||||
from ankiqt import ui
|
from ankiqt import ui
|
||||||
from anki.sound import clearAudioQueue
|
from anki.sound import clearAudioQueue
|
||||||
|
from anki.hooks import addHook, removeHook
|
||||||
|
|
||||||
class FocusButton(QPushButton):
|
class FocusButton(QPushButton):
|
||||||
def focusInEvent(self, evt):
|
def focusInEvent(self, evt):
|
||||||
|
@ -36,12 +37,13 @@ class AddCards(QDialog):
|
||||||
self.addChooser()
|
self.addChooser()
|
||||||
self.addButtons()
|
self.addButtons()
|
||||||
self.setupStatus()
|
self.setupStatus()
|
||||||
self.modelChanged(self.parent.deck.currentModel)
|
self.modelChanged()
|
||||||
self.addedItems = 0
|
self.addedItems = 0
|
||||||
self.forceClose = False
|
self.forceClose = False
|
||||||
restoreGeom(self, "add")
|
restoreGeom(self, "add")
|
||||||
restoreSplitter(self.dialog.splitter, "add")
|
restoreSplitter(self.dialog.splitter, "add")
|
||||||
self.show()
|
self.show()
|
||||||
|
addHook('guiReset', self.modelChanged)
|
||||||
ui.dialogs.open("AddCards", self)
|
ui.dialogs.open("AddCards", self)
|
||||||
|
|
||||||
def setupEditor(self):
|
def setupEditor(self):
|
||||||
|
@ -52,8 +54,7 @@ class AddCards(QDialog):
|
||||||
def addChooser(self):
|
def addChooser(self):
|
||||||
self.modelChooser = ui.modelchooser.ModelChooser(self,
|
self.modelChooser = ui.modelchooser.ModelChooser(self,
|
||||||
self.parent,
|
self.parent,
|
||||||
self.parent.deck,
|
self.parent.deck)
|
||||||
self.modelChanged)
|
|
||||||
self.dialog.modelArea.setLayout(self.modelChooser)
|
self.dialog.modelArea.setLayout(self.modelChooser)
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
|
@ -97,7 +98,7 @@ class AddCards(QDialog):
|
||||||
browser.updateSearch()
|
browser.updateSearch()
|
||||||
browser.onFact()
|
browser.onFact()
|
||||||
|
|
||||||
def modelChanged(self, model):
|
def modelChanged(self):
|
||||||
oldFact = self.editor.fact
|
oldFact = self.editor.fact
|
||||||
# create a new fact
|
# create a new fact
|
||||||
fact = self.parent.deck.newFact()
|
fact = self.parent.deck.newFact()
|
||||||
|
@ -176,6 +177,7 @@ question or answer on all cards."""), parent=self)
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
||||||
def onClose(self):
|
def onClose(self):
|
||||||
|
removeHook('guiReset', self.modelChanged)
|
||||||
# stop anything playing
|
# stop anything playing
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
if (self.forceClose or self.editor.fieldsAreBlank() or
|
if (self.forceClose or self.editor.fieldsAreBlank() or
|
||||||
|
|
|
@ -9,10 +9,11 @@ from anki import stdmodels
|
||||||
from anki.models import *
|
from anki.models import *
|
||||||
from ankiqt import ui
|
from ankiqt import ui
|
||||||
import ankiqt.forms
|
import ankiqt.forms
|
||||||
|
from anki.hooks import addHook, removeHook
|
||||||
|
|
||||||
class ModelChooser(QHBoxLayout):
|
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)
|
QHBoxLayout.__init__(self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.main = main
|
self.main = main
|
||||||
|
@ -54,6 +55,7 @@ class ModelChooser(QHBoxLayout):
|
||||||
self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange)
|
self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange)
|
||||||
self.addWidget(self.cards)
|
self.addWidget(self.cards)
|
||||||
self.drawCardModels()
|
self.drawCardModels()
|
||||||
|
addHook('guiReset', self.onModelEdited)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
for i in range(self.count()):
|
for i in range(self.count()):
|
||||||
|
@ -68,6 +70,9 @@ class ModelChooser(QHBoxLayout):
|
||||||
onFinish=self.onModelEdited)
|
onFinish=self.onModelEdited)
|
||||||
|
|
||||||
def onModelEdited(self):
|
def onModelEdited(self):
|
||||||
|
# hack
|
||||||
|
from ankiqt import mw
|
||||||
|
self.deck = mw.deck
|
||||||
self.drawModels()
|
self.drawModels()
|
||||||
self.changed(self.deck.currentModel)
|
self.changed(self.deck.currentModel)
|
||||||
|
|
||||||
|
@ -79,7 +84,8 @@ class ModelChooser(QHBoxLayout):
|
||||||
|
|
||||||
def changed(self, model):
|
def changed(self, model):
|
||||||
self.deck.addModel(model)
|
self.deck.addModel(model)
|
||||||
self.onChangeFunc(model)
|
if self.onChangeFunc:
|
||||||
|
self.onChangeFunc(model)
|
||||||
self.drawCardModels()
|
self.drawCardModels()
|
||||||
|
|
||||||
def drawModels(self):
|
def drawModels(self):
|
||||||
|
|
Loading…
Reference in a new issue