mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Apply CSS variables from Python side
Why go full-circle with the Sass variables? This way we only need one interface for add-on authors to interact with. It also makes it easier for us to apply additional themes in the future.
This commit is contained in:
parent
34ed551f94
commit
87db774412
7 changed files with 20 additions and 10 deletions
|
@ -1,6 +1,5 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* 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 */
|
||||||
@use "root-vars";
|
|
||||||
@use "sass/vars" as *;
|
@use "sass/vars" as *;
|
||||||
@use "sass/card-counts";
|
@use "sass/card-counts";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* 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 */
|
||||||
|
|
||||||
@use "root-vars";
|
|
||||||
@use "sass/vars" as *;
|
@use "sass/vars" as *;
|
||||||
@use "sass/card-counts";
|
@use "sass/card-counts";
|
||||||
@use "sass/button-mixins" as button;
|
@use "sass/button-mixins" as button;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* 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 */
|
||||||
|
|
||||||
@use "root-vars";
|
|
||||||
@use "sass/vars" as *;
|
@use "sass/vars" as *;
|
||||||
@use "sass/card-counts";
|
@use "sass/card-counts";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* 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 */
|
||||||
|
|
||||||
@use "root-vars";
|
|
||||||
@use "sass/vars" as *;
|
@use "sass/vars" as *;
|
||||||
@use "sass/elevation";
|
@use "sass/elevation";
|
||||||
@use "sass/button-mixins" as button;
|
@use "sass/button-mixins" as button;
|
||||||
|
|
|
@ -12,7 +12,7 @@ import anki.lang
|
||||||
from anki._legacy import deprecated
|
from anki._legacy import deprecated
|
||||||
from anki.lang import is_rtl
|
from anki.lang import is_rtl
|
||||||
from anki.utils import is_lin, is_mac, is_win
|
from anki.utils import is_lin, is_mac, is_win
|
||||||
from aqt import colors, gui_hooks
|
from aqt import colors, gui_hooks, props
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.utils import askUser, is_gesture_or_zoom_event, openLink, showInfo, tr
|
from aqt.utils import askUser, is_gesture_or_zoom_event, openLink, showInfo, tr
|
||||||
|
@ -448,7 +448,6 @@ div[contenteditable="true"]:focus {{
|
||||||
)
|
)
|
||||||
|
|
||||||
zoom = self.app_zoom_factor()
|
zoom = self.app_zoom_factor()
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
body {{ zoom: {zoom}; background-color: var(--canvas); }}
|
body {{ zoom: {zoom}; background-color: var(--canvas); }}
|
||||||
html {{ {font} }}
|
html {{ {font} }}
|
||||||
|
@ -457,6 +456,23 @@ html {{ {font} }}
|
||||||
:root[class*=night-mode] {{ --canvas: {colors.CANVAS["dark"]} }}
|
:root[class*=night-mode] {{ --canvas: {colors.CANVAS["dark"]} }}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def css_vars(self) -> str:
|
||||||
|
br = "\n "
|
||||||
|
return f"""
|
||||||
|
:root {{
|
||||||
|
{br.join([f"/* {color['comment']} */{br}--{name.lower().replace('_', '-')}: {color['light']};" for name, color in colors.__dict__.items() if name != "__builtins__" and isinstance(color, dict)])}
|
||||||
|
}}
|
||||||
|
:root[class*=night-mode] {{
|
||||||
|
{br.join([f"/* {color['comment']} */{br}--{name.lower().replace('_', '-')}: {color['dark']};" for name, color in colors.__dict__.items() if name != "__builtins__" and isinstance(color, dict)])}
|
||||||
|
}}
|
||||||
|
:root {{
|
||||||
|
{br.join([f"/* {prop['comment']} */{br}--{name.lower().replace('_', '-')}: {prop['light']};" for name, prop in props.__dict__.items() if name != "__builtins__" and isinstance(prop, dict)])}
|
||||||
|
}}
|
||||||
|
:root[class*=night-mode] {{
|
||||||
|
{br.join([f"/* {prop['comment']} */{br}--{name.lower().replace('_', '-')}: {prop['dark']};" for name, prop in props.__dict__.items() if name != "__builtins__" and isinstance(prop, dict)])}
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
def stdHtml(
|
def stdHtml(
|
||||||
self,
|
self,
|
||||||
body: str,
|
body: str,
|
||||||
|
@ -478,13 +494,13 @@ html {{ {font} }}
|
||||||
|
|
||||||
gui_hooks.webview_will_set_content(web_content, context)
|
gui_hooks.webview_will_set_content(web_content, context)
|
||||||
|
|
||||||
csstxt = ""
|
csstxt = f'<style id="vars">{self.css_vars()}</style>'
|
||||||
if "css/webview.css" in css:
|
if "css/webview.css" in css:
|
||||||
# we want our dynamic styling to override the defaults in
|
# we want our dynamic styling to override the defaults in
|
||||||
# css/webview.css, but come before user-provided stylesheets so that
|
# css/webview.css, but come before user-provided stylesheets so that
|
||||||
# they can override us if necessary
|
# they can override us if necessary
|
||||||
web_content.css.remove("css/webview.css")
|
web_content.css.remove("css/webview.css")
|
||||||
csstxt = self.bundledCSS("css/webview.css")
|
csstxt += self.bundledCSS("css/webview.css")
|
||||||
csstxt += f"<style>{self.standard_css()}</style>"
|
csstxt += f"<style>{self.standard_css()}</style>"
|
||||||
|
|
||||||
csstxt += "\n".join(self.bundledCSS(fname) for fname in web_content.css)
|
csstxt += "\n".join(self.bundledCSS(fname) for fname in web_content.css)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@use "vars" as *;
|
@use "vars" as *;
|
||||||
@use "root-vars";
|
|
||||||
@use "scrollbar";
|
@use "scrollbar";
|
||||||
@use "button-mixins" as button;
|
@use "button-mixins" as button;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
@use "root-vars";
|
|
||||||
@use "sass/button-mixins" as button;
|
@use "sass/button-mixins" as button;
|
||||||
|
|
||||||
label,
|
label,
|
||||||
|
|
Loading…
Reference in a new issue