From 751a341f1b11d12bf1bb1f5f1fecc6d000f022a0 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 2 Dec 2010 04:14:02 +0900 Subject: [PATCH] add the ability to edit layouts from model properties --- ankiqt/ui/clayout.py | 35 ++++++++++++++++++++++++++--------- ankiqt/ui/facteditor.py | 2 +- ankiqt/ui/modelproperties.py | 5 +++++ designer/modelproperties.ui | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/ankiqt/ui/clayout.py b/ankiqt/ui/clayout.py index ea88c18e2..8229bf832 100644 --- a/ankiqt/ui/clayout.py +++ b/ankiqt/ui/clayout.py @@ -22,14 +22,27 @@ class ResizingTextEdit(QTextEdit): class CardLayout(QDialog): - def __init__(self, factedit, fact, card=None): - self.parent = factedit.parent - QDialog.__init__(self, self.parent, Qt.Window) - self.factedit = factedit + def __init__(self, parent, factedit, factOrModel, card=None): + self.parent = parent + QDialog.__init__(self, parent, Qt.Window) self.mw = ankiqt.mw self.deck = self.mw.deck - self.fact = fact - self.model = fact.model + self.factedit = factedit + 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.plastiqueStyle = None if (sys.platform.startswith("darwin") or @@ -39,8 +52,12 @@ class CardLayout(QDialog): # limited to an existing card self.cards = [self.card] else: - # active & possible - self.cards = self.deck.previewFact(self.fact) + if factedit: + # 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: ui.utils.showInfo(_( "Please enter some text first."), @@ -272,7 +289,7 @@ order by n""", id=card.id) if modified: self.fact.model.setModified() self.deck.flushMod() - if self.factedit.onChange: + if self.factedit and self.factedit.onChange: self.factedit.onChange("all") else: self.mw.reset() diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 9a2ff2bf6..b83904e55 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -804,7 +804,7 @@ class FactEditor(object): def onCardLayout(self): 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 # [sound] et al conflicts diff --git a/ankiqt/ui/modelproperties.py b/ankiqt/ui/modelproperties.py index 0f183dcda..2149c6532 100644 --- a/ankiqt/ui/modelproperties.py +++ b/ankiqt/ui/modelproperties.py @@ -63,6 +63,11 @@ class ModelProperties(QDialog): self.moveCardDown) self.connect(self.dialog.cardRename, SIGNAL("clicked()"), self.renameCard) + self.connect(self.dialog.cardLayout, SIGNAL("clicked()"), + self.cardLayout) + + def cardLayout(self): + ui.clayout.CardLayout(self, None, self.m) def renameCard(self): txt = ui.utils.getText(_("New name?"), parent=self) diff --git a/designer/modelproperties.ui b/designer/modelproperties.ui index 307a44cf1..65dfc41d6 100644 --- a/designer/modelproperties.ui +++ b/designer/modelproperties.ui @@ -146,6 +146,13 @@ + + + + Card &Layout + + + @@ -165,6 +172,19 @@ + + name + mediaURL + cardList + cardAdd + cardRename + cardUp + cardDown + cardToggle + cardDelete + cardLayout + buttonBox +