70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import flet as ft
|
|
import designer as d
|
|
|
|
_ui_text = ft.TextTheme(
|
|
body_medium=ft.TextStyle(font_family=d.FONT_UI),
|
|
body_large=ft.TextStyle(font_family=d.FONT_UI),
|
|
body_small=ft.TextStyle(font_family=d.FONT_UI),
|
|
label_large=ft.TextStyle(font_family=d.FONT_UI),
|
|
label_medium=ft.TextStyle(font_family=d.FONT_UI),
|
|
label_small=ft.TextStyle(font_family=d.FONT_UI),
|
|
title_large=ft.TextStyle(font_family=d.FONT_UI, weight=ft.FontWeight.W_600),
|
|
title_medium=ft.TextStyle(font_family=d.FONT_UI, weight=ft.FontWeight.W_500),
|
|
title_small=ft.TextStyle(font_family=d.FONT_UI),
|
|
)
|
|
|
|
THEMES = {
|
|
"light": ft.Theme(
|
|
color_scheme_seed=d.PRIMARY,
|
|
color_scheme=ft.ColorScheme(
|
|
primary=d.PRIMARY,
|
|
secondary=d.ACCENT,
|
|
background=d.BACKGROUND,
|
|
surface=d.SURFACE,
|
|
),
|
|
text_theme=_ui_text,
|
|
),
|
|
"dark": ft.Theme(
|
|
color_scheme_seed=d.PRIMARY,
|
|
color_scheme=ft.ColorScheme(
|
|
primary=d.PRIMARY_LIGHT,
|
|
secondary=d.ACCENT,
|
|
background="#121212",
|
|
surface="#1E1E1E",
|
|
on_surface=ft.colors.WHITE,
|
|
),
|
|
text_theme=_ui_text,
|
|
),
|
|
}
|
|
|
|
|
|
def apply(page: ft.Page, theme_id: str = "light"):
|
|
theme = THEMES.get(theme_id, THEMES["light"])
|
|
if theme_id == "dark":
|
|
page.theme_mode = ft.ThemeMode.DARK
|
|
page.dark_theme = theme
|
|
else:
|
|
page.theme_mode = ft.ThemeMode.LIGHT
|
|
page.theme = theme
|
|
|
|
|
|
def apply_article_font(page: ft.Page, font_family: str):
|
|
"""Temporarily override body text font for article reading view."""
|
|
article_text = ft.TextTheme(
|
|
body_medium=ft.TextStyle(font_family=font_family, size=16, height=1.7),
|
|
body_large=ft.TextStyle(font_family=font_family, size=18, height=1.7),
|
|
body_small=ft.TextStyle(font_family=font_family),
|
|
)
|
|
if page.theme:
|
|
page.theme.text_theme = article_text
|
|
else:
|
|
page.theme = ft.Theme(text_theme=article_text)
|
|
page.update()
|
|
|
|
|
|
def reset_font(page: ft.Page):
|
|
"""Restore default UI font after leaving article view."""
|
|
if page.theme:
|
|
page.theme.text_theme = _ui_text
|
|
page.update()
|