add the ability to edit layouts from model properties

This commit is contained in:
Damien Elmes 2010-12-02 04:14:02 +09:00
parent 4fa5c0d432
commit 751a341f1b
4 changed files with 52 additions and 10 deletions

View file

@ -22,14 +22,27 @@ class ResizingTextEdit(QTextEdit):
class CardLayout(QDialog): class CardLayout(QDialog):
def __init__(self, factedit, fact, card=None): def __init__(self, parent, factedit, factOrModel, card=None):
self.parent = factedit.parent self.parent = parent
QDialog.__init__(self, self.parent, Qt.Window) QDialog.__init__(self, parent, Qt.Window)
self.factedit = factedit
self.mw = ankiqt.mw self.mw = ankiqt.mw
self.deck = self.mw.deck self.deck = self.mw.deck
self.fact = fact self.factedit = factedit
self.model = fact.model if factedit:
self.fact = factOrModel
self.model = fact.model
else:
self.model = factOrModel
# see if there's an available fact
id = self.deck.s.scalar(
"select id from facts where modelId = :id", id=self.model.id)
if id:
self.fact = self.deck.s.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.card = card self.card = card
self.plastiqueStyle = None self.plastiqueStyle = None
if (sys.platform.startswith("darwin") or if (sys.platform.startswith("darwin") or
@ -39,8 +52,12 @@ class CardLayout(QDialog):
# limited to an existing card # limited to an existing card
self.cards = [self.card] self.cards = [self.card]
else: else:
# active & possible if factedit:
self.cards = self.deck.previewFact(self.fact) # active & possible
self.cards = self.deck.previewFact(self.fact)
else:
# all
self.cards = self.deck.previewFact(self.fact, cms=self.model.cardModels)
if not self.cards: if not self.cards:
ui.utils.showInfo(_( ui.utils.showInfo(_(
"Please enter some text first."), "Please enter some text first."),
@ -272,7 +289,7 @@ order by n""", id=card.id)
if modified: if modified:
self.fact.model.setModified() self.fact.model.setModified()
self.deck.flushMod() self.deck.flushMod()
if self.factedit.onChange: if self.factedit and self.factedit.onChange:
self.factedit.onChange("all") self.factedit.onChange("all")
else: else:
self.mw.reset() self.mw.reset()

View file

@ -804,7 +804,7 @@ class FactEditor(object):
def onCardLayout(self): def onCardLayout(self):
self.saveFields() self.saveFields()
ui.clayout.CardLayout(self, self.fact, self.card) ui.clayout.CardLayout(self.parent, self, self.fact, self.card)
# FIXME: in some future version, we should use a different delimiter, as # FIXME: in some future version, we should use a different delimiter, as
# [sound] et al conflicts # [sound] et al conflicts

View file

@ -63,6 +63,11 @@ class ModelProperties(QDialog):
self.moveCardDown) self.moveCardDown)
self.connect(self.dialog.cardRename, SIGNAL("clicked()"), self.connect(self.dialog.cardRename, SIGNAL("clicked()"),
self.renameCard) self.renameCard)
self.connect(self.dialog.cardLayout, SIGNAL("clicked()"),
self.cardLayout)
def cardLayout(self):
ui.clayout.CardLayout(self, None, self.m)
def renameCard(self): def renameCard(self):
txt = ui.utils.getText(_("New name?"), parent=self) txt = ui.utils.getText(_("New name?"), parent=self)

View file

@ -146,6 +146,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="cardLayout">
<property name="text">
<string>Card &amp;Layout</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@ -165,6 +172,19 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>name</tabstop>
<tabstop>mediaURL</tabstop>
<tabstop>cardList</tabstop>
<tabstop>cardAdd</tabstop>
<tabstop>cardRename</tabstop>
<tabstop>cardUp</tabstop>
<tabstop>cardDown</tabstop>
<tabstop>cardToggle</tabstop>
<tabstop>cardDelete</tabstop>
<tabstop>cardLayout</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>