2012-12-21 08:51:59 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2016-04-05 03:02:01 +02:00
|
|
|
import anki.lang
|
2012-12-21 08:51:59 +01:00
|
|
|
import aqt
|
2019-12-20 10:19:03 +01:00
|
|
|
from aqt import AnkiQt
|
2020-12-22 04:01:06 +01:00
|
|
|
from aqt.profiles import RecordingDriver, VideoDriver
|
2019-12-20 10:19:03 +01:00
|
|
|
from aqt.qt import *
|
2021-01-07 05:24:49 +01:00
|
|
|
from aqt.utils import (
|
|
|
|
TR,
|
2021-01-25 14:45:47 +01:00
|
|
|
HelpPage,
|
2021-01-07 05:24:49 +01:00
|
|
|
askUser,
|
|
|
|
disable_help_button,
|
|
|
|
openHelp,
|
|
|
|
showInfo,
|
|
|
|
showWarning,
|
|
|
|
tr,
|
|
|
|
)
|
2019-12-20 10:19:03 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-12-22 04:01:06 +01:00
|
|
|
def video_driver_name_for_platform(driver: VideoDriver) -> str:
|
|
|
|
if driver == VideoDriver.ANGLE:
|
|
|
|
return tr(TR.PREFERENCES_VIDEO_DRIVER_ANGLE)
|
|
|
|
elif driver == VideoDriver.Software:
|
|
|
|
if isMac:
|
|
|
|
return tr(TR.PREFERENCES_VIDEO_DRIVER_SOFTWARE_MAC)
|
|
|
|
else:
|
|
|
|
return tr(TR.PREFERENCES_VIDEO_DRIVER_SOFTWARE_OTHER)
|
|
|
|
else:
|
|
|
|
if isMac:
|
|
|
|
return tr(TR.PREFERENCES_VIDEO_DRIVER_OPENGL_MAC)
|
|
|
|
else:
|
|
|
|
return tr(TR.PREFERENCES_VIDEO_DRIVER_OPENGL_OTHER)
|
|
|
|
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
class Preferences(QDialog):
|
2019-12-19 00:58:16 +01:00
|
|
|
def __init__(self, mw: AnkiQt):
|
2012-12-21 08:51:59 +01:00
|
|
|
QDialog.__init__(self, mw, Qt.Window)
|
|
|
|
self.mw = mw
|
|
|
|
self.prof = self.mw.pm.profile
|
|
|
|
self.form = aqt.forms.preferences.Ui_Preferences()
|
|
|
|
self.form.setupUi(self)
|
2021-01-07 05:24:49 +01:00
|
|
|
disable_help_button(self)
|
2014-06-03 09:24:47 +02:00
|
|
|
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
|
|
|
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
|
2021-01-25 14:45:47 +01:00
|
|
|
qconnect(
|
|
|
|
self.form.buttonBox.helpRequested, lambda: openHelp(HelpPage.PREFERENCES)
|
|
|
|
)
|
2017-09-10 07:15:12 +02:00
|
|
|
self.silentlyClose = True
|
2021-01-31 09:46:43 +01:00
|
|
|
self.prefs = self.mw.col.get_preferences()
|
2016-04-05 03:02:01 +02:00
|
|
|
self.setupLang()
|
2012-12-21 08:51:59 +01:00
|
|
|
self.setupCollection()
|
|
|
|
self.setupNetwork()
|
|
|
|
self.setupBackup()
|
|
|
|
self.setupOptions()
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def accept(self):
|
2015-04-26 12:28:32 +02:00
|
|
|
# avoid exception if main window is already closed
|
|
|
|
if not self.mw.col:
|
|
|
|
return
|
2012-12-21 08:51:59 +01:00
|
|
|
self.updateCollection()
|
|
|
|
self.updateNetwork()
|
|
|
|
self.updateBackup()
|
|
|
|
self.updateOptions()
|
|
|
|
self.mw.pm.save()
|
|
|
|
self.mw.reset()
|
|
|
|
self.done(0)
|
2017-09-10 07:15:12 +02:00
|
|
|
aqt.dialogs.markClosed("Preferences")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def reject(self):
|
|
|
|
self.accept()
|
|
|
|
|
2016-04-05 03:02:01 +02:00
|
|
|
# Language
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def setupLang(self):
|
|
|
|
f = self.form
|
|
|
|
f.lang.addItems([x[0] for x in anki.lang.langs])
|
|
|
|
f.lang.setCurrentIndex(self.langIdx())
|
2020-05-04 05:23:08 +02:00
|
|
|
qconnect(f.lang.currentIndexChanged, self.onLangIdxChanged)
|
2016-04-05 03:02:01 +02:00
|
|
|
|
|
|
|
def langIdx(self):
|
|
|
|
codes = [x[1] for x in anki.lang.langs]
|
2020-03-11 05:58:57 +01:00
|
|
|
lang = anki.lang.currentLang
|
|
|
|
if lang in anki.lang.compatMap:
|
|
|
|
lang = anki.lang.compatMap[lang]
|
2020-03-23 07:08:06 +01:00
|
|
|
else:
|
|
|
|
lang = lang.replace("-", "_")
|
2016-04-05 03:02:01 +02:00
|
|
|
try:
|
2020-03-11 05:58:57 +01:00
|
|
|
return codes.index(lang)
|
2016-04-05 03:02:01 +02:00
|
|
|
except:
|
2019-09-23 13:18:03 +02:00
|
|
|
return codes.index("en_US")
|
2016-04-05 03:02:01 +02:00
|
|
|
|
|
|
|
def onLangIdxChanged(self, idx):
|
|
|
|
code = anki.lang.langs[idx][1]
|
|
|
|
self.mw.pm.setLang(code)
|
2020-11-17 08:42:43 +01:00
|
|
|
showInfo(
|
|
|
|
tr(TR.PREFERENCES_PLEASE_RESTART_ANKI_TO_COMPLETE_LANGUAGE), parent=self
|
|
|
|
)
|
2016-04-05 03:02:01 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Collection options
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def setupCollection(self):
|
|
|
|
import anki.consts as c
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
f = self.form
|
|
|
|
qc = self.mw.col.conf
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2020-12-22 04:01:06 +01:00
|
|
|
self.setup_video_driver()
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2020-11-17 10:23:06 +01:00
|
|
|
f.newSpread.addItems(list(c.newCardSchedulingLabels(self.mw.col).values()))
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
f.useCurrent.setCurrentIndex(int(not qc.get("addToCur", True)))
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2021-01-31 09:46:43 +01:00
|
|
|
s = self.prefs.sched
|
2020-12-15 14:09:19 +01:00
|
|
|
f.lrnCutoff.setValue(int(s.learn_ahead_secs / 60.0))
|
|
|
|
f.timeLimit.setValue(int(s.time_limit_secs / 60.0))
|
2020-05-11 10:35:15 +02:00
|
|
|
f.showEstimates.setChecked(s.show_intervals_on_buttons)
|
|
|
|
f.showProgress.setChecked(s.show_remaining_due_counts)
|
|
|
|
f.newSpread.setCurrentIndex(s.new_review_mix)
|
|
|
|
f.dayLearnFirst.setChecked(s.day_learn_first)
|
|
|
|
f.dayOffset.setValue(s.rollover)
|
|
|
|
|
|
|
|
if s.scheduler_version < 2:
|
2018-01-22 02:24:45 +01:00
|
|
|
f.dayLearnFirst.setVisible(False)
|
2020-03-10 08:50:18 +01:00
|
|
|
f.new_timezone.setVisible(False)
|
2018-04-30 08:26:19 +02:00
|
|
|
else:
|
|
|
|
f.newSched.setChecked(True)
|
2020-05-11 10:35:15 +02:00
|
|
|
f.new_timezone.setChecked(s.new_timezone)
|
2018-01-20 06:32:52 +01:00
|
|
|
|
2020-12-22 04:01:06 +01:00
|
|
|
def setup_video_driver(self):
|
|
|
|
self.video_drivers = VideoDriver.all_for_platform()
|
|
|
|
names = [
|
|
|
|
tr(TR.PREFERENCES_VIDEO_DRIVER, driver=video_driver_name_for_platform(d))
|
|
|
|
for d in self.video_drivers
|
|
|
|
]
|
|
|
|
self.form.video_driver.addItems(names)
|
|
|
|
self.form.video_driver.setCurrentIndex(
|
|
|
|
self.video_drivers.index(self.mw.pm.video_driver())
|
|
|
|
)
|
|
|
|
|
|
|
|
def update_video_driver(self):
|
|
|
|
new_driver = self.video_drivers[self.form.video_driver.currentIndex()]
|
|
|
|
if new_driver != self.mw.pm.video_driver():
|
|
|
|
self.mw.pm.set_video_driver(new_driver)
|
|
|
|
showInfo(tr(TR.PREFERENCES_CHANGES_WILL_TAKE_EFFECT_WHEN_YOU))
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def updateCollection(self):
|
|
|
|
f = self.form
|
|
|
|
d = self.mw.col
|
2018-08-30 05:39:04 +02:00
|
|
|
|
2020-12-22 04:01:06 +01:00
|
|
|
self.update_video_driver()
|
2018-08-30 05:39:04 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
qc = d.conf
|
2019-12-23 01:34:10 +01:00
|
|
|
qc["addToCur"] = not f.useCurrent.currentIndex()
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2021-01-31 09:46:43 +01:00
|
|
|
s = self.prefs.sched
|
2020-05-11 10:35:15 +02:00
|
|
|
s.show_remaining_due_counts = f.showProgress.isChecked()
|
|
|
|
s.show_intervals_on_buttons = f.showEstimates.isChecked()
|
|
|
|
s.new_review_mix = f.newSpread.currentIndex()
|
|
|
|
s.time_limit_secs = f.timeLimit.value() * 60
|
|
|
|
s.learn_ahead_secs = f.lrnCutoff.value() * 60
|
|
|
|
s.day_learn_first = f.dayLearnFirst.isChecked()
|
|
|
|
s.rollover = f.dayOffset.value()
|
|
|
|
s.new_timezone = f.new_timezone.isChecked()
|
|
|
|
|
|
|
|
# if moving this, make sure scheduler change is moved to Rust or
|
|
|
|
# happens afterwards
|
2021-01-31 09:46:43 +01:00
|
|
|
self.mw.col.set_preferences(self.prefs)
|
2020-05-11 10:35:15 +02:00
|
|
|
|
2018-04-30 08:26:19 +02:00
|
|
|
self._updateSchedVer(f.newSched.isChecked())
|
2018-01-20 06:32:52 +01:00
|
|
|
d.setMod()
|
|
|
|
|
2018-04-30 08:26:19 +02:00
|
|
|
# Scheduler version
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def _updateSchedVer(self, wantNew):
|
|
|
|
haveNew = self.mw.col.schedVer() == 2
|
|
|
|
|
|
|
|
# nothing to do?
|
|
|
|
if haveNew == wantNew:
|
|
|
|
return
|
|
|
|
|
2020-11-17 08:42:43 +01:00
|
|
|
if not askUser(tr(TR.PREFERENCES_THIS_WILL_RESET_ANY_CARDS_IN)):
|
2018-04-30 08:26:19 +02:00
|
|
|
return
|
|
|
|
|
2019-12-06 09:37:39 +01:00
|
|
|
if wantNew:
|
|
|
|
self.mw.col.changeSchedulerVer(2)
|
|
|
|
else:
|
|
|
|
self.mw.col.changeSchedulerVer(1)
|
2018-04-30 08:26:19 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Network
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def setupNetwork(self):
|
2020-02-27 03:25:19 +01:00
|
|
|
self.form.media_log.setText(tr(TR.SYNC_MEDIA_LOG_BUTTON))
|
2020-05-04 05:23:08 +02:00
|
|
|
qconnect(self.form.media_log.clicked, self.on_media_log)
|
2019-12-23 01:34:10 +01:00
|
|
|
self.form.syncOnProgramOpen.setChecked(self.prof["autoSync"])
|
|
|
|
self.form.syncMedia.setChecked(self.prof["syncMedia"])
|
2020-07-01 03:35:24 +02:00
|
|
|
self.form.autoSyncMedia.setChecked(self.mw.pm.auto_sync_media_minutes() != 0)
|
2019-12-23 01:34:10 +01:00
|
|
|
if not self.prof["syncKey"]:
|
2012-12-21 08:51:59 +01:00
|
|
|
self._hideAuth()
|
|
|
|
else:
|
2019-12-23 01:34:10 +01:00
|
|
|
self.form.syncUser.setText(self.prof.get("syncUser", ""))
|
2020-05-04 05:23:08 +02:00
|
|
|
qconnect(self.form.syncDeauth.clicked, self.onSyncDeauth)
|
2020-08-09 06:44:03 +02:00
|
|
|
self.form.syncDeauth.setText(tr(TR.SYNC_LOG_OUT_BUTTON))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 03:22:24 +01:00
|
|
|
def on_media_log(self):
|
|
|
|
self.mw.media_syncer.show_sync_log()
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def _hideAuth(self):
|
2013-04-15 06:46:07 +02:00
|
|
|
self.form.syncDeauth.setVisible(False)
|
2013-10-03 23:09:36 +02:00
|
|
|
self.form.syncUser.setText("")
|
2019-12-23 01:34:10 +01:00
|
|
|
self.form.syncLabel.setText(
|
2020-11-18 02:32:22 +01:00
|
|
|
tr(TR.PREFERENCES_SYNCHRONIZATIONNOT_CURRENTLY_ENABLED_CLICK_THE_SYNC)
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-15 08:48:35 +01:00
|
|
|
def onSyncDeauth(self) -> None:
|
|
|
|
if self.mw.media_syncer.is_syncing():
|
|
|
|
showWarning("Can't log out while sync in progress.")
|
|
|
|
return
|
2019-12-23 01:34:10 +01:00
|
|
|
self.prof["syncKey"] = None
|
2020-02-15 08:48:35 +01:00
|
|
|
self.mw.col.media.force_resync()
|
2012-12-21 08:51:59 +01:00
|
|
|
self._hideAuth()
|
|
|
|
|
|
|
|
def updateNetwork(self):
|
2019-12-23 01:34:10 +01:00
|
|
|
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
|
|
|
|
self.prof["syncMedia"] = self.form.syncMedia.isChecked()
|
2020-07-01 06:01:24 +02:00
|
|
|
self.mw.pm.set_auto_sync_media_minutes(
|
|
|
|
self.form.autoSyncMedia.isChecked() and 15 or 0
|
|
|
|
)
|
2013-05-14 08:23:50 +02:00
|
|
|
if self.form.fullSync.isChecked():
|
2014-11-03 08:28:12 +01:00
|
|
|
self.mw.col.modSchema(check=False)
|
2013-05-14 08:23:50 +02:00
|
|
|
self.mw.col.setMod()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Backup
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def setupBackup(self):
|
2019-12-23 01:34:10 +01:00
|
|
|
self.form.numBackups.setValue(self.prof["numBackups"])
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def updateBackup(self):
|
2019-12-23 01:34:10 +01:00
|
|
|
self.prof["numBackups"] = self.form.numBackups.value()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Basic & Advanced Options
|
|
|
|
######################################################################
|
|
|
|
|
2019-12-19 02:39:40 +01:00
|
|
|
def setupOptions(self):
|
2012-12-21 08:51:59 +01:00
|
|
|
self.form.pastePNG.setChecked(self.prof.get("pastePNG", False))
|
2020-12-15 14:09:19 +01:00
|
|
|
self.form.uiScale.setValue(int(self.mw.pm.uiScale() * 100))
|
2020-01-16 03:36:04 +01:00
|
|
|
self.form.pasteInvert.setChecked(self.prof.get("pasteInvert", False))
|
2020-01-21 12:00:17 +01:00
|
|
|
self.form.showPlayButtons.setChecked(self.prof.get("showPlayButtons", True))
|
2020-01-23 06:08:10 +01:00
|
|
|
self.form.nightMode.setChecked(self.mw.pm.night_mode())
|
2020-02-02 23:32:07 +01:00
|
|
|
self.form.interrupt_audio.setChecked(self.mw.pm.interrupt_audio())
|
2020-12-18 10:48:43 +01:00
|
|
|
self._recording_drivers = [
|
|
|
|
RecordingDriver.QtAudioInput,
|
|
|
|
RecordingDriver.PyAudio,
|
|
|
|
]
|
2020-12-21 07:13:32 +01:00
|
|
|
# The plan is to phase out PyAudio soon, so will hold off on
|
|
|
|
# making this string translatable for now.
|
2020-12-18 10:48:43 +01:00
|
|
|
self.form.recording_driver.addItems(
|
|
|
|
[
|
|
|
|
f"Voice recording driver: {driver.value}"
|
|
|
|
for driver in self._recording_drivers
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.form.recording_driver.setCurrentIndex(
|
|
|
|
self._recording_drivers.index(self.mw.pm.recording_driver())
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-19 02:39:40 +01:00
|
|
|
def updateOptions(self):
|
2020-01-23 06:08:10 +01:00
|
|
|
restart_required = False
|
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
self.prof["pastePNG"] = self.form.pastePNG.isChecked()
|
2020-01-16 03:36:04 +01:00
|
|
|
self.prof["pasteInvert"] = self.form.pasteInvert.isChecked()
|
2019-12-23 01:34:10 +01:00
|
|
|
newScale = self.form.uiScale.value() / 100
|
2019-12-19 00:58:16 +01:00
|
|
|
if newScale != self.mw.pm.uiScale():
|
|
|
|
self.mw.pm.setUiScale(newScale)
|
2020-01-23 06:08:10 +01:00
|
|
|
restart_required = True
|
2020-01-21 12:00:17 +01:00
|
|
|
self.prof["showPlayButtons"] = self.form.showPlayButtons.isChecked()
|
2020-01-23 06:08:10 +01:00
|
|
|
|
2020-04-15 13:37:16 +02:00
|
|
|
if self.mw.pm.night_mode() != self.form.nightMode.isChecked():
|
|
|
|
self.mw.pm.set_night_mode(not self.mw.pm.night_mode())
|
|
|
|
restart_required = True
|
2020-01-23 06:08:10 +01:00
|
|
|
|
2020-02-02 23:32:07 +01:00
|
|
|
self.mw.pm.set_interrupt_audio(self.form.interrupt_audio.isChecked())
|
2020-12-21 06:04:22 +01:00
|
|
|
|
|
|
|
new_audio_driver = self._recording_drivers[
|
|
|
|
self.form.recording_driver.currentIndex()
|
|
|
|
]
|
|
|
|
if self.mw.pm.recording_driver() != new_audio_driver:
|
|
|
|
self.mw.pm.set_recording_driver(new_audio_driver)
|
|
|
|
if new_audio_driver == RecordingDriver.PyAudio:
|
|
|
|
showInfo(
|
|
|
|
"""\
|
|
|
|
The PyAudio driver will likely be removed in a future update. If you find it works better \
|
|
|
|
for you than the default driver, please let us know on the Anki forums."""
|
|
|
|
)
|
2020-02-02 23:32:07 +01:00
|
|
|
|
2020-01-23 06:08:10 +01:00
|
|
|
if restart_required:
|
2020-11-17 08:42:43 +01:00
|
|
|
showInfo(tr(TR.PREFERENCES_CHANGES_WILL_TAKE_EFFECT_WHEN_YOU))
|