allow previewing of other templates when editing, include info on what's shown

This commit is contained in:
Damien Elmes 2010-12-25 08:46:45 +09:00
parent 3eca37d75c
commit d7971c33f6
2 changed files with 46 additions and 25 deletions

View file

@ -49,15 +49,21 @@ class CardLayout(QDialog):
sys.platform.startswith("win32")): sys.platform.startswith("win32")):
self.plastiqueStyle = QStyleFactory.create("plastique") self.plastiqueStyle = QStyleFactory.create("plastique")
if self.card: if self.card:
# limited to an existing card # limited to an existing templates
self.cards = [self.card] self.cards = [self.deck.s.query(Card).get(id) for id in
self.deck.s.column0(
"select id from cards where factId = :fid "
"order by ordinal", fid=self.fact.id)]
type = 0
else: else:
if factedit: if factedit:
# active & possible # active & possible
self.cards = self.deck.previewFact(self.fact) self.cards = self.deck.previewFact(self.fact)
type = 1
else: else:
# all # all
self.cards = self.deck.previewFact(self.fact, cms=self.model.cardModels) self.cards = self.deck.previewFact(self.fact, cms=self.model.cardModels)
type = 2
if not self.cards: if not self.cards:
ui.utils.showInfo(_( ui.utils.showInfo(_(
"Please enter some text first."), "Please enter some text first."),
@ -65,6 +71,15 @@ class CardLayout(QDialog):
return return
self.form = ankiqt.forms.clayout.Ui_Dialog() self.form = ankiqt.forms.clayout.Ui_Dialog()
self.form.setupUi(self) self.form.setupUi(self)
if type == 0:
self.form.templateType.setText(
_("Templates used by fact:"))
elif type == 1:
self.form.templateType.setText(
_("Templates that will be created:"))
else:
self.form.templateType.setText(
_("All templates:"))
# FIXME: add this # 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()"),
@ -205,12 +220,21 @@ order by n""", id=card.id)
def fillCardList(self): def fillCardList(self):
self.form.cardList.clear() self.form.cardList.clear()
cards = []
idx = 0
for n, c in enumerate(self.cards):
if c == self.card:
cards.append(_("%s (current)") % c.cardModel.name)
idx = n
else:
cards.append(c.cardModel.name)
self.form.cardList.addItems( self.form.cardList.addItems(
QStringList([c.cardModel.name for c in self.cards])) QStringList(cards))
if [self.card] == self.cards: self.form.editTemplates.setEnabled(False)
self.form.cardList.setEnabled(False) if idx != 0:
self.form.editTemplates.setEnabled(False) self.form.cardList.setCurrentIndex(idx)
self.cardChanged(0) self.cardChanged(idx)
self.form.cardList.setFocus()
def cardChanged(self, idx): def cardChanged(self, idx):
self.card = self.cards[idx] self.card = self.cards[idx]

View file

@ -40,7 +40,7 @@
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="1" column="1"> <item row="3" column="1">
<widget class="QTextEdit" name="cardQuestion"> <widget class="QTextEdit" name="cardQuestion">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -62,7 +62,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="4" column="1">
<widget class="QTextEdit" name="cardAnswer"> <widget class="QTextEdit" name="cardAnswer">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -87,17 +87,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Template</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QComboBox" name="cardList"> <widget class="QComboBox" name="cardList">
@ -118,7 +108,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0" rowspan="2"> <item row="3" column="0" rowspan="2">
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item> <item>
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="label_14">
@ -159,7 +149,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0"> <item row="5" column="0">
<widget class="QLabel" name="label_13"> <widget class="QLabel" name="label_13">
<property name="text"> <property name="text">
<string>Alignment</string> <string>Alignment</string>
@ -169,10 +159,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="5" column="1">
<widget class="QComboBox" name="alignment"/> <widget class="QComboBox" name="alignment"/>
</item> </item>
<item row="4" column="0"> <item row="6" column="0">
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="label_16">
<property name="text"> <property name="text">
<string>Background</string> <string>Background</string>
@ -182,7 +172,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="6" column="1">
<widget class="QPushButton" name="background"> <widget class="QPushButton" name="background">
<property name="text"> <property name="text">
<string/> <string/>
@ -192,6 +182,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="templateType">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>