From 5899b60b59db4f7648493b60081df328a7b6d68b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 29 Mar 2011 15:51:23 +0900 Subject: [PATCH] group conf startup --- aqt/groupconf.py | 122 ++++++++++++++++++++++--- aqt/groupconfsel.py | 60 ------------- aqt/groupman.py | 14 +-- designer/groupconf.ui | 190 +++++++++++++++++++++++++++++---------- designer/groupconfsel.ui | 4 +- 5 files changed, 261 insertions(+), 129 deletions(-) delete mode 100644 aqt/groupconfsel.py diff --git a/aqt/groupconf.py b/aqt/groupconf.py index dd84ddcbe..82ffa443e 100644 --- a/aqt/groupconf.py +++ b/aqt/groupconf.py @@ -4,36 +4,136 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * -import aqt +import aqt, simplejson +from aqt.utils import showInfo class GroupConf(QDialog): - def __init__(self, mw): - QDialog.__init__(self, mw) + def __init__(self, mw, gcid, parent=None): + QDialog.__init__(self, parent or mw) self.mw = mw + self.gcid = gcid self.form = aqt.forms.groupconf.Ui_Dialog() self.form.setupUi(self) + (self.name, self.conf) = self.mw.deck.db.first( + "select name, conf from gconf where id = ?", self.gcid) + self.conf = simplejson.loads(self.conf) + self.setWindowTitle(self.name) self.setupNew() self.setupLapse() self.setupRev() self.setupCram() self.setupGeneral() - self.connect(self.form.optionsHelpButton, - SIGNAL("clicked()"), + self.connect(self.form.buttonBox, + SIGNAL("helpRequested()"), lambda: QDesktopServices.openUrl(QUrl( - aqt.appWiki + "StudyOptions"))) + aqt.appWiki + "GroupOptions"))) self.exec_() + def listToUser(self, l): + return " ".join([str(x) for x in l]) + def setupNew(self): - pass + c = self.conf['new'] + f = self.form + f.lrnSteps.setText(self.listToUser(c['delays'])) + f.lrnGradInt.setValue(c['ints'][0]) + f.lrnEasyInt.setValue(c['ints'][2]) + f.lrnFirstInt.setValue(c['ints'][1]) + f.lrnFactor.setValue(c['initialFactor']) def setupLapse(self): - pass + c = self.conf['lapse'] + f = self.form + f.lapSteps.setText(self.listToUser(c['delays'])) + f.lapMult.setValue(c['mult']) + f.lapMinInt.setValue(c['minInt']) + f.leechThreshold.setValue(c['leechFails']) + f.leechAction.setCurrentIndex(c['leechAction'][0]) + f.lapRelearn.setChecked(c['relearn']) def setupRev(self): - pass + c = self.conf['rev'] + f = self.form + f.revSpace.setValue(c['fuzz']*100) + f.revMinSpace.setValue(c['minSpace']) + f.easyBonus.setValue(c['ease4']*100) def setupCram(self): - pass + c = self.conf['cram'] + f = self.form + f.cramSteps.setText(self.listToUser(c['delays'])) + f.cramBoost.setChecked(c['resched']) + f.cramReset.setChecked(c['reset']) + f.cramMult.setValue(c['mult']) + f.cramMinInt.setValue(c['minInt']) def setupGeneral(self): - pass + c = self.conf + f = self.form + f.maxTaken.setValue(c['maxTaken']) + +class GroupConfSelector(QDialog): + def __init__(self, mw, gids, parent=None): + QDialog.__init__(self, parent or mw) + self.mw = mw + self.gids = gids + self.form = aqt.forms.groupconfsel.Ui_Dialog() + self.form.setupUi(self) + self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"), + self.onRename) + self.reload() + self.addButtons() + self.exec_() + + def reload(self): + self.confs = self.mw.deck.groupConfs() + self.form.list.clear() + item1 = 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) + + def addButtons(self): + box = self.form.buttonBox + def button(name, func, type=QDialogButtonBox.ActionRole): + b = box.addButton(name, type) + b.connect(b, SIGNAL("clicked()"), func) + return b + button(_("Edit..."), self.onEdit).setShortcut("e") + button(_("Copy"), self.onCopy).setShortcut("c") + button(_("Delete"), self.onDelete) + + def gcid(self): + return self.confs[self.form.list.currentRow()][1] + + def onRename(self, item): + gcid = self.gcid() + self.mw.deck.db.execute("update gconf set name = ? where id = ?", + unicode(item.text()), gcid) + + def onEdit(self): + GroupConf(self.mw, self.gcid(), self) + + def onCopy(self): + gcid = self.gcid() + gc = list(self.mw.deck.db.first("select * from gconf where id = ?", gcid)) + gc[0] = self.mw.deck.nextID("gcid") + gc[2] = _("%s copy")%gc[2] + self.mw.deck.db.execute("insert into gconf values (?,?,?,?)", *gc) + self.reload() + + def onDelete(self): + gcid = self.gcid() + if gcid == 1: + showInfo(_("The default configuration can't be removed."), self) + else: + self.mw.deck.save(_("Delete Group Config")) + self.mw.deck.db.execute( + "update groups set gcid = 1 where gcid = ?", gcid) + self.mw.deck.db.execute( + "delete from gconf where id = ?", gcid) + self.reload() diff --git a/aqt/groupconfsel.py b/aqt/groupconfsel.py deleted file mode 100644 index bcce655a3..000000000 --- a/aqt/groupconfsel.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright: Damien Elmes -# -*- coding: utf-8 -*- -# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html - -from PyQt4.QtCore import * -from PyQt4.QtGui import * -import aqt -from aqt.utils import showInfo - -class GroupConfSelector(QDialog): - def __init__(self, mw, gids): - QDialog.__init__(self, mw) - self.mw = mw - self.gids = gids - self.form = aqt.forms.groupconfsel.Ui_Dialog() - self.form.setupUi(self) - self.load() - self.addButtons() - self.exec_() - - def load(self): - self.confs = self.mw.deck.groupConfs() - for c in self.confs: - item = QListWidgetItem(c[0]) - item.setFlags(item.flags() | Qt.ItemIsEditable) - self.form.list.addItem(item) - self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"), - self.onRename) - - def addButtons(self): - box = self.form.buttonBox - def button(name, func, type=QDialogButtonBox.ActionRole): - b = box.addButton(name, type) - b.connect(b, SIGNAL("clicked()"), func) - return b - button(_("Edit"), self.onEdit) - button(_("Copy"), self.onCopy) - button(_("Delete"), self.onDelete) - - def idx(self): - return self.form.list.currentRow() - - def onRename(self, item): - idx = self.idx() - id = self.confs[idx][1] - self.mw.deck.db.execute("update gconf set name = ? where id = ?", - unicode(item.text()), id) - - def onEdit(self): - pass - - def onCopy(self): - pass - - def onDelete(self): - idx = self.form.list.currentRow() - if self.confs[idx][1] == 1: - showInfo(_("The default configuration can't be removed.")) - return - diff --git a/aqt/groupman.py b/aqt/groupman.py index 3f9d42786..cd90d0ab7 100644 --- a/aqt/groupman.py +++ b/aqt/groupman.py @@ -54,13 +54,13 @@ class GroupManager(QDialog): b.connect(b, SIGNAL("clicked()"), func) return b # exits - button(_("&Study"), self.onStudy, QDialogButtonBox.AcceptRole) + b = button(_("&Study"), self.onStudy, QDialogButtonBox.AcceptRole) button(_("&Cram"), self.onCram, QDialogButtonBox.AcceptRole) # selection - button(_("Select &All"), self.onSelectAll) - button(_("Select &None"), self.onSelectNone) - button(_("&Rename..."), self.onRename) - button(_("&Config..."), self.onEdit) + button(_("Select &All"), self.onSelectAll).setShortcut("a") + button(_("Select &None"), self.onSelectNone).setShortcut("n") + button(_("&Rename..."), self.onRename).setShortcut("r") + b = button(_("&Options..."), self.onEdit).setShortcut("o") self.connect(box, SIGNAL("helpRequested()"), lambda: QDesktopServices.openUrl(QUrl( @@ -115,8 +115,8 @@ class GroupManager(QDialog): if gid: gids.append(gid) if gids: - from aqt.groupconfsel import GroupConfSelector - GroupConfSelector(self.mw, gids) + from aqt.groupconf import GroupConfSelector + GroupConfSelector(self.mw, gids, self) else: showInfo(_("None of the selected items are a group.")) diff --git a/designer/groupconf.ui b/designer/groupconf.ui index d9981fcd2..fe87e94de 100644 --- a/designer/groupconf.ui +++ b/designer/groupconf.ui @@ -14,7 +14,7 @@ - 0 + 4 @@ -87,9 +87,6 @@ - - - @@ -100,6 +97,26 @@ + + + + 130 + + + 1000 + + + 5 + + + + + + + % + + + @@ -137,17 +154,7 @@ - Interval multiplier - - - - - - - 1.000000000000000 - - - 0.050000000000000 + New interval @@ -243,6 +250,23 @@ + + + + % + + + + + + + 100 + + + 5 + + + @@ -275,7 +299,14 @@ - + + + 100 + + + 5 + + @@ -314,20 +345,26 @@ - x - - - - - - - 1 + % + + + + 100 + + + 1000 + + + 5 + + + @@ -365,17 +402,7 @@ - Lapse interval multiplier - - - - - - - 1.000000000000000 - - - 0.050000000000000 + New interval @@ -388,6 +415,9 @@ + + false + 1 @@ -407,18 +437,38 @@ + + + + false + + + 100 + + + 5 + + + + + + + days + + + - - - Qt::Horizontal + + + + 0 + 0 + - - - 40 - 20 - + + % - + @@ -452,7 +502,17 @@ - + + + 30 + + + 3600 + + + 10 + + @@ -525,8 +585,8 @@ accept() - 248 - 254 + 254 + 320 157 @@ -541,8 +601,8 @@ reject() - 316 - 260 + 322 + 320 286 @@ -550,5 +610,37 @@ + + cramReset + toggled(bool) + cramMult + setEnabled(bool) + + + 96 + 103 + + + 187 + 133 + + + + + cramReset + toggled(bool) + cramMinInt + setEnabled(bool) + + + 138 + 103 + + + 187 + 168 + + + diff --git a/designer/groupconfsel.ui b/designer/groupconfsel.ui index b0fcba20b..51a86129a 100644 --- a/designer/groupconfsel.ui +++ b/designer/groupconfsel.ui @@ -6,8 +6,8 @@ 0 0 - 573 - 377 + 421 + 188