mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
use checkmarks instead of multi selection so we don't lose keyboard focus
This commit is contained in:
parent
c8aafa7edf
commit
783d8f2a5f
2 changed files with 61 additions and 31 deletions
|
@ -6,29 +6,34 @@ from PyQt4.QtCore import *
|
|||
from PyQt4.QtGui import *
|
||||
import aqt
|
||||
|
||||
COLNAME = 0
|
||||
COLCHECK = 1
|
||||
COLCOUNT = 2
|
||||
COLDUE = 3
|
||||
COLNEW = 4
|
||||
|
||||
class GroupSel(QDialog):
|
||||
def __init__(self, mw):
|
||||
QDialog.__init__(self, mw)
|
||||
self.mw = mw
|
||||
self.form = aqt.forms.groupsel.Ui_Dialog()
|
||||
self.form.setupUi(self)
|
||||
self.load()
|
||||
# self.connect(self.form.optionsHelpButton,
|
||||
# SIGNAL("clicked()"),
|
||||
# lambda: QDesktopServices.openUrl(QUrl(
|
||||
# aqt.appWiki + "StudyOptions")))
|
||||
self.loadTable()
|
||||
self.addButtons()
|
||||
self.exec_()
|
||||
|
||||
def load(self):
|
||||
import time
|
||||
def loadTable(self):
|
||||
# load the data into the tree
|
||||
self.mw.progress.start()
|
||||
grps = self.mw.deck.sched.groupCountTree()
|
||||
self.mw.progress.finish()
|
||||
self._groupMap = {}
|
||||
items = self._makeItems(grps)
|
||||
self.form.tree.addTopLevelItems(items)
|
||||
for item in items:
|
||||
self._addButtons(item)
|
||||
# default to check column
|
||||
self.form.tree.setCurrentItem(items[0], 1)
|
||||
self.items = items
|
||||
# config tree
|
||||
h = self.form.tree.header()
|
||||
h.setResizeMode(QHeaderView.ResizeToContents)
|
||||
h.setResizeMode(0, QHeaderView.Stretch)
|
||||
|
@ -36,26 +41,51 @@ class GroupSel(QDialog):
|
|||
self.form.tree.setIndentation(15)
|
||||
self.form.tree.expandAll()
|
||||
|
||||
def _addButtons(self, item):
|
||||
gid = self._groupMap[unicode(item.text(0))]
|
||||
if gid:
|
||||
b = QPushButton("Edit")
|
||||
b.setFixedHeight(20)
|
||||
b.connect(b, SIGNAL("clicked()"), lambda g=gid: self._edit(gid))
|
||||
self.form.tree.setItemWidget(item, 4, b)
|
||||
for i in range(item.childCount()):
|
||||
self._addButtons(item.child(i))
|
||||
def addButtons(self):
|
||||
box = self.form.buttonBox
|
||||
def button(name, func):
|
||||
b = box.addButton(name, QDialogButtonBox.ActionRole)
|
||||
b.connect(b, SIGNAL("clicked()"), func)
|
||||
button(_("Select &All"), self.onSelectAll)
|
||||
button(_("Select &None"), self.onSelectNone)
|
||||
button(_("&Edit..."), self.onEdit)
|
||||
self.connect(box,
|
||||
SIGNAL("helpRequested()"),
|
||||
lambda: QDesktopServices.openUrl(QUrl(
|
||||
aqt.appWiki + "GroupSelection")))
|
||||
|
||||
def _edit(self, gid):
|
||||
def onSelectAll(self):
|
||||
for i in self.items:
|
||||
i.setCheckState(COLCHECK, Qt.Checked)
|
||||
|
||||
def onSelectNone(self):
|
||||
for i in self.items:
|
||||
i.setCheckState(COLCHECK, Qt.Unchecked)
|
||||
|
||||
def onEdit(self):
|
||||
item = self.form.tree.currentItem()
|
||||
gid = self._groupMap[unicode(item.text(0))]
|
||||
print "edit", gid
|
||||
|
||||
def _makeItems(self, grps):
|
||||
if not self.mw.deck.qconf['groups']:
|
||||
on = None
|
||||
else:
|
||||
for gid in self.mw.deck.qconf['groups']:
|
||||
on[gid] = True
|
||||
def makeItems(grp):
|
||||
branch = QTreeWidgetItem()
|
||||
branch.setText(0, grp[0])
|
||||
branch.setText(1, str(grp[2]))
|
||||
branch.setText(2, str(grp[3]))
|
||||
branch.setText(3, str(grp[4]))
|
||||
branch.setFlags(
|
||||
Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable|
|
||||
Qt.ItemIsTristate)
|
||||
if not on or on[gid]:
|
||||
branch.setCheckState(1, Qt.Checked)
|
||||
else:
|
||||
branch.setCheckState(1, Qt.Unchecked)
|
||||
branch.setText(COLNAME, grp[0])
|
||||
branch.setText(COLCOUNT, str(grp[2]))
|
||||
branch.setText(COLDUE, str(grp[3]))
|
||||
branch.setText(COLNEW, str(grp[4]))
|
||||
self._groupMap[grp[0]] = grp[1]
|
||||
if grp[5]:
|
||||
for c in grp[5]:
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="tree">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
|
@ -27,6 +27,11 @@
|
|||
<string>Group</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Cards</string>
|
||||
|
@ -42,11 +47,6 @@
|
|||
<string>New</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Actions</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -55,7 +55,7 @@
|
|||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue