mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
saving of state
This commit is contained in:
parent
783d8f2a5f
commit
ccf3e0ae0d
2 changed files with 42 additions and 8 deletions
|
@ -27,7 +27,7 @@ class GroupSel(QDialog):
|
||||||
self.mw.progress.start()
|
self.mw.progress.start()
|
||||||
grps = self.mw.deck.sched.groupCountTree()
|
grps = self.mw.deck.sched.groupCountTree()
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
self._groupMap = {}
|
self.groupMap = {}
|
||||||
items = self._makeItems(grps)
|
items = self._makeItems(grps)
|
||||||
self.form.tree.addTopLevelItems(items)
|
self.form.tree.addTopLevelItems(items)
|
||||||
# default to check column
|
# default to check column
|
||||||
|
@ -43,9 +43,13 @@ class GroupSel(QDialog):
|
||||||
|
|
||||||
def addButtons(self):
|
def addButtons(self):
|
||||||
box = self.form.buttonBox
|
box = self.form.buttonBox
|
||||||
def button(name, func):
|
def button(name, func, type=QDialogButtonBox.ActionRole):
|
||||||
b = box.addButton(name, QDialogButtonBox.ActionRole)
|
b = box.addButton(name, type)
|
||||||
b.connect(b, SIGNAL("clicked()"), func)
|
b.connect(b, SIGNAL("clicked()"), func)
|
||||||
|
# exits
|
||||||
|
button(_("&Study"), self.onStudy, QDialogButtonBox.AcceptRole)
|
||||||
|
button(_("&Cram"), self.onCram, QDialogButtonBox.AcceptRole)
|
||||||
|
# actions
|
||||||
button(_("Select &All"), self.onSelectAll)
|
button(_("Select &All"), self.onSelectAll)
|
||||||
button(_("Select &None"), self.onSelectNone)
|
button(_("Select &None"), self.onSelectNone)
|
||||||
button(_("&Edit..."), self.onEdit)
|
button(_("&Edit..."), self.onEdit)
|
||||||
|
@ -54,6 +58,12 @@ class GroupSel(QDialog):
|
||||||
lambda: QDesktopServices.openUrl(QUrl(
|
lambda: QDesktopServices.openUrl(QUrl(
|
||||||
aqt.appWiki + "GroupSelection")))
|
aqt.appWiki + "GroupSelection")))
|
||||||
|
|
||||||
|
def onStudy(self):
|
||||||
|
print "study"
|
||||||
|
|
||||||
|
def onCram(self):
|
||||||
|
print "cram"
|
||||||
|
|
||||||
def onSelectAll(self):
|
def onSelectAll(self):
|
||||||
for i in self.items:
|
for i in self.items:
|
||||||
i.setCheckState(COLCHECK, Qt.Checked)
|
i.setCheckState(COLCHECK, Qt.Checked)
|
||||||
|
@ -64,10 +74,31 @@ class GroupSel(QDialog):
|
||||||
|
|
||||||
def onEdit(self):
|
def onEdit(self):
|
||||||
item = self.form.tree.currentItem()
|
item = self.form.tree.currentItem()
|
||||||
gid = self._groupMap[unicode(item.text(0))]
|
gid = self.groupMap[unicode(item.text(0))]
|
||||||
print "edit", gid
|
|
||||||
|
def reject(self):
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
gids = []
|
||||||
|
def findEnabled(item):
|
||||||
|
if item.checkState(1) == Qt.Checked:
|
||||||
|
gid = self.groupMap[unicode(item.text(0))]
|
||||||
|
if gid:
|
||||||
|
gids.append(gid)
|
||||||
|
for i in range(item.childCount()):
|
||||||
|
findEnabled(item.child(i))
|
||||||
|
for item in self.items:
|
||||||
|
findEnabled(item)
|
||||||
|
if len(gids) == self.gidCount:
|
||||||
|
# all enabled is same as empty
|
||||||
|
gids = []
|
||||||
|
self.mw.deck.qconf['groups'] = gids
|
||||||
|
QDialog.accept(self)
|
||||||
|
|
||||||
def _makeItems(self, grps):
|
def _makeItems(self, grps):
|
||||||
|
self.gidCount = 0
|
||||||
|
on = {}
|
||||||
if not self.mw.deck.qconf['groups']:
|
if not self.mw.deck.qconf['groups']:
|
||||||
on = None
|
on = None
|
||||||
else:
|
else:
|
||||||
|
@ -78,7 +109,8 @@ class GroupSel(QDialog):
|
||||||
branch.setFlags(
|
branch.setFlags(
|
||||||
Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable|
|
Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable|
|
||||||
Qt.ItemIsTristate)
|
Qt.ItemIsTristate)
|
||||||
if not on or on[gid]:
|
gid = grp[1]
|
||||||
|
if not on or gid in on:
|
||||||
branch.setCheckState(1, Qt.Checked)
|
branch.setCheckState(1, Qt.Checked)
|
||||||
else:
|
else:
|
||||||
branch.setCheckState(1, Qt.Unchecked)
|
branch.setCheckState(1, Qt.Unchecked)
|
||||||
|
@ -86,7 +118,9 @@ class GroupSel(QDialog):
|
||||||
branch.setText(COLCOUNT, str(grp[2]))
|
branch.setText(COLCOUNT, str(grp[2]))
|
||||||
branch.setText(COLDUE, str(grp[3]))
|
branch.setText(COLDUE, str(grp[3]))
|
||||||
branch.setText(COLNEW, str(grp[4]))
|
branch.setText(COLNEW, str(grp[4]))
|
||||||
self._groupMap[grp[0]] = grp[1]
|
self.groupMap[grp[0]] = grp[1]
|
||||||
|
if grp[1]:
|
||||||
|
self.gidCount += 1
|
||||||
if grp[5]:
|
if grp[5]:
|
||||||
for c in grp[5]:
|
for c in grp[5]:
|
||||||
branch.addChild(makeItems(c))
|
branch.addChild(makeItems(c))
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue