night mode

This commit is contained in:
Damien Elmes 2017-12-04 12:20:56 +10:00
parent 15e102e047
commit fcccf12ba6
7 changed files with 30 additions and 7 deletions

View file

@ -188,6 +188,12 @@ def entsToTxt(html):
return text # leave as is return text # leave as is
return reEnts.sub(fixup, html) return reEnts.sub(fixup, html)
def bodyClass(col, card):
bodyclass = "card card%d" % (card.ord+1)
if col.conf.get("nightMode"):
bodyclass += " nightMode"
return bodyclass
# IDs # IDs
############################################################################## ##############################################################################

View file

@ -13,8 +13,9 @@ import json
from aqt.qt import * from aqt.qt import *
import anki import anki
import aqt.forms import aqt.forms
from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, isWin, intTime,\ from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, \
isMac, isLin isWin, intTime, \
isMac, isLin, bodyClass
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \ saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \ showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \
@ -1347,7 +1348,7 @@ where id in %s""" % ids2str(sf))
txt = c.a() txt = c.a()
txt = re.sub("\[\[type:[^]]+\]\]", "", txt) txt = re.sub("\[\[type:[^]]+\]\]", "", txt)
bodyclass="card card%d" % (c.ord+1) bodyclass = bodyClass(self.mw.col, c)
clearAudioQueue() clearAudioQueue()
if self.mw.reviewer.autoplay(c): if self.mw.reviewer.autoplay(c):

View file

@ -12,7 +12,7 @@ from anki.sound import playFromText, clearAudioQueue
from aqt.utils import saveGeom, restoreGeom, mungeQA,\ from aqt.utils import saveGeom, restoreGeom, mungeQA,\
showInfo, askUser, getOnlyText, \ showInfo, askUser, getOnlyText, \
showWarning, openHelp, downArrow showWarning, openHelp, downArrow
from anki.utils import isMac, isWin, joinFields from anki.utils import isMac, isWin, joinFields, bodyClass
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
import json import json
from anki.hooks import runFilter from anki.hooks import runFilter
@ -297,7 +297,8 @@ Please create a new card type first."""))
c = self.card c = self.card
ti = self.maybeTextInput ti = self.maybeTextInput
bodyclass="card card%d" % (c.ord+1)
bodyclass = bodyClass(self.mw.col, c)
q = ti(mungeQA(self.mw.col, c.q(reload=True))) q = ti(mungeQA(self.mw.col, c.q(reload=True)))
q = runFilter("prepareQA", q, c, "clayoutQuestion") q = runFilter("prepareQA", q, c, "clayoutQuestion")

View file

@ -80,6 +80,7 @@ class Preferences(QDialog):
f.timeLimit.setValue(qc['timeLim']/60.0) f.timeLimit.setValue(qc['timeLim']/60.0)
f.showEstimates.setChecked(qc['estTimes']) f.showEstimates.setChecked(qc['estTimes'])
f.showProgress.setChecked(qc['dueCounts']) f.showProgress.setChecked(qc['dueCounts'])
f.nightMode.setChecked(qc.get("nightMode", False))
f.newSpread.addItems(list(c.newCardSchedulingLabels().values())) f.newSpread.addItems(list(c.newCardSchedulingLabels().values()))
f.newSpread.setCurrentIndex(qc['newSpread']) f.newSpread.setCurrentIndex(qc['newSpread'])
f.useCurrent.setCurrentIndex(int(not qc.get("addToCur", True))) f.useCurrent.setCurrentIndex(int(not qc.get("addToCur", True)))
@ -91,6 +92,7 @@ class Preferences(QDialog):
qc['dueCounts'] = f.showProgress.isChecked() qc['dueCounts'] = f.showProgress.isChecked()
qc['estTimes'] = f.showEstimates.isChecked() qc['estTimes'] = f.showEstimates.isChecked()
qc['newSpread'] = f.newSpread.currentIndex() qc['newSpread'] = f.newSpread.currentIndex()
qc['nightMode'] = f.nightMode.isChecked()
qc['timeLim'] = f.timeLimit.value()*60 qc['timeLim'] = f.timeLimit.value()*60
qc['collapseTime'] = f.lrnCutoff.value()*60 qc['collapseTime'] = f.lrnCutoff.value()*60
qc['addToCur'] = not f.useCurrent.currentIndex() qc['addToCur'] = not f.useCurrent.currentIndex()

View file

@ -10,7 +10,7 @@ import html.parser
from anki.lang import _, ngettext from anki.lang import _, ngettext
from aqt.qt import * from aqt.qt import *
from anki.utils import stripHTML, json from anki.utils import stripHTML, json, bodyClass
from anki.hooks import addHook, runHook, runFilter from anki.hooks import addHook, runHook, runFilter
from anki.sound import playFromText, clearAudioQueue, play from anki.sound import playFromText, clearAudioQueue, play
from aqt.utils import mungeQA, tooltip, askUserDialog, \ from aqt.utils import mungeQA, tooltip, askUserDialog, \
@ -167,7 +167,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
q = self._mungeQA(q) q = self._mungeQA(q)
q = runFilter("prepareQA", q, c, "reviewQuestion") q = runFilter("prepareQA", q, c, "reviewQuestion")
bodyclass = "card card%d" % (c.ord+1) bodyclass = bodyClass(self.mw.col, c)
self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass)) self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass))
self._drawFlag() self._drawFlag()

View file

@ -78,6 +78,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="nightMode">
<property name="text">
<string>Show cards as white on black (night mode)</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QComboBox" name="useCurrent"> <widget class="QComboBox" name="useCurrent">
<item> <item>
@ -429,6 +436,7 @@
<tabstop>showEstimates</tabstop> <tabstop>showEstimates</tabstop>
<tabstop>showProgress</tabstop> <tabstop>showProgress</tabstop>
<tabstop>pastePNG</tabstop> <tabstop>pastePNG</tabstop>
<tabstop>nightMode</tabstop>
<tabstop>useCurrent</tabstop> <tabstop>useCurrent</tabstop>
<tabstop>newSpread</tabstop> <tabstop>newSpread</tabstop>
<tabstop>dayOffset</tabstop> <tabstop>dayOffset</tabstop>

View file

@ -8,6 +8,11 @@ body {
overflow-wrap: break-word; overflow-wrap: break-word;
} }
body.nightMode {
background-color: black;
color: white;
}
img { img {
max-width: 95%; max-width: 95%;
max-height: 95%; max-height: 95%;