pass night mode into body_class() instead of changing globally
This commit is contained in:
parent
e2425d3b0d
commit
06a0b1ee73
@ -56,7 +56,7 @@ class CardLayout(QDialog):
|
||||
self.model = note.model()
|
||||
self.templates = self.model["tmpls"]
|
||||
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.have_autoplayed = False
|
||||
self.mm._remove_from_cache(self.model["id"])
|
||||
@ -323,7 +323,7 @@ class CardLayout(QDialog):
|
||||
self.on_preview_toggled()
|
||||
|
||||
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()
|
||||
|
||||
def on_mobile_class_action_toggled(self):
|
||||
@ -342,7 +342,7 @@ class CardLayout(QDialog):
|
||||
|
||||
a = m.addAction(tr(TR.CARD_TEMPLATES_NIGHT_MODE))
|
||||
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)
|
||||
|
||||
a = m.addAction(tr(TR.CARD_TEMPLATES_ADD_MOBILE_CLASS))
|
||||
@ -458,9 +458,9 @@ class CardLayout(QDialog):
|
||||
|
||||
ti = self.maybeTextInput
|
||||
|
||||
theme_manager.set_night_mode(self.night_mode_action_toggled)
|
||||
|
||||
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
|
||||
bodyclass = theme_manager.body_classes_for_card_ord(
|
||||
c.ord, self.night_mode_is_enabled
|
||||
)
|
||||
if self.mobile_class_action_toggled:
|
||||
bodyclass += " mobile"
|
||||
|
||||
@ -788,7 +788,6 @@ Enter deck to place new %s cards in, or leave blank:"""
|
||||
except TemplateError as e:
|
||||
showWarning(str(e))
|
||||
return
|
||||
theme_manager.set_night_mode(self.mw.pm.night_mode())
|
||||
self.mw.reset()
|
||||
tooltip(tr(TR.CARD_TEMPLATES_CHANGES_SAVED), parent=self.parent())
|
||||
self.cleanup()
|
||||
@ -812,7 +811,6 @@ Enter deck to place new %s cards in, or leave blank:"""
|
||||
self.preview_web = None
|
||||
self.model = None
|
||||
self.rendered_card = None
|
||||
theme_manager.set_night_mode(self.mw.pm.night_mode())
|
||||
self.mw = None
|
||||
|
||||
def onHelp(self):
|
||||
|
@ -3,7 +3,7 @@
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import platform
|
||||
from typing import Dict
|
||||
from typing import Dict, Optional
|
||||
|
||||
from anki.utils import isMac
|
||||
from aqt import QApplication, gui_hooks, isWin
|
||||
@ -54,7 +54,7 @@ class ThemeManager:
|
||||
|
||||
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."
|
||||
classes = []
|
||||
if isWin:
|
||||
@ -63,15 +63,20 @@ class ThemeManager:
|
||||
classes.append("isMac")
|
||||
else:
|
||||
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"])
|
||||
if self.macos_dark_mode():
|
||||
classes.append("macos-dark-mode")
|
||||
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."
|
||||
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:
|
||||
"""Get a color defined in _vars.scss
|
||||
|
Loading…
Reference in New Issue
Block a user