mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
actually save gconf selection; refresh; show conf in list; use 2 bboxes
This commit is contained in:
parent
f48b3b27da
commit
e0582dee2f
3 changed files with 52 additions and 19 deletions
|
@ -5,6 +5,7 @@
|
|||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
import aqt, simplejson
|
||||
from anki.utils import ids2str
|
||||
from aqt.utils import showInfo, showWarning
|
||||
|
||||
# Configuration editing
|
||||
|
@ -147,21 +148,33 @@ class GroupConfSelector(QDialog):
|
|||
self.form.setupUi(self)
|
||||
self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"),
|
||||
self.onRename)
|
||||
self.defaultId = self.mw.deck.db.scalar(
|
||||
"select gcid from groups where id = ?", self.gids[0])
|
||||
self.reload()
|
||||
self.addButtons()
|
||||
self.exec_()
|
||||
|
||||
def accept(self):
|
||||
# save
|
||||
self.mw.deck.db.execute(
|
||||
"update groups set gcid = ? where id in "+ids2str(self.gids),
|
||||
self.gcid())
|
||||
QDialog.accept(self)
|
||||
|
||||
def reject(self):
|
||||
self.accept()
|
||||
|
||||
def reload(self):
|
||||
self.confs = self.mw.deck.groupConfs()
|
||||
self.form.list.clear()
|
||||
item1 = None
|
||||
deflt = None
|
||||
for c in self.confs:
|
||||
item = QListWidgetItem(c[0])
|
||||
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||
self.form.list.addItem(item)
|
||||
if not item1:
|
||||
item1 = item
|
||||
self.form.list.setCurrentItem(item1)
|
||||
if c[1] == self.defaultId:
|
||||
deflt = item
|
||||
self.form.list.setCurrentItem(deflt)
|
||||
|
||||
def addButtons(self):
|
||||
box = self.form.buttonBox
|
||||
|
|
|
@ -8,10 +8,11 @@ import aqt
|
|||
from aqt.utils import showInfo, getOnlyText
|
||||
|
||||
COLNAME = 0
|
||||
COLCHECK = 1
|
||||
COLCOUNT = 2
|
||||
COLDUE = 3
|
||||
COLNEW = 4
|
||||
COLOPTS = 1
|
||||
COLCHECK = 2
|
||||
COLCOUNT = 3
|
||||
COLDUE = 4
|
||||
COLNEW = 5
|
||||
GREY = "#777"
|
||||
|
||||
class GroupManager(QDialog):
|
||||
|
@ -36,7 +37,7 @@ class GroupManager(QDialog):
|
|||
self.items = items
|
||||
self.form.tree.expandAll()
|
||||
# default to check column
|
||||
self.form.tree.setCurrentItem(self.items[0], 1)
|
||||
self.form.tree.setCurrentItem(self.items[0], COLCHECK)
|
||||
|
||||
def loadTable(self):
|
||||
self.reload()
|
||||
|
@ -48,7 +49,7 @@ class GroupManager(QDialog):
|
|||
self.form.tree.setIndentation(15)
|
||||
|
||||
def addButtons(self):
|
||||
box = self.form.buttonBox
|
||||
box = self.form.buttonBox2
|
||||
def button(name, func, type=QDialogButtonBox.ActionRole):
|
||||
b = box.addButton(name, type)
|
||||
b.connect(b, SIGNAL("clicked()"), func)
|
||||
|
@ -59,7 +60,7 @@ class GroupManager(QDialog):
|
|||
b = button(_("&Options..."), self.onEdit).setShortcut("o")
|
||||
button(_("&Rename..."), self.onRename).setShortcut("r")
|
||||
button(_("&Delete"), self.onDelete)
|
||||
self.connect(box,
|
||||
self.connect(self.form.buttonBox1,
|
||||
SIGNAL("helpRequested()"),
|
||||
lambda: aqt.openHelp("GroupManager"))
|
||||
|
||||
|
@ -118,8 +119,11 @@ class GroupManager(QDialog):
|
|||
if gid:
|
||||
gids.append(gid)
|
||||
if gids:
|
||||
# this gets set on reload; do it in the background so it doesn't flicker
|
||||
self.form.tree.setCurrentItem(self.items[0], COLCHECK)
|
||||
from aqt.groupconf import GroupConfSelector
|
||||
GroupConfSelector(self.mw, gids, self)
|
||||
self.reload()
|
||||
else:
|
||||
showInfo(_("None of the selected items are a group."))
|
||||
|
||||
|
@ -154,6 +158,8 @@ class GroupManager(QDialog):
|
|||
else:
|
||||
for gid in self.mw.deck.qconf['groups']:
|
||||
on[gid] = True
|
||||
self.confMap = dict(self.mw.deck.db.all(
|
||||
"select g.id, gc.name from groups g, gconf gc where g.gcid=gc.id"))
|
||||
grey = QBrush(QColor(GREY))
|
||||
def makeItems(grp, head=""):
|
||||
branch = QTreeWidgetItem()
|
||||
|
@ -162,12 +168,14 @@ class GroupManager(QDialog):
|
|||
Qt.ItemIsTristate)
|
||||
gid = grp[1]
|
||||
if not gid:
|
||||
branch.setForeground(0, grey)
|
||||
branch.setForeground(COLNAME, grey)
|
||||
if not on or gid in on:
|
||||
branch.setCheckState(1, Qt.Checked)
|
||||
branch.setCheckState(COLCHECK, Qt.Checked)
|
||||
else:
|
||||
branch.setCheckState(1, Qt.Unchecked)
|
||||
branch.setCheckState(COLCHECK, Qt.Unchecked)
|
||||
branch.setText(COLNAME, grp[0])
|
||||
if gid:
|
||||
branch.setText(COLOPTS, self.confMap[gid])
|
||||
branch.setText(COLCOUNT, str(grp[2]))
|
||||
branch.setText(COLDUE, str(grp[3]))
|
||||
branch.setText(COLNEW, str(grp[4]))
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<property name="windowTitle">
|
||||
<string>Groups</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="tree">
|
||||
<property name="alternatingRowColors">
|
||||
|
@ -30,6 +30,11 @@
|
|||
<string>Group</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
|
@ -53,9 +58,16 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<widget class="QDialogButtonBox" name="buttonBox2">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::NoButton</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox1">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
|
@ -67,7 +79,7 @@
|
|||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<sender>buttonBox1</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
|
@ -83,7 +95,7 @@
|
|||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<sender>buttonBox1</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
|
|
Loading…
Reference in a new issue