mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
pass night mode into body_class() instead of changing globally
This commit is contained in:
parent
e2425d3b0d
commit
06a0b1ee73
2 changed files with 16 additions and 13 deletions
|
@ -56,7 +56,7 @@ class CardLayout(QDialog):
|
||||||
self.model = note.model()
|
self.model = note.model()
|
||||||
self.templates = self.model["tmpls"]
|
self.templates = self.model["tmpls"]
|
||||||
self.fill_empty_action_toggled = fill_empty
|
self.fill_empty_action_toggled = fill_empty
|
||||||
self.night_mode_action_toggled = self.mw.pm.night_mode()
|
self.night_mode_is_enabled = self.mw.pm.night_mode()
|
||||||
self.mobile_class_action_toggled = False
|
self.mobile_class_action_toggled = False
|
||||||
self.have_autoplayed = False
|
self.have_autoplayed = False
|
||||||
self.mm._remove_from_cache(self.model["id"])
|
self.mm._remove_from_cache(self.model["id"])
|
||||||
|
@ -323,7 +323,7 @@ class CardLayout(QDialog):
|
||||||
self.on_preview_toggled()
|
self.on_preview_toggled()
|
||||||
|
|
||||||
def on_night_mode_action_toggled(self):
|
def on_night_mode_action_toggled(self):
|
||||||
self.night_mode_action_toggled = not self.night_mode_action_toggled
|
self.night_mode_is_enabled = not self.night_mode_is_enabled
|
||||||
self.on_preview_toggled()
|
self.on_preview_toggled()
|
||||||
|
|
||||||
def on_mobile_class_action_toggled(self):
|
def on_mobile_class_action_toggled(self):
|
||||||
|
@ -342,7 +342,7 @@ class CardLayout(QDialog):
|
||||||
|
|
||||||
a = m.addAction(tr(TR.CARD_TEMPLATES_NIGHT_MODE))
|
a = m.addAction(tr(TR.CARD_TEMPLATES_NIGHT_MODE))
|
||||||
a.setCheckable(True)
|
a.setCheckable(True)
|
||||||
a.setChecked(self.night_mode_action_toggled)
|
a.setChecked(self.night_mode_is_enabled)
|
||||||
qconnect(a.triggered, self.on_night_mode_action_toggled)
|
qconnect(a.triggered, self.on_night_mode_action_toggled)
|
||||||
|
|
||||||
a = m.addAction(tr(TR.CARD_TEMPLATES_ADD_MOBILE_CLASS))
|
a = m.addAction(tr(TR.CARD_TEMPLATES_ADD_MOBILE_CLASS))
|
||||||
|
@ -458,9 +458,9 @@ class CardLayout(QDialog):
|
||||||
|
|
||||||
ti = self.maybeTextInput
|
ti = self.maybeTextInput
|
||||||
|
|
||||||
theme_manager.set_night_mode(self.night_mode_action_toggled)
|
bodyclass = theme_manager.body_classes_for_card_ord(
|
||||||
|
c.ord, self.night_mode_is_enabled
|
||||||
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
|
)
|
||||||
if self.mobile_class_action_toggled:
|
if self.mobile_class_action_toggled:
|
||||||
bodyclass += " mobile"
|
bodyclass += " mobile"
|
||||||
|
|
||||||
|
@ -788,7 +788,6 @@ Enter deck to place new %s cards in, or leave blank:"""
|
||||||
except TemplateError as e:
|
except TemplateError as e:
|
||||||
showWarning(str(e))
|
showWarning(str(e))
|
||||||
return
|
return
|
||||||
theme_manager.set_night_mode(self.mw.pm.night_mode())
|
|
||||||
self.mw.reset()
|
self.mw.reset()
|
||||||
tooltip(tr(TR.CARD_TEMPLATES_CHANGES_SAVED), parent=self.parent())
|
tooltip(tr(TR.CARD_TEMPLATES_CHANGES_SAVED), parent=self.parent())
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
@ -812,7 +811,6 @@ Enter deck to place new %s cards in, or leave blank:"""
|
||||||
self.preview_web = None
|
self.preview_web = None
|
||||||
self.model = None
|
self.model = None
|
||||||
self.rendered_card = None
|
self.rendered_card = None
|
||||||
theme_manager.set_night_mode(self.mw.pm.night_mode())
|
|
||||||
self.mw = None
|
self.mw = None
|
||||||
|
|
||||||
def onHelp(self):
|
def onHelp(self):
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# 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 platform
|
import platform
|
||||||
from typing import Dict
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from anki.utils import isMac
|
from anki.utils import isMac
|
||||||
from aqt import QApplication, gui_hooks, isWin
|
from aqt import QApplication, gui_hooks, isWin
|
||||||
|
@ -54,7 +54,7 @@ class ThemeManager:
|
||||||
|
|
||||||
return cache.setdefault(path, icon)
|
return cache.setdefault(path, icon)
|
||||||
|
|
||||||
def body_class(self) -> str:
|
def body_class(self, night_mode: Optional[bool] = None) -> str:
|
||||||
"Returns space-separated class list for platform/theme."
|
"Returns space-separated class list for platform/theme."
|
||||||
classes = []
|
classes = []
|
||||||
if isWin:
|
if isWin:
|
||||||
|
@ -63,15 +63,20 @@ class ThemeManager:
|
||||||
classes.append("isMac")
|
classes.append("isMac")
|
||||||
else:
|
else:
|
||||||
classes.append("isLin")
|
classes.append("isLin")
|
||||||
if self.night_mode:
|
|
||||||
|
if night_mode is None:
|
||||||
|
night_mode = self.night_mode
|
||||||
|
if night_mode:
|
||||||
classes.extend(["nightMode", "night_mode"])
|
classes.extend(["nightMode", "night_mode"])
|
||||||
if self.macos_dark_mode():
|
if self.macos_dark_mode():
|
||||||
classes.append("macos-dark-mode")
|
classes.append("macos-dark-mode")
|
||||||
return " ".join(classes)
|
return " ".join(classes)
|
||||||
|
|
||||||
def body_classes_for_card_ord(self, card_ord: int) -> str:
|
def body_classes_for_card_ord(
|
||||||
|
self, card_ord: int, night_mode: Optional[bool] = None
|
||||||
|
) -> str:
|
||||||
"Returns body classes used when showing a card."
|
"Returns body classes used when showing a card."
|
||||||
return f"card card{card_ord+1} {self.body_class()}"
|
return f"card card{card_ord+1} {self.body_class(night_mode)}"
|
||||||
|
|
||||||
def str_color(self, key: str) -> str:
|
def str_color(self, key: str) -> str:
|
||||||
"""Get a color defined in _vars.scss
|
"""Get a color defined in _vars.scss
|
||||||
|
|
Loading…
Reference in a new issue