mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 13:17:12 -05:00
start of clayout port
This commit is contained in:
parent
37b7bb00d6
commit
2f6867c4cc
6 changed files with 138 additions and 201 deletions
302
aqt/clayout.py
302
aqt/clayout.py
|
|
@ -4,17 +4,15 @@
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView
|
from PyQt4.QtWebKit import QWebPage, QWebView
|
||||||
import sys, re
|
import re
|
||||||
import aqt.forms
|
from anki.consts import *
|
||||||
import anki
|
#from anki.models import *
|
||||||
from anki.models import *
|
#from anki.facts import *
|
||||||
from anki.facts import *
|
import aqt
|
||||||
from anki.cards import Card
|
|
||||||
from anki.sound import playFromText, clearAudioQueue
|
from anki.sound import playFromText, clearAudioQueue
|
||||||
from aqt.ui.utils import saveGeom, restoreGeom, getBase, mungeQA, \
|
from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \
|
||||||
saveSplitter, restoreSplitter
|
saveSplitter, restoreSplitter, showInfo, isMac, isWin
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
from aqt import ui
|
|
||||||
|
|
||||||
class ResizingTextEdit(QTextEdit):
|
class ResizingTextEdit(QTextEdit):
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
|
|
@ -22,137 +20,102 @@ class ResizingTextEdit(QTextEdit):
|
||||||
|
|
||||||
class CardLayout(QDialog):
|
class CardLayout(QDialog):
|
||||||
|
|
||||||
def __init__(self, parent, factedit, factOrModel, card=None):
|
# type is previewCards() type
|
||||||
self.parent = parent
|
def __init__(self, mw, fact, type=0, ord=0, parent=None):
|
||||||
QDialog.__init__(self, parent, Qt.Window)
|
QDialog.__init__(self, parent or mw, Qt.Window)
|
||||||
self.mw = aqt.mw
|
self.mw = aqt.mw
|
||||||
|
self.fact = fact
|
||||||
|
self.type = type
|
||||||
|
self.ord = ord
|
||||||
self.deck = self.mw.deck
|
self.deck = self.mw.deck
|
||||||
self.factedit = factedit
|
self.model = fact.model()
|
||||||
self.card = card
|
|
||||||
if factedit is not None:
|
|
||||||
self.fact = factOrModel
|
|
||||||
self.model = self.fact.model
|
|
||||||
else:
|
|
||||||
self.model = factOrModel
|
|
||||||
# see if there's an available fact
|
|
||||||
id = self.deck.db.scalar(
|
|
||||||
"select id from facts where modelId = :id", id=self.model.id)
|
|
||||||
if id:
|
|
||||||
self.fact = self.deck.db.query(Fact).get(id)
|
|
||||||
else:
|
|
||||||
# generate a dummy one
|
|
||||||
self.fact = self.deck.newFact(self.model)
|
|
||||||
for f in self.fact.keys():
|
|
||||||
self.fact[f] = f
|
|
||||||
self.plastiqueStyle = None
|
|
||||||
if (sys.platform.startswith("darwin") or
|
|
||||||
sys.platform.startswith("win32")):
|
|
||||||
self.plastiqueStyle = QStyleFactory.create("plastique")
|
|
||||||
if self.card:
|
|
||||||
# limited to an existing template
|
|
||||||
self.cards = [self.deck.db.query(Card).get(id) for id in
|
|
||||||
self.deck.db.column0(
|
|
||||||
"select id from cards where factId = :fid "
|
|
||||||
"order by ordinal", fid=self.fact.id)]
|
|
||||||
type = 0
|
|
||||||
else:
|
|
||||||
if factedit:
|
|
||||||
# active & possible
|
|
||||||
self.cards = self.deck.previewFact(self.fact)
|
|
||||||
type = 1
|
|
||||||
else:
|
|
||||||
# all
|
|
||||||
self.cards = self.deck.previewFact(self.fact, cms=self.model.cardModels)
|
|
||||||
type = 2
|
|
||||||
if not self.cards:
|
|
||||||
ui.utils.showInfo(_(
|
|
||||||
"Please enter some text first."),
|
|
||||||
parent=self.parent)
|
|
||||||
return
|
|
||||||
self.form = aqt.forms.clayout.Ui_Dialog()
|
self.form = aqt.forms.clayout.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
restoreSplitter(self.form.splitter, "clayout")
|
self.plastiqueStyle = None
|
||||||
if type == 0:
|
if isMac or isWin:
|
||||||
self.form.templateType.setText(
|
self.plastiqueStyle = QStyleFactory.create("plastique")
|
||||||
_("Templates used by fact:"))
|
# FIXME: add editing
|
||||||
elif type == 1:
|
|
||||||
self.form.templateType.setText(
|
|
||||||
_("Templates that will be created:"))
|
|
||||||
else:
|
|
||||||
self.form.templateType.setText(
|
|
||||||
_("All templates:"))
|
|
||||||
# FIXME: add this
|
|
||||||
self.form.editTemplates.hide()
|
self.form.editTemplates.hide()
|
||||||
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
|
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
|
||||||
self.onHelp)
|
self.onHelp)
|
||||||
self.setupCards()
|
self.setupCards()
|
||||||
self.setupFields()
|
self.setupFields()
|
||||||
|
restoreSplitter(self.form.splitter, "clayout")
|
||||||
restoreGeom(self, "CardLayout")
|
restoreGeom(self, "CardLayout")
|
||||||
# hack to ensure we're focused on the active template in the model
|
self.reload()
|
||||||
# properties
|
if not self.cards:
|
||||||
if type == 2 and factOrModel.currentCard.ordinal != 0:
|
showInfo(_("Please enter some text first."),
|
||||||
idx = factOrModel.currentCard.ordinal
|
parent=parent or mw)
|
||||||
self.form.cardList.setCurrentIndex(idx)
|
return
|
||||||
self.cardChanged(idx)
|
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
self.cards = self.deck.previewCards(self.fact, self.type)
|
||||||
|
self.fillCardList()
|
||||||
|
self.fillFieldList()
|
||||||
|
self.fieldChanged(0)
|
||||||
|
self.readField()
|
||||||
|
|
||||||
# Cards & Preview
|
# Cards & Preview
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def setupCards(self):
|
def setupCards(self):
|
||||||
self.needFormatRebuild = False
|
|
||||||
self.updatingCards = False
|
self.updatingCards = False
|
||||||
self.playedAudio = {}
|
self.playedAudio = {}
|
||||||
|
f = self.form
|
||||||
|
if type == 0:
|
||||||
|
f.templateType.setText(
|
||||||
|
_("Templates used by fact:"))
|
||||||
|
elif type == 1:
|
||||||
|
f.templateType.setText(
|
||||||
|
_("Templates that will be created:"))
|
||||||
|
else:
|
||||||
|
f.templateType.setText(
|
||||||
|
_("All templates:"))
|
||||||
# replace with more appropriate size hints
|
# replace with more appropriate size hints
|
||||||
for e in ("cardQuestion", "cardAnswer"):
|
for e in ("cardQuestion", "cardAnswer"):
|
||||||
w = getattr(self.form, e)
|
w = getattr(f, e)
|
||||||
idx = self.form.templateLayout.indexOf(w)
|
idx = f.templateLayout.indexOf(w)
|
||||||
r = self.form.templateLayout.getItemPosition(idx)
|
r = f.templateLayout.getItemPosition(idx)
|
||||||
self.form.templateLayout.removeWidget(w)
|
f.templateLayout.removeWidget(w)
|
||||||
w.hide()
|
w.hide()
|
||||||
w.deleteLater()
|
w.deleteLater()
|
||||||
w = ResizingTextEdit(self)
|
w = ResizingTextEdit(self)
|
||||||
setattr(self.form, e, w)
|
setattr(f, e, w)
|
||||||
self.form.templateLayout.addWidget(w, r[0], r[1])
|
f.templateLayout.addWidget(w, r[0], r[1])
|
||||||
self.connect(self.form.cardList, SIGNAL("activated(int)"),
|
self.connect(f.cardList, SIGNAL("activated(int)"),
|
||||||
self.cardChanged)
|
self.cardChanged)
|
||||||
# self.connect(self.form.editTemplates, SIGNAL("clicked())"),
|
# self.connect(f.editTemplates, SIGNAL("clicked())"),
|
||||||
# self.onEdit)
|
# self.onEdit)
|
||||||
self.connect(self.form.cardQuestion, SIGNAL("textChanged()"),
|
c = self.connect
|
||||||
lambda: self.formatChanged("question"))
|
c(f.cardQuestion, SIGNAL("textChanged()"), self.formatChanged)
|
||||||
self.connect(self.form.cardAnswer, SIGNAL("textChanged()"),
|
c(f.cardAnswer, SIGNAL("textChanged()"), self.formatChanged)
|
||||||
lambda: self.formatChanged("answer"))
|
c(f.alignment, SIGNAL("activated(int)"), self.saveCard)
|
||||||
self.connect(self.form.alignment,
|
c(f.background, SIGNAL("clicked()"),
|
||||||
SIGNAL("activated(int)"),
|
lambda w=f.background:\
|
||||||
self.saveCard)
|
|
||||||
self.connect(self.form.background,
|
|
||||||
SIGNAL("clicked()"),
|
|
||||||
lambda w=self.form.background:\
|
|
||||||
self.chooseColour(w, "card"))
|
self.chooseColour(w, "card"))
|
||||||
self.connect(self.form.questionInAnswer,
|
c(f.questionInAnswer, SIGNAL("clicked()"), self.saveCard)
|
||||||
SIGNAL("clicked()"), self.saveCard)
|
c(f.allowEmptyAnswer, SIGNAL("clicked()"), self.saveCard)
|
||||||
self.connect(self.form.allowEmptyAnswer,
|
c(f.typeAnswer, SIGNAL("activated(int)"), self.saveCard)
|
||||||
SIGNAL("clicked()"), self.saveCard)
|
c(f.flipButton, SIGNAL("clicked()"), self.onFlip)
|
||||||
self.connect(self.form.typeAnswer, SIGNAL("activated(int)"),
|
|
||||||
self.saveCard)
|
|
||||||
self.connect(self.form.flipButton, SIGNAL("clicked()"),
|
|
||||||
self.onFlip)
|
|
||||||
def linkClicked(url):
|
def linkClicked(url):
|
||||||
QDesktopServices.openUrl(QUrl(url))
|
QDesktopServices.openUrl(QUrl(url))
|
||||||
self.form.preview.page().setLinkDelegationPolicy(
|
f.preview.page().setLinkDelegationPolicy(
|
||||||
QWebPage.DelegateExternalLinks)
|
QWebPage.DelegateExternalLinks)
|
||||||
self.connect(self.form.preview,
|
self.connect(f.preview,
|
||||||
SIGNAL("linkClicked(QUrl)"),
|
SIGNAL("linkClicked(QUrl)"),
|
||||||
linkClicked)
|
linkClicked)
|
||||||
if self.plastiqueStyle:
|
if self.plastiqueStyle:
|
||||||
self.form.background.setStyle(self.plastiqueStyle)
|
f.background.setStyle(self.plastiqueStyle)
|
||||||
self.form.alignment.clear()
|
f.alignment.addItems(
|
||||||
self.form.alignment.addItems(
|
|
||||||
QStringList(alignmentLabels().values()))
|
QStringList(alignmentLabels().values()))
|
||||||
self.fillCardList()
|
self.typeFieldNames = self.model.fieldMap()
|
||||||
|
s = [_("Don't ask me to type in the answer")]
|
||||||
|
s += [_("Compare with field '%s'") % fi
|
||||||
|
for fi in self.typeFieldNames.keys()]
|
||||||
|
f.typeAnswer.insertItems(0, QStringList(s))
|
||||||
|
|
||||||
def formatToScreen(self, fmt):
|
def formatToScreen(self, fmt):
|
||||||
fmt = re.sub("%\((.+?)\)s", "{{\\1}}", fmt)
|
|
||||||
fmt = fmt.replace("}}<br>", "}}\n")
|
fmt = fmt.replace("}}<br>", "}}\n")
|
||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
|
|
@ -165,31 +128,13 @@ class CardLayout(QDialog):
|
||||||
# self, self.deck, self.model, self.mw,
|
# self, self.deck, self.model, self.mw,
|
||||||
# onFinish=self.updateModelsList)
|
# onFinish=self.updateModelsList)
|
||||||
|
|
||||||
def formatChanged(self, type):
|
def formatChanged(self):
|
||||||
if self.updatingCards:
|
if self.updatingCards:
|
||||||
return
|
return
|
||||||
if type == "question":
|
text = unicode(self.form.cardQuestion.toPlainText())
|
||||||
text = unicode(self.form.cardQuestion.toPlainText())
|
self.card.template()['qfmt'] = self.screenToFormat(text)
|
||||||
text = self.screenToFormat(text)
|
text = unicode(self.form.cardAnswer.toPlainText())
|
||||||
#self.realCardModel(self.card).qformat = text
|
self.card.template()['afmt'] = self.screenToFormat(text)
|
||||||
self.card.cardModel.qformat = text
|
|
||||||
else:
|
|
||||||
text = unicode(self.form.cardAnswer.toPlainText())
|
|
||||||
text = self.screenToFormat(text)
|
|
||||||
self.card.cardModel.aformat = text
|
|
||||||
self.fact.model.setModified()
|
|
||||||
self.deck.flushMod()
|
|
||||||
d = {}
|
|
||||||
for f in self.fact.model.fieldModels:
|
|
||||||
d[f.name] = (f.id, self.fact[f.name])
|
|
||||||
for card in self.cards:
|
|
||||||
qa = formatQA(None, self.fact.modelId, d, card.splitTags(),
|
|
||||||
card.cardModel, self.deck)
|
|
||||||
card.question = qa['question']
|
|
||||||
card.answer = qa['answer']
|
|
||||||
card.setModified()
|
|
||||||
self.deck.setModified()
|
|
||||||
self.needFormatRebuild = True
|
|
||||||
self.renderPreview()
|
self.renderPreview()
|
||||||
|
|
||||||
def onFlip(self):
|
def onFlip(self):
|
||||||
|
|
@ -199,29 +144,19 @@ class CardLayout(QDialog):
|
||||||
self.form.cardQuestion.setPlainText(a)
|
self.form.cardQuestion.setPlainText(a)
|
||||||
|
|
||||||
def readCard(self):
|
def readCard(self):
|
||||||
card = self.card.cardModel
|
|
||||||
self.form.background.setPalette(QPalette(QColor(
|
|
||||||
getattr(card, "lastFontColour"))))
|
|
||||||
self.updatingCards = True
|
self.updatingCards = True
|
||||||
self.form.cardQuestion.setPlainText(self.formatToScreen(card.qformat))
|
t = self.card.template()
|
||||||
self.form.cardAnswer.setPlainText(self.formatToScreen(card.aformat))
|
f = self.form
|
||||||
self.form.questionInAnswer.setChecked(card.questionInAnswer)
|
f.background.setPalette(QPalette(QColor(t['bg'])))
|
||||||
self.form.allowEmptyAnswer.setChecked(card.allowEmptyAnswer)
|
f.cardQuestion.setPlainText(self.formatToScreen(t['qfmt']))
|
||||||
self.form.alignment.setCurrentIndex(card.questionAlign)
|
f.cardAnswer.setPlainText(self.formatToScreen(t['afmt']))
|
||||||
self.form.typeAnswer.clear()
|
f.questionInAnswer.setChecked(t['hideQ'])
|
||||||
self.typeFieldNames = self.deck.db.column0("""
|
f.allowEmptyAnswer.setChecked(t['emptyAns'])
|
||||||
select fieldModels.name as n from fieldModels, cardModels
|
f.alignment.setCurrentIndex(t['align'])
|
||||||
where cardModels.modelId = fieldModels.modelId
|
if t['typeAns'] is None:
|
||||||
and cardModels.id = :id
|
f.typeAnswer.setCurrentIndex(0)
|
||||||
order by n""", id=card.id)
|
else:
|
||||||
s = [_("Don't ask me to type in the answer")]
|
f.typeAnswer.setCurrentIndex(t['typeAns'] + 1)
|
||||||
s += [_("Compare with field '%s'") % f for f in self.typeFieldNames]
|
|
||||||
self.form.typeAnswer.insertItems(0, QStringList(s))
|
|
||||||
try:
|
|
||||||
idx = self.typeFieldNames.index(card.typeAnswer)
|
|
||||||
except ValueError:
|
|
||||||
idx = -1
|
|
||||||
self.form.typeAnswer.setCurrentIndex(idx + 1)
|
|
||||||
self.updatingCards = False
|
self.updatingCards = False
|
||||||
|
|
||||||
def fillCardList(self):
|
def fillCardList(self):
|
||||||
|
|
@ -229,16 +164,15 @@ order by n""", id=card.id)
|
||||||
cards = []
|
cards = []
|
||||||
idx = 0
|
idx = 0
|
||||||
for n, c in enumerate(self.cards):
|
for n, c in enumerate(self.cards):
|
||||||
if c == self.card:
|
if c.ord == self.ord:
|
||||||
cards.append(_("%s (current)") % c.cardModel.name)
|
cards.append(_("%s (current)") % c.template()['name'])
|
||||||
idx = n
|
idx = n
|
||||||
else:
|
else:
|
||||||
cards.append(c.cardModel.name)
|
cards.append(c.template()['name'])
|
||||||
self.form.cardList.addItems(
|
self.form.cardList.addItems(
|
||||||
QStringList(cards))
|
QStringList(cards))
|
||||||
self.form.editTemplates.setEnabled(False)
|
self.form.editTemplates.setEnabled(False)
|
||||||
if idx != 0:
|
self.form.cardList.setCurrentIndex(idx)
|
||||||
self.form.cardList.setCurrentIndex(idx)
|
|
||||||
self.cardChanged(idx)
|
self.cardChanged(idx)
|
||||||
self.form.cardList.setFocus()
|
self.form.cardList.setFocus()
|
||||||
|
|
||||||
|
|
@ -278,34 +212,28 @@ order by n""", id=card.id)
|
||||||
|
|
||||||
def renderPreview(self):
|
def renderPreview(self):
|
||||||
c = self.card
|
c = self.card
|
||||||
styles = (self.deck.rebuildCSS() +
|
styles = self.model.genCSS()
|
||||||
("\nhtml { background: %s }" % c.cardModel.lastFontColour))
|
|
||||||
styles = runFilter("addStyles", styles, c)
|
|
||||||
self.form.preview.setHtml(
|
self.form.preview.setHtml(
|
||||||
('<html><head>%s</head><body>' % getBase(self.deck, c)) +
|
('<html><head>%s</head><body>' % getBase(self.deck, c)) +
|
||||||
"<style>" + styles + "</style>" +
|
"<style>" + styles + "</style>" +
|
||||||
runFilter("drawQuestion", mungeQA(self.deck, c.htmlQuestion()),
|
mungeQA(c.q(reload=True)) +
|
||||||
c) +
|
|
||||||
"<hr>" +
|
"<hr>" +
|
||||||
runFilter("drawAnswer", mungeQA(self.deck, c.htmlAnswer()),
|
mungeQA(c.a())
|
||||||
c)
|
|
||||||
+ "</body></html>")
|
+ "</body></html>")
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
if c.id not in self.playedAudio:
|
if c.id not in self.playedAudio:
|
||||||
playFromText(c.question)
|
playFromText(c.q())
|
||||||
playFromText(c.answer)
|
playFromText(c.a())
|
||||||
self.playedAudio[c.id] = True
|
self.playedAudio[c.id] = True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
return
|
||||||
|
self.fact.model.setModified()
|
||||||
|
|
||||||
modified = False
|
modified = False
|
||||||
self.mw.startProgress()
|
self.mw.startProgress()
|
||||||
self.deck.updateProgress(_("Applying changes..."))
|
self.deck.updateProgress(_("Applying changes..."))
|
||||||
reset=True
|
reset=True
|
||||||
if self.needFormatRebuild:
|
|
||||||
# need to generate q/a templates
|
|
||||||
self.deck.updateCardsFromModel(self.fact.model)
|
|
||||||
self.deck.finishProgress()
|
|
||||||
modified = True
|
|
||||||
if len(self.fieldOrdinalUpdatedIds) > 0:
|
if len(self.fieldOrdinalUpdatedIds) > 0:
|
||||||
self.deck.rebuildFieldOrdinals(self.model.id, self.fieldOrdinalUpdatedIds)
|
self.deck.rebuildFieldOrdinals(self.model.id, self.fieldOrdinalUpdatedIds)
|
||||||
modified = True
|
modified = True
|
||||||
|
|
@ -334,9 +262,6 @@ order by n""", id=card.id)
|
||||||
self.fieldOrdinalUpdatedIds = []
|
self.fieldOrdinalUpdatedIds = []
|
||||||
self.updatingFields = False
|
self.updatingFields = False
|
||||||
self.needFieldRebuild = False
|
self.needFieldRebuild = False
|
||||||
self.fillFieldList()
|
|
||||||
self.fieldChanged(0)
|
|
||||||
self.readField()
|
|
||||||
self.connect(self.form.fieldList, SIGNAL("currentRowChanged(int)"),
|
self.connect(self.form.fieldList, SIGNAL("currentRowChanged(int)"),
|
||||||
self.fieldChanged)
|
self.fieldChanged)
|
||||||
self.connect(self.form.fieldAdd, SIGNAL("clicked()"),
|
self.connect(self.form.fieldAdd, SIGNAL("clicked()"),
|
||||||
|
|
@ -377,28 +302,23 @@ order by n""", id=card.id)
|
||||||
def fieldChanged(self, idx):
|
def fieldChanged(self, idx):
|
||||||
if self.updatingFields:
|
if self.updatingFields:
|
||||||
return
|
return
|
||||||
self.field = self.model.fieldModels[idx]
|
self.field = self.model.fields[idx]
|
||||||
self.readField()
|
self.readField()
|
||||||
self.enableFieldMoveButtons()
|
self.enableFieldMoveButtons()
|
||||||
|
|
||||||
def readField(self):
|
def readField(self):
|
||||||
field = self.field
|
fld = self.field
|
||||||
|
f = self.form
|
||||||
self.updatingFields = True
|
self.updatingFields = True
|
||||||
self.form.fieldName.setText(field.name)
|
f.fieldName.setText(fld['name'])
|
||||||
self.form.fieldUnique.setChecked(field.unique)
|
f.fieldUnique.setChecked(fld['uniq'])
|
||||||
self.form.fieldRequired.setChecked(field.required)
|
f.fieldRequired.setChecked(fld['req'])
|
||||||
self.form.numeric.setChecked(field.numeric)
|
f.fontFamily.setCurrentFont(QFont(fld['font']))
|
||||||
if not field.quizFontFamily:
|
f.fontSize.setValue(fld['qsize'])
|
||||||
# backwards compat
|
f.fontSizeEdit.setValue(fld['esize'])
|
||||||
field.quizFontFamily = u"Arial"
|
f.fontColour.setPalette(QPalette(QColor(fld['qcol'])))
|
||||||
self.form.fontFamily.setCurrentFont(QFont(
|
f.rtl.setChecked(fld['rtl'])
|
||||||
field.quizFontFamily))
|
f.preserveWhitespace.setChecked(fld['pre'])
|
||||||
self.form.fontSize.setValue(field.quizFontSize or 20)
|
|
||||||
self.form.fontSizeEdit.setValue(field.editFontSize or 20)
|
|
||||||
self.form.fontColour.setPalette(QPalette(QColor(
|
|
||||||
field.quizFontColour or "#000000")))
|
|
||||||
self.form.rtl.setChecked(not not field.features)
|
|
||||||
self.form.preserveWhitespace.setChecked(not not field.editFontFamily)
|
|
||||||
self.updatingFields = False
|
self.updatingFields = False
|
||||||
|
|
||||||
def saveField(self, *args):
|
def saveField(self, *args):
|
||||||
|
|
@ -445,8 +365,8 @@ order by n""", id=card.id)
|
||||||
oldRow = 0
|
oldRow = 0
|
||||||
self.form.fieldList.clear()
|
self.form.fieldList.clear()
|
||||||
n = 1
|
n = 1
|
||||||
for field in self.model.fieldModels:
|
for field in self.model.fields:
|
||||||
label = field.name
|
label = field['name']
|
||||||
item = QListWidgetItem(label)
|
item = QListWidgetItem(label)
|
||||||
self.form.fieldList.addItem(item)
|
self.form.fieldList.addItem(item)
|
||||||
n += 1
|
n += 1
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from aqt.utils import showText
|
||||||
|
|
||||||
class ErrorHandler(QObject):
|
class ErrorHandler(QObject):
|
||||||
"Catch stderr and write into buffer."
|
"Catch stderr and write into buffer."
|
||||||
|
ivl = 100
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
QObject.__init__(self, mw)
|
QObject.__init__(self, mw)
|
||||||
|
|
@ -35,11 +36,10 @@ class ErrorHandler(QObject):
|
||||||
self.emit(SIGNAL("errorTimer"))
|
self.emit(SIGNAL("errorTimer"))
|
||||||
|
|
||||||
def _setTimer(self):
|
def _setTimer(self):
|
||||||
ivl = 200
|
|
||||||
if not self.timer:
|
if not self.timer:
|
||||||
self.timer = QTimer(self.mw)
|
self.timer = QTimer(self.mw)
|
||||||
self.mw.connect(self.timer, SIGNAL("timeout()"), self.onTimeout)
|
self.mw.connect(self.timer, SIGNAL("timeout()"), self.onTimeout)
|
||||||
self.timer.setInterval(200)
|
self.timer.setInterval(self.ivl)
|
||||||
self.timer.setSingleShot(True)
|
self.timer.setSingleShot(True)
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -655,8 +655,9 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
aqt.stats.DeckStats(self)
|
aqt.stats.DeckStats(self)
|
||||||
|
|
||||||
def onCardLayout(self):
|
def onCardLayout(self):
|
||||||
aqt.clayout.CardLayout(self, 0, self.currentCard.fact,
|
from aqt.clayout import CardLayout
|
||||||
card=self.currentCard)
|
CardLayout(self, self.reviewer.card.fact(), type=1,
|
||||||
|
ord=self.reviewer.card.ord)
|
||||||
|
|
||||||
def onDeckProperties(self):
|
def onDeckProperties(self):
|
||||||
import aqt.deckopts
|
import aqt.deckopts
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,18 @@ class ModelProperties(QDialog):
|
||||||
self.cardLayout)
|
self.cardLayout)
|
||||||
|
|
||||||
def cardLayout(self):
|
def cardLayout(self):
|
||||||
|
# # see if there's an available fact
|
||||||
|
# id = self.deck.db.scalar(
|
||||||
|
# "select id from facts where modelId = :id", id=self.model.id)
|
||||||
|
# if id:
|
||||||
|
# self.fact = self.deck.db.query(Fact).get(id)
|
||||||
|
# else:
|
||||||
|
# # generate a dummy one
|
||||||
|
# self.fact = self.deck.newFact(self.model)
|
||||||
|
# for f in self.fact.keys():
|
||||||
|
# self.fact[f] = f
|
||||||
|
|
||||||
|
|
||||||
self.m.currentCard = self.currentCard
|
self.m.currentCard = self.currentCard
|
||||||
ui.clayout.CardLayout(self, None, self.m)
|
ui.clayout.CardLayout(self, None, self.m)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,6 @@ div#filler {
|
||||||
css = self.mw.sharedCSS
|
css = self.mw.sharedCSS
|
||||||
css += self.mw.deck.allCSS()
|
css += self.mw.deck.allCSS()
|
||||||
css += self._css
|
css += self._css
|
||||||
css = runFilter("addStyles", css)
|
|
||||||
return css
|
return css
|
||||||
|
|
||||||
# Type in the answer
|
# Type in the answer
|
||||||
|
|
|
||||||
15
aqt/utils.py
15
aqt/utils.py
|
|
@ -267,15 +267,17 @@ def applyStyles(widget):
|
||||||
def getBase(deck, card):
|
def getBase(deck, card):
|
||||||
base = None
|
base = None
|
||||||
if deck and card:
|
if deck and card:
|
||||||
if deck.getBool("remoteImages") and card.fact.model.features:
|
print "fixme: remote images"
|
||||||
base = card.fact.model.features
|
mdir = deck.media.dir()
|
||||||
elif deck.mediaDir():
|
if False: # deck.getBool("remoteImages") and card.fact.model.features:
|
||||||
if sys.platform.startswith("win32"):
|
pass #base = card.fact.model.features
|
||||||
|
elif mdir:
|
||||||
|
if isWin:
|
||||||
prefix = u"file:///"
|
prefix = u"file:///"
|
||||||
else:
|
else:
|
||||||
prefix = u"file://"
|
prefix = u"file://"
|
||||||
base = prefix + unicode(
|
base = prefix + unicode(
|
||||||
urllib.quote(deck.mediaDir().encode("utf-8")),
|
urllib.quote(mdir.encode("utf-8")),
|
||||||
"utf-8") + "/"
|
"utf-8") + "/"
|
||||||
if base:
|
if base:
|
||||||
return '<base href="%s">' % base
|
return '<base href="%s">' % base
|
||||||
|
|
@ -294,3 +296,6 @@ def shortcut(key):
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
return re.sub("(?i)ctrl", "Command", key)
|
return re.sub("(?i)ctrl", "Command", key)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
isMac = sys.platform.startswith("darwin")
|
||||||
|
isWin = sys.platform.startswith("win32")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue