From dac9f0584b06c7102268462b01abc6cfaffec535 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 18 Apr 2011 05:22:14 +0900 Subject: [PATCH] group improvements - set groups now supports setting cards from fact - editor doesn't set cards when fact group is changed - card group and fact group can be displayed separately - window title doesn't bother to calculate total card count --- aqt/addcards.py | 2 +- aqt/browser.py | 65 +++++++++++++------------ aqt/editor.py | 9 ++-- designer/browser.ui | 8 +-- designer/setgroup.ui | 113 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+), 38 deletions(-) create mode 100644 designer/setgroup.ui diff --git a/aqt/addcards.py b/aqt/addcards.py index 0b4b3c197..9a43136c7 100644 --- a/aqt/addcards.py +++ b/aqt/addcards.py @@ -44,7 +44,7 @@ class AddCards(QDialog): print "focus lost" def setupEditor(self): - self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea) + self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, True) def setupChooser(self): self.modelChooser = aqt.modelchooser.ModelChooser( diff --git a/aqt/browser.py b/aqt/browser.py index 9c8d2787a..f76339cfa 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -226,8 +226,10 @@ class DeckModel(QAbstractTableModel): if c.type == 0: return _("(new)") return "%d%%" % (c.factor/10) - elif type == "group": + elif type == "cardGroup": return self.browser.mw.deck.groupName(c.gid) + elif type == "factGroup": + return self.browser.mw.deck.groupName(c.fact().gid) # def limitContent(self, txt): # if "" in txt: @@ -336,7 +338,7 @@ class Browser(QMainWindow): c = self.connect; f = self.form; s = SIGNAL("triggered()") c(f.actionAddItems, s, self.mw.onAddCard) c(f.actionDelete, s, self.deleteCards) - c(f.actionChangeGroup, s, self.changeGroup) + c(f.actionSetGroup, s, self.setGroup) c(f.actionAddTag, s, self.addTags) c(f.actionDeleteTag, s, self.deleteTags) c(f.actionReschedule, s, self.reschedule) @@ -400,7 +402,8 @@ class Browser(QMainWindow): ('question', _("Question")), ('answer', _("Answer")), ('template', _("Card")), - ('group', _("Group")), + ('cardGroup', _("Card Group")), + ('factGroup', _("Fact Group")), ('factFld', _("Sort Field")), ('factCrt', _("Created")), ('factMod', _("Edited")), @@ -454,12 +457,11 @@ class Browser(QMainWindow): def updateTitle(self): selected = len(self.form.tableView.selectionModel().selectedRows()) - self.setWindowTitle(ngettext("Browser (%(cur)d " - "card shown; %(sel)s)", "Browser (%(cur)d " - "cards shown; %(sel)s)", - self.deck.cardCount) % { - "cur": len(self.model.cards), - "tot": self.deck.cardCount(), + cur = len(self.model.cards) + self.setWindowTitle(ngettext("Browser (%(cur)d card shown; %(sel)s)", + "Browser (%(cur)d cards shown; %(sel)s)", + cur) % { + "cur": cur, "sel": ngettext("%d selected", "%d selected", selected) % selected } + " - " + self.deck.name()) return selected @@ -527,9 +529,10 @@ class Browser(QMainWindow): def onSortChanged(self, idx, ord): type = self.model.activeCols[idx] - noSort = ("question", "answer", "template", "group") + noSort = ("question", "answer", "template", "cardGroup", "factGroup") if type in noSort: - showInfo(_("Please choose a different column to sort by.")) + showInfo(_("Sorting on this column is not supported. Please " + "choose another.")) type = self.deck.conf['sortType'] if self.deck.conf['sortType'] != type: self.deck.conf['sortType'] = type @@ -793,37 +796,39 @@ where id in %s""" % ids2str(sf)) # Group change ###################################################################### - def changeGroup(self): + def setGroup(self): d = QDialog(self) d.setWindowModality(Qt.WindowModal) - l = QVBoxLayout() - d.setLayout(l) - lab = QLabel(_("Put cards in group:")) - l.addWidget(lab) + frm = aqt.forms.setgroup.Ui_Dialog() + frm.setupUi(d) from aqt.tagedit import TagEdit te = TagEdit(d, type=1) - l.addWidget(te) + frm.groupBox.layout().insertWidget(0, te) te.setDeck(self.deck) - cf = QCheckBox(_("Change facts too")) - l.addWidget(cf) - bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) - bb.connect(bb, SIGNAL("accepted()"), d, SLOT("accept()")) - bb.connect(bb, SIGNAL("rejected()"), d, SLOT("reject()")) - l.addWidget(bb) - if d.exec_(): + d.connect(d, SIGNAL("accepted()"), lambda: self.onSetGroup(frm, te)) + d.show() + te.setFocus() + + def onSetGroup(self, frm, te): + self.model.beginReset() + self.mw.checkpoint(_("Set Group")) + if frm.selGroup.isChecked(): gid = self.deck.groupId(unicode(te.text())) - self.model.beginReset() - self.mw.checkpoint(_("Set Group")) self.deck.db.execute( "update cards set gid = ? where id in " + ids2str( self.selectedCards()), gid) - if cf.isChecked(): + if frm.moveFacts.isChecked(): self.deck.db.execute( "update facts set gid = ? where id in " + ids2str( self.selectedFacts()), gid) - self.onSearch(reset=False) - self.mw.requireReset() - self.model.endReset() + else: + print "updating cards" + self.deck.db.execute(""" +update cards set gid = (select gid from facts where id = cards.fid) +where id in %s""" % ids2str(self.selectedCards())) + self.onSearch(reset=False) + self.mw.requireReset() + self.model.endReset() # Tags ###################################################################### diff --git a/aqt/editor.py b/aqt/editor.py index f77578466..e7f278b4d 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -187,11 +187,12 @@ $(function () { # caller is responsible for resetting fact on reset class Editor(object): - def __init__(self, mw, widget): + def __init__(self, mw, widget, editableGroup=False): self.widget = widget self.mw = mw self.fact = None self.stealFocus = True + self.editableGroup = editableGroup self._loaded = False self._keepButtons = False # current card, for card layout @@ -465,7 +466,10 @@ class Editor(object): tb.setSpacing(12) tb.setMargin(6) # group - l = QLabel(_("Group")) + if self.editableGroup: + l = QLabel(_("Group")) + else: + l = QLabel(_("Fact Group")) tb.addWidget(l, 0, 0) self.group = aqt.tagedit.TagEdit(self.widget, type=1) self.group.connect(self.group, SIGNAL("lostFocus"), @@ -496,7 +500,6 @@ class Editor(object): if not self.fact: return self.fact.gid = self.mw.deck.groupId(unicode(self.group.text())) - self.fact.updateCardGids() self.fact.tags = parseTags(unicode(self.tags.text())) self.fact.flush() runHook("tagsAndGroupUpdated", self.fact) diff --git a/designer/browser.ui b/designer/browser.ui index d5ba216fb..6b487de86 100644 --- a/designer/browser.ui +++ b/designer/browser.ui @@ -211,7 +211,7 @@ - + @@ -267,7 +267,7 @@ - + @@ -549,13 +549,13 @@ Find &Duplicates... - + :/icons/stock_group.png:/icons/stock_group.png - Change Group + Set Group Ctrl+G diff --git a/designer/setgroup.ui b/designer/setgroup.ui new file mode 100644 index 000000000..a14a689b8 --- /dev/null +++ b/designer/setgroup.ui @@ -0,0 +1,113 @@ + + + Dialog + + + + 0 + 0 + 291 + 188 + + + + Anki + + + + + + Move cards to chosen group: + + + true + + + + + + + + + + + + + Move facts too + + + + + + + + + + Move cards to their fact's group + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 224 + 192 + + + 157 + 213 + + + + + buttonBox + rejected() + Dialog + reject() + + + 292 + 198 + + + 286 + 213 + + + + + selGroup + toggled(bool) + groupBox + setEnabled(bool) + + + 188 + 19 + + + 343 + 53 + + + + +