move collection options into preferences

This commit is contained in:
Damien Elmes 2011-12-10 23:41:33 +09:00
parent d3acebe395
commit 569b903cdc
8 changed files with 185 additions and 250 deletions

View file

@ -7,7 +7,6 @@ import aqt, simplejson
from anki.utils import ids2str
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
from operator import itemgetter
import datetime, time
class DeckConf(QDialog):
def __init__(self, mw):
@ -27,7 +26,6 @@ class DeckConf(QDialog):
SIGNAL("clicked()"),
self.onRestore)
self.setupCombos()
self.setupCollection()
self.setWindowTitle(_("Options for %s") % self.deck['name'])
self.exec_()
@ -36,7 +34,6 @@ class DeckConf(QDialog):
f = self.form
f.newOrder.addItems(cs.newCardOrderLabels().values())
f.revOrder.addItems(cs.revCardOrderLabels().values())
f.newSpread.addItems(cs.newCardSchedulingLabels().values())
self.connect(f.newOrder, SIGNAL("currentIndexChanged(int)"),
self.onNewOrderChanged)
@ -111,32 +108,6 @@ class DeckConf(QDialog):
self.conf['name'] = name
self.loadConfs()
# Collection options
######################################################################
def setupCollection(self):
import anki.consts as c
f = self.form
qc = self.mw.col.conf
self.startDate = datetime.datetime.fromtimestamp(self.mw.col.crt)
f.dayOffset.setValue(self.startDate.hour)
f.lrnCutoff.setValue(qc['collapseTime']/60.0)
f.newSpread.setCurrentIndex(qc['newSpread'])
f.timeLimit.setValue(qc['timeLim']/60.0)
def saveCollection(self):
f = self.form
d = self.mw.col
qc = d.conf
qc['newSpread'] = f.newSpread.currentIndex()
qc['timeLim'] = f.timeLimit.value()*60
qc['collapseTime'] = f.lrnCutoff.value()*60
hrs = f.dayOffset.value()
old = self.startDate
date = datetime.datetime(
old.year, old.month, old.day, hrs)
d.crt = int(time.mktime(date.timetuple()))
# Loading
##################################################
@ -174,6 +145,7 @@ class DeckConf(QDialog):
# general
c = self.conf
f.maxTaken.setValue(c['maxTaken'])
f.autoplaySounds.setChecked(c['autoplay'])
def onRestore(self):
self.mw.col.decks.restoreToDefault(self.conf)
@ -181,7 +153,6 @@ class DeckConf(QDialog):
f = self.form
f.dayOffset.setValue(4)
f.lrnCutoff.setValue(20)
f.newSpread.setCurrentIndex(0)
f.timeLimit.setValue(0)
# New order
@ -244,16 +215,13 @@ class DeckConf(QDialog):
# general
c = self.conf
c['maxTaken'] = f.maxTaken.value()
c['autoplay'] = f.autoplaySounds.isChecked()
self.mw.col.decks.save(self.conf)
#make sure to save() deck and conf (on saveConf())
def reject(self):
self.accept()
def accept(self):
self.saveCollection()
self.saveConf()
self.mw.reset()
QDialog.accept(self)

View file

@ -125,7 +125,7 @@ button { font-weight: bold; }
def _renderBottom(self):
links = [
["opts", _("Options")],
["opts", _("Study Options")],
["cram", _("Cram")],
]
buf = ""

View file

@ -2,7 +2,7 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import datetime, time, os
from aqt.qt import *
from anki.lang import langs
from aqt.utils import openFolder, showWarning, getText
@ -18,6 +18,7 @@ class Preferences(QDialog):
self.form.setupUi(self)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
lambda: openHelp("Preferences"))
self.setupCollection()
self.setupLang()
self.setupNetwork()
self.setupBackup()
@ -25,6 +26,7 @@ class Preferences(QDialog):
self.show()
def accept(self):
self.updateCollection()
self.updateNetwork()
self.updateBackup()
self.updateOptions()
@ -35,6 +37,38 @@ class Preferences(QDialog):
def reject(self):
self.accept()
# Collection options
######################################################################
def setupCollection(self):
import anki.consts as c
f = self.form
qc = self.mw.col.conf
self.startDate = datetime.datetime.fromtimestamp(self.mw.col.crt)
f.dayOffset.setValue(self.startDate.hour)
f.lrnCutoff.setValue(qc['collapseTime']/60.0)
f.timeLimit.setValue(qc['timeLim']/60.0)
f.showEstimates.setChecked(qc['estTimes'])
f.showProgress.setChecked(qc['dueCounts'])
f.newSpread.addItems(c.newCardSchedulingLabels().values())
f.newSpread.setCurrentIndex(qc['newSpread'])
def updateCollection(self):
f = self.form
d = self.mw.col
qc = d.conf
qc['dueCounts'] = f.showProgress.isChecked()
qc['estTimes'] = f.showEstimates.isChecked()
qc['newSpread'] = f.newSpread.currentIndex()
qc['timeLim'] = f.timeLimit.value()*60
qc['collapseTime'] = f.lrnCutoff.value()*60
hrs = f.dayOffset.value()
old = self.startDate
date = datetime.datetime(
old.year, old.month, old.day, hrs)
d.crt = int(time.mktime(date.timetuple()))
d.setMod()
# Language handling
######################################################################
@ -74,6 +108,9 @@ class Preferences(QDialog):
self.prof['syncMedia'])
if not self.prof['syncKey']:
self.form.syncDeauth.setShown(False)
self.form.syncLabel.setText(_("""\
<b>Synchronization</b><br>
Not currently enabled; click the sync button in the main window to enable."""))
else:
self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
self.onSyncDeauth)
@ -112,21 +149,14 @@ class Preferences(QDialog):
######################################################################
def setupOptions(self):
self.form.showEstimates.setChecked(self.prof['showDueTimes'])
self.form.showProgress.setChecked(self.prof['showProgress'])
self.form.deleteMedia.setChecked(self.prof['deleteMedia'])
self.form.stripHTML.setChecked(self.prof['stripHTML'])
self.form.autoplaySounds.setChecked(self.prof['autoplay'])
self.connect(
self.form.profilePass, SIGNAL("clicked()"),
self.onProfilePass)
def updateOptions(self):
self.prof['showDueTimes'] = self.form.showEstimates.isChecked()
self.prof['showProgress'] = self.form.showProgress.isChecked()
self.prof['stripHTML'] = self.form.stripHTML.isChecked()
self.prof['autoplay'] = self.form.autoplaySounds.isChecked()
self.prof['deleteMedia'] = self.form.deleteMedia.isChecked()
self.prof['deleteMedia'] = self.form.deleteMedia.isChecked()
def onProfilePass(self):

View file

@ -46,11 +46,6 @@ profileConf = dict(
deleteMedia=False,
preserveKeyboard=True,
# reviewing
autoplay=True,
showDueTimes=True,
showProgress=True,
# syncing
syncKey=None,
syncMedia=True,

View file

@ -124,7 +124,7 @@ function _typeAnsPress() {
c = self.card
# grab the question and play audio
q = c.q()
if self.mw.pm.profile['autoplay']:
if self.mw.col.decks.conf(self.card.did)['autoplay']:
playFromText(q)
# render & update bottom
q = self._mungeQA(q)
@ -144,7 +144,7 @@ function _typeAnsPress() {
c = self.card
a = c.a()
# play audio?
if self.mw.pm.profile['autoplay']:
if self.mw.col.decks.conf(self.card.did)['autoplay']:
playFromText(a)
# render and update bottom
a = self._mungeQA(a)
@ -408,6 +408,8 @@ var updateTime = function () {
self.bottom._css + self._bottomCSS)
def _remaining(self):
if not self.mw.col.conf['dueCounts']:
return ""
counts = list(self.mw.col.sched.counts(self.card))
idx = self.mw.col.sched.countIdx(self.card)
counts[idx] = "<u>%s</u>" % (counts[idx])
@ -449,7 +451,7 @@ var updateTime = function () {
return buf + script
def _buttonTime(self, i, green):
if not self.mw.pm.profile['showDueTimes']:
if not self.mw.col.conf['estTimes']:
return "<div class=spacer></div>"
txt = self.mw.col.sched.nextIvlStr(self.card, i+1, True)
return '<span class=nobold>%s</span><br>' % txt

View file

@ -46,11 +46,8 @@ class Upgrader(object):
for k in (
"recentColours", "stripHTML", "editFontFamily", "editFontSize",
"editLineSize", "deleteMedia", "preserveKeyboard", "numBackups",
"proxyHost", "proxyPass", "proxyPort", "proxyUser",
"showProgress"):
"proxyHost", "proxyPass", "proxyPort", "proxyUser"):
p[k] = self.conf[k]
p['autoplay'] = self.conf['autoplaySounds']
p['showDueTimes'] = not self.conf['suppressEstimates']
self.mw.pm.save()
# Wizard

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>437</height>
<height>438</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -555,91 +555,12 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_22">
<widget class="QCheckBox" name="autoplaySounds">
<property name="text">
<string>&lt;b&gt;Collection Options&lt;/b&gt;&lt;br&gt;The settings below are shared between all decks.</string>
<string>Automatically play audio</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="newSpread"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Next day starts at</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="dayOffset">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>23</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Learn ahead limit</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="lrnCutoff">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_29">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_30">
<property name="text">
<string>Timebox time limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="timeLimit">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_39">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_40">
<property name="text">
<string>hours past midnight</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
@ -693,10 +614,7 @@
<tabstop>leechThreshold</tabstop>
<tabstop>leechAction</tabstop>
<tabstop>maxTaken</tabstop>
<tabstop>newSpread</tabstop>
<tabstop>dayOffset</tabstop>
<tabstop>lrnCutoff</tabstop>
<tabstop>timeLimit</tabstop>
<tabstop>autoplaySounds</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>461</width>
<height>442</height>
<width>439</width>
<height>420</height>
</rect>
</property>
<property name="windowTitle">
@ -28,15 +28,14 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
<number>12</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;b&gt;Language&lt;/b&gt;</string>
</property>
<property name="wordWrap">
<bool>false</bool>
<string>Language:</string>
</property>
</widget>
</item>
@ -50,25 +49,7 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;b&gt;Reviewing&lt;/b&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoplaySounds">
<property name="text">
<string>Automatically play audio</string>
</property>
</widget>
</layout>
</item>
<item>
<widget class="QCheckBox" name="showEstimates">
@ -85,25 +66,121 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<widget class="QCheckBox" name="stripHTML">
<property name="text">
<string>Strip HTML when pasting text</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="deleteMedia">
<property name="text">
<string>When adding media, move instead of copying</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="newSpread"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Next day starts at</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="dayOffset">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>23</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Learn ahead limit</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="lrnCutoff">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_29">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_30">
<property name="text">
<string>Timebox time limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="timeLimit">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_39">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_40">
<property name="text">
<string>hours past midnight</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QPushButton" name="profilePass">
<property name="text">
<string>Some settings will take effect after you restart Anki.</string>
<string>Profile Password...</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
@ -125,7 +202,7 @@
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_16">
<widget class="QLabel" name="syncLabel">
<property name="text">
<string>&lt;b&gt;Synchronisation&lt;/b&gt;</string>
</property>
@ -388,61 +465,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Advanced</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="stripHTML">
<property name="text">
<string>Strip HTML when pasting text</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="deleteMedia">
<property name="text">
<string>Move instead of copying media when adding</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="profilePass">
<property name="text">
<string>Profile Password...</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Some settings will take effect after you restart Anki.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -458,12 +480,16 @@
</layout>
</widget>
<tabstops>
<tabstop>buttonBox</tabstop>
<tabstop>interfaceLang</tabstop>
<tabstop>autoplaySounds</tabstop>
<tabstop>showEstimates</tabstop>
<tabstop>showProgress</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>stripHTML</tabstop>
<tabstop>deleteMedia</tabstop>
<tabstop>newSpread</tabstop>
<tabstop>dayOffset</tabstop>
<tabstop>lrnCutoff</tabstop>
<tabstop>timeLimit</tabstop>
<tabstop>profilePass</tabstop>
<tabstop>syncMedia</tabstop>
<tabstop>syncOnProgramOpen</tabstop>
<tabstop>syncDeauth</tabstop>
@ -472,9 +498,8 @@
<tabstop>proxyUser</tabstop>
<tabstop>proxyPass</tabstop>
<tabstop>numBackups</tabstop>
<tabstop>stripHTML</tabstop>
<tabstop>deleteMedia</tabstop>
<tabstop>profilePass</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources/>
<connections>