show non-groups in grey, disable edit button when on non-group

This commit is contained in:
Damien Elmes 2011-03-29 12:59:23 +09:00
parent 9d12bc54b9
commit 7510c17245
2 changed files with 22 additions and 2 deletions

View file

@ -11,6 +11,7 @@ COLCHECK = 1
COLCOUNT = 2 COLCOUNT = 2
COLDUE = 3 COLDUE = 3
COLNEW = 4 COLNEW = 4
GREY = "#777"
class GroupSel(QDialog): class GroupSel(QDialog):
def __init__(self, mw): def __init__(self, mw):
@ -46,18 +47,29 @@ class GroupSel(QDialog):
def button(name, func, type=QDialogButtonBox.ActionRole): def button(name, func, type=QDialogButtonBox.ActionRole):
b = box.addButton(name, type) b = box.addButton(name, type)
b.connect(b, SIGNAL("clicked()"), func) b.connect(b, SIGNAL("clicked()"), func)
return b
# exits # exits
button(_("&Study"), self.onStudy, QDialogButtonBox.AcceptRole) button(_("&Study"), self.onStudy, QDialogButtonBox.AcceptRole)
button(_("&Cram"), self.onCram, QDialogButtonBox.AcceptRole) button(_("&Cram"), self.onCram, QDialogButtonBox.AcceptRole)
# actions # selection
button(_("Select &All"), self.onSelectAll) button(_("Select &All"), self.onSelectAll)
button(_("Select &None"), self.onSelectNone) button(_("Select &None"), self.onSelectNone)
button(_("&Edit..."), self.onEdit) # edit can only be active if current item has a gid
self.editButton = button(_("&Edit..."), self.onEdit)
self.connect(self.form.tree, SIGNAL(
"currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)"),
self.onChange)
self.connect(box, self.connect(box,
SIGNAL("helpRequested()"), SIGNAL("helpRequested()"),
lambda: QDesktopServices.openUrl(QUrl( lambda: QDesktopServices.openUrl(QUrl(
aqt.appWiki + "GroupSelection"))) aqt.appWiki + "GroupSelection")))
def onChange(self, new, old):
if self.groupMap[unicode(new.text(0))]:
self.editButton.setEnabled(True)
else:
self.editButton.setEnabled(False)
def onStudy(self): def onStudy(self):
self.mw.deck.reset() self.mw.deck.reset()
self.mw.moveToState("review") self.mw.moveToState("review")
@ -77,6 +89,8 @@ 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))]
from aqt.groupconf import GroupConf
GroupConf(self.mw, gid)
def reject(self): def reject(self):
self.accept() self.accept()
@ -106,12 +120,15 @@ class GroupSel(QDialog):
else: else:
for gid in self.mw.deck.qconf['groups']: for gid in self.mw.deck.qconf['groups']:
on[gid] = True on[gid] = True
grey = QBrush(QColor(GREY))
def makeItems(grp): def makeItems(grp):
branch = QTreeWidgetItem() branch = QTreeWidgetItem()
branch.setFlags( branch.setFlags(
Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable| Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable|
Qt.ItemIsTristate) Qt.ItemIsTristate)
gid = grp[1] gid = grp[1]
if not gid:
branch.setForeground(0, grey)
if not on or gid in on: if not on or gid in on:
branch.setCheckState(1, Qt.Checked) branch.setCheckState(1, Qt.Checked)
else: else:

View file

@ -19,6 +19,9 @@
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<attribute name="headerStretchLastSection"> <attribute name="headerStretchLastSection">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>