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 anki.utils import ids2str
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
from operator import itemgetter from operator import itemgetter
import datetime, time
class DeckConf(QDialog): class DeckConf(QDialog):
def __init__(self, mw): def __init__(self, mw):
@ -27,7 +26,6 @@ class DeckConf(QDialog):
SIGNAL("clicked()"), SIGNAL("clicked()"),
self.onRestore) self.onRestore)
self.setupCombos() self.setupCombos()
self.setupCollection()
self.setWindowTitle(_("Options for %s") % self.deck['name']) self.setWindowTitle(_("Options for %s") % self.deck['name'])
self.exec_() self.exec_()
@ -36,7 +34,6 @@ class DeckConf(QDialog):
f = self.form f = self.form
f.newOrder.addItems(cs.newCardOrderLabels().values()) f.newOrder.addItems(cs.newCardOrderLabels().values())
f.revOrder.addItems(cs.revCardOrderLabels().values()) f.revOrder.addItems(cs.revCardOrderLabels().values())
f.newSpread.addItems(cs.newCardSchedulingLabels().values())
self.connect(f.newOrder, SIGNAL("currentIndexChanged(int)"), self.connect(f.newOrder, SIGNAL("currentIndexChanged(int)"),
self.onNewOrderChanged) self.onNewOrderChanged)
@ -111,32 +108,6 @@ class DeckConf(QDialog):
self.conf['name'] = name self.conf['name'] = name
self.loadConfs() 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 # Loading
################################################## ##################################################
@ -174,6 +145,7 @@ class DeckConf(QDialog):
# general # general
c = self.conf c = self.conf
f.maxTaken.setValue(c['maxTaken']) f.maxTaken.setValue(c['maxTaken'])
f.autoplaySounds.setChecked(c['autoplay'])
def onRestore(self): def onRestore(self):
self.mw.col.decks.restoreToDefault(self.conf) self.mw.col.decks.restoreToDefault(self.conf)
@ -181,7 +153,6 @@ class DeckConf(QDialog):
f = self.form f = self.form
f.dayOffset.setValue(4) f.dayOffset.setValue(4)
f.lrnCutoff.setValue(20) f.lrnCutoff.setValue(20)
f.newSpread.setCurrentIndex(0)
f.timeLimit.setValue(0) f.timeLimit.setValue(0)
# New order # New order
@ -244,16 +215,13 @@ class DeckConf(QDialog):
# general # general
c = self.conf c = self.conf
c['maxTaken'] = f.maxTaken.value() c['maxTaken'] = f.maxTaken.value()
c['autoplay'] = f.autoplaySounds.isChecked()
self.mw.col.decks.save(self.conf) self.mw.col.decks.save(self.conf)
#make sure to save() deck and conf (on saveConf())
def reject(self): def reject(self):
self.accept() self.accept()
def accept(self): def accept(self):
self.saveCollection()
self.saveConf() self.saveConf()
self.mw.reset() self.mw.reset()
QDialog.accept(self) QDialog.accept(self)

View file

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

View file

@ -2,7 +2,7 @@
# Copyright: Damien Elmes <anki@ichi2.net> # Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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 aqt.qt import *
from anki.lang import langs from anki.lang import langs
from aqt.utils import openFolder, showWarning, getText from aqt.utils import openFolder, showWarning, getText
@ -18,6 +18,7 @@ class Preferences(QDialog):
self.form.setupUi(self) self.form.setupUi(self)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
lambda: openHelp("Preferences")) lambda: openHelp("Preferences"))
self.setupCollection()
self.setupLang() self.setupLang()
self.setupNetwork() self.setupNetwork()
self.setupBackup() self.setupBackup()
@ -25,6 +26,7 @@ class Preferences(QDialog):
self.show() self.show()
def accept(self): def accept(self):
self.updateCollection()
self.updateNetwork() self.updateNetwork()
self.updateBackup() self.updateBackup()
self.updateOptions() self.updateOptions()
@ -35,6 +37,38 @@ class Preferences(QDialog):
def reject(self): def reject(self):
self.accept() 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 # Language handling
###################################################################### ######################################################################
@ -74,6 +108,9 @@ class Preferences(QDialog):
self.prof['syncMedia']) self.prof['syncMedia'])
if not self.prof['syncKey']: if not self.prof['syncKey']:
self.form.syncDeauth.setShown(False) 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: else:
self.connect(self.form.syncDeauth, SIGNAL("clicked()"), self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
self.onSyncDeauth) self.onSyncDeauth)
@ -112,21 +149,14 @@ class Preferences(QDialog):
###################################################################### ######################################################################
def setupOptions(self): 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.deleteMedia.setChecked(self.prof['deleteMedia'])
self.form.stripHTML.setChecked(self.prof['stripHTML']) self.form.stripHTML.setChecked(self.prof['stripHTML'])
self.form.autoplaySounds.setChecked(self.prof['autoplay'])
self.connect( self.connect(
self.form.profilePass, SIGNAL("clicked()"), self.form.profilePass, SIGNAL("clicked()"),
self.onProfilePass) self.onProfilePass)
def updateOptions(self): 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['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() self.prof['deleteMedia'] = self.form.deleteMedia.isChecked()
def onProfilePass(self): def onProfilePass(self):

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>500</width> <width>500</width>
<height>437</height> <height>438</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -555,91 +555,12 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_22"> <widget class="QCheckBox" name="autoplaySounds">
<property name="text"> <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> </property>
</widget> </widget>
</item> </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> <item>
<spacer name="verticalSpacer_5"> <spacer name="verticalSpacer_5">
<property name="orientation"> <property name="orientation">
@ -693,10 +614,7 @@
<tabstop>leechThreshold</tabstop> <tabstop>leechThreshold</tabstop>
<tabstop>leechAction</tabstop> <tabstop>leechAction</tabstop>
<tabstop>maxTaken</tabstop> <tabstop>maxTaken</tabstop>
<tabstop>newSpread</tabstop> <tabstop>autoplaySounds</tabstop>
<tabstop>dayOffset</tabstop>
<tabstop>lrnCutoff</tabstop>
<tabstop>timeLimit</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
</tabstops> </tabstops>
<resources> <resources>

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>461</width> <width>439</width>
<height>442</height> <height>420</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -28,15 +28,14 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>12</number>
</property> </property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&lt;b&gt;Language&lt;/b&gt;</string> <string>Language:</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -50,25 +49,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<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>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="showEstimates"> <widget class="QCheckBox" name="showEstimates">
@ -85,25 +66,121 @@
</widget> </widget>
</item> </item>
<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"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>0</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QPushButton" name="profilePass">
<property name="text"> <property name="text">
<string>Some settings will take effect after you restart Anki.</string> <string>Profile Password...</string>
</property> </property>
<property name="alignment"> <property name="autoDefault">
<set>Qt::AlignCenter</set> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -125,7 +202,7 @@
<item> <item>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="syncLabel">
<property name="text"> <property name="text">
<string>&lt;b&gt;Synchronisation&lt;/b&gt;</string> <string>&lt;b&gt;Synchronisation&lt;/b&gt;</string>
</property> </property>
@ -388,61 +465,6 @@
</item> </item>
</layout> </layout>
</widget> </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> </widget>
</item> </item>
<item> <item>
@ -458,12 +480,16 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>buttonBox</tabstop>
<tabstop>interfaceLang</tabstop> <tabstop>interfaceLang</tabstop>
<tabstop>autoplaySounds</tabstop>
<tabstop>showEstimates</tabstop> <tabstop>showEstimates</tabstop>
<tabstop>showProgress</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>syncMedia</tabstop>
<tabstop>syncOnProgramOpen</tabstop> <tabstop>syncOnProgramOpen</tabstop>
<tabstop>syncDeauth</tabstop> <tabstop>syncDeauth</tabstop>
@ -472,9 +498,8 @@
<tabstop>proxyUser</tabstop> <tabstop>proxyUser</tabstop>
<tabstop>proxyPass</tabstop> <tabstop>proxyPass</tabstop>
<tabstop>numBackups</tabstop> <tabstop>numBackups</tabstop>
<tabstop>stripHTML</tabstop> <tabstop>buttonBox</tabstop>
<tabstop>deleteMedia</tabstop> <tabstop>tabWidget</tabstop>
<tabstop>profilePass</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>