mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
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
This commit is contained in:
parent
b5df36f458
commit
dac9f0584b
5 changed files with 159 additions and 38 deletions
|
@ -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(
|
||||
|
|
|
@ -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 "<c>" 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
|
||||
######################################################################
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -211,7 +211,7 @@
|
|||
<addaction name="actionAddItems"/>
|
||||
<addaction name="actionAddCards"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionChangeGroup"/>
|
||||
<addaction name="actionSetGroup"/>
|
||||
<addaction name="actionAddTag"/>
|
||||
<addaction name="actionDeleteTag"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -267,7 +267,7 @@
|
|||
<addaction name="actionAddItems"/>
|
||||
<addaction name="actionAddCards"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionChangeGroup"/>
|
||||
<addaction name="actionSetGroup"/>
|
||||
<addaction name="actionAddTag"/>
|
||||
<addaction name="actionDeleteTag"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -549,13 +549,13 @@
|
|||
<string>Find &Duplicates...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionChangeGroup">
|
||||
<action name="actionSetGroup">
|
||||
<property name="icon">
|
||||
<iconset resource="icons.qrc">
|
||||
<normaloff>:/icons/stock_group.png</normaloff>:/icons/stock_group.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Change Group</string>
|
||||
<string>Set Group</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
|
|
113
designer/setgroup.ui
Normal file
113
designer/setgroup.ui
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>291</width>
|
||||
<height>188</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Anki</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="selGroup">
|
||||
<property name="text">
|
||||
<string>Move cards to chosen group:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="moveFacts">
|
||||
<property name="text">
|
||||
<string>Move facts too</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="factGroup">
|
||||
<property name="text">
|
||||
<string>Move cards to their fact's group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>224</x>
|
||||
<y>192</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>213</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>292</x>
|
||||
<y>198</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>213</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>selGroup</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>groupBox</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>188</x>
|
||||
<y>19</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>343</x>
|
||||
<y>53</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in a new issue