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.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
import aqt, simplejson
|
import aqt, simplejson
|
||||||
|
from anki.utils import ids2str
|
||||||
from aqt.utils import showInfo, showWarning
|
from aqt.utils import showInfo, showWarning
|
||||||
|
|
||||||
# Configuration editing
|
# Configuration editing
|
||||||
|
@ -147,21 +148,33 @@ class GroupConfSelector(QDialog):
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"),
|
self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"),
|
||||||
self.onRename)
|
self.onRename)
|
||||||
|
self.defaultId = self.mw.deck.db.scalar(
|
||||||
|
"select gcid from groups where id = ?", self.gids[0])
|
||||||
self.reload()
|
self.reload()
|
||||||
self.addButtons()
|
self.addButtons()
|
||||||
self.exec_()
|
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):
|
def reload(self):
|
||||||
self.confs = self.mw.deck.groupConfs()
|
self.confs = self.mw.deck.groupConfs()
|
||||||
self.form.list.clear()
|
self.form.list.clear()
|
||||||
item1 = None
|
deflt = None
|
||||||
for c in self.confs:
|
for c in self.confs:
|
||||||
item = QListWidgetItem(c[0])
|
item = QListWidgetItem(c[0])
|
||||||
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||||
self.form.list.addItem(item)
|
self.form.list.addItem(item)
|
||||||
if not item1:
|
if c[1] == self.defaultId:
|
||||||
item1 = item
|
deflt = item
|
||||||
self.form.list.setCurrentItem(item1)
|
self.form.list.setCurrentItem(deflt)
|
||||||
|
|
||||||
def addButtons(self):
|
def addButtons(self):
|
||||||
box = self.form.buttonBox
|
box = self.form.buttonBox
|
||||||
|
|
|
@ -8,10 +8,11 @@ import aqt
|
||||||
from aqt.utils import showInfo, getOnlyText
|
from aqt.utils import showInfo, getOnlyText
|
||||||
|
|
||||||
COLNAME = 0
|
COLNAME = 0
|
||||||
COLCHECK = 1
|
COLOPTS = 1
|
||||||
COLCOUNT = 2
|
COLCHECK = 2
|
||||||
COLDUE = 3
|
COLCOUNT = 3
|
||||||
COLNEW = 4
|
COLDUE = 4
|
||||||
|
COLNEW = 5
|
||||||
GREY = "#777"
|
GREY = "#777"
|
||||||
|
|
||||||
class GroupManager(QDialog):
|
class GroupManager(QDialog):
|
||||||
|
@ -36,7 +37,7 @@ class GroupManager(QDialog):
|
||||||
self.items = items
|
self.items = items
|
||||||
self.form.tree.expandAll()
|
self.form.tree.expandAll()
|
||||||
# default to check column
|
# default to check column
|
||||||
self.form.tree.setCurrentItem(self.items[0], 1)
|
self.form.tree.setCurrentItem(self.items[0], COLCHECK)
|
||||||
|
|
||||||
def loadTable(self):
|
def loadTable(self):
|
||||||
self.reload()
|
self.reload()
|
||||||
|
@ -48,7 +49,7 @@ class GroupManager(QDialog):
|
||||||
self.form.tree.setIndentation(15)
|
self.form.tree.setIndentation(15)
|
||||||
|
|
||||||
def addButtons(self):
|
def addButtons(self):
|
||||||
box = self.form.buttonBox
|
box = self.form.buttonBox2
|
||||||
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)
|
||||||
|
@ -59,7 +60,7 @@ class GroupManager(QDialog):
|
||||||
b = button(_("&Options..."), self.onEdit).setShortcut("o")
|
b = button(_("&Options..."), self.onEdit).setShortcut("o")
|
||||||
button(_("&Rename..."), self.onRename).setShortcut("r")
|
button(_("&Rename..."), self.onRename).setShortcut("r")
|
||||||
button(_("&Delete"), self.onDelete)
|
button(_("&Delete"), self.onDelete)
|
||||||
self.connect(box,
|
self.connect(self.form.buttonBox1,
|
||||||
SIGNAL("helpRequested()"),
|
SIGNAL("helpRequested()"),
|
||||||
lambda: aqt.openHelp("GroupManager"))
|
lambda: aqt.openHelp("GroupManager"))
|
||||||
|
|
||||||
|
@ -118,8 +119,11 @@ class GroupManager(QDialog):
|
||||||
if gid:
|
if gid:
|
||||||
gids.append(gid)
|
gids.append(gid)
|
||||||
if gids:
|
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
|
from aqt.groupconf import GroupConfSelector
|
||||||
GroupConfSelector(self.mw, gids, self)
|
GroupConfSelector(self.mw, gids, self)
|
||||||
|
self.reload()
|
||||||
else:
|
else:
|
||||||
showInfo(_("None of the selected items are a group."))
|
showInfo(_("None of the selected items are a group."))
|
||||||
|
|
||||||
|
@ -154,6 +158,8 @@ class GroupManager(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
|
||||||
|
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))
|
grey = QBrush(QColor(GREY))
|
||||||
def makeItems(grp, head=""):
|
def makeItems(grp, head=""):
|
||||||
branch = QTreeWidgetItem()
|
branch = QTreeWidgetItem()
|
||||||
|
@ -162,12 +168,14 @@ class GroupManager(QDialog):
|
||||||
Qt.ItemIsTristate)
|
Qt.ItemIsTristate)
|
||||||
gid = grp[1]
|
gid = grp[1]
|
||||||
if not gid:
|
if not gid:
|
||||||
branch.setForeground(0, grey)
|
branch.setForeground(COLNAME, grey)
|
||||||
if not on or gid in on:
|
if not on or gid in on:
|
||||||
branch.setCheckState(1, Qt.Checked)
|
branch.setCheckState(COLCHECK, Qt.Checked)
|
||||||
else:
|
else:
|
||||||
branch.setCheckState(1, Qt.Unchecked)
|
branch.setCheckState(COLCHECK, Qt.Unchecked)
|
||||||
branch.setText(COLNAME, grp[0])
|
branch.setText(COLNAME, grp[0])
|
||||||
|
if gid:
|
||||||
|
branch.setText(COLOPTS, self.confMap[gid])
|
||||||
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]))
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Groups</string>
|
<string>Groups</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeWidget" name="tree">
|
<widget class="QTreeWidget" name="tree">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
|
@ -30,6 +30,11 @@
|
||||||
<string>Group</string>
|
<string>Group</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Options</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>On</string>
|
<string>On</string>
|
||||||
|
@ -53,9 +58,16 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<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">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||||
|
@ -67,7 +79,7 @@
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox1</sender>
|
||||||
<signal>accepted()</signal>
|
<signal>accepted()</signal>
|
||||||
<receiver>Dialog</receiver>
|
<receiver>Dialog</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
|
@ -83,7 +95,7 @@
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox1</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
<receiver>Dialog</receiver>
|
<receiver>Dialog</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
|
|
Loading…
Reference in a new issue