feat(config): Implement parsing for shader and window frame configurations
This commit is contained in:
19
src/theme.py
19
src/theme.py
@@ -268,6 +268,12 @@ _current_palette: str = "DPG Default"
|
|||||||
_current_font_path: str = ""
|
_current_font_path: str = ""
|
||||||
_current_font_size: float = 14.0
|
_current_font_size: float = 14.0
|
||||||
_current_scale: float = 1.0
|
_current_scale: float = 1.0
|
||||||
|
_shader_config: dict[str, Any] = {
|
||||||
|
"crt": False,
|
||||||
|
"bloom": False,
|
||||||
|
"bg": "none",
|
||||||
|
"custom_window_frame": False,
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------ public API
|
# ------------------------------------------------------------------ public API
|
||||||
|
|
||||||
@@ -286,6 +292,14 @@ def get_current_font_size() -> float:
|
|||||||
def get_current_scale() -> float:
|
def get_current_scale() -> float:
|
||||||
return _current_scale
|
return _current_scale
|
||||||
|
|
||||||
|
def get_shader_config(key: str) -> Any:
|
||||||
|
"""Get a specific shader configuration value."""
|
||||||
|
return _shader_config.get(key)
|
||||||
|
|
||||||
|
def get_window_frame_config() -> bool:
|
||||||
|
"""Get the window frame configuration."""
|
||||||
|
return _shader_config.get("custom_window_frame", False)
|
||||||
|
|
||||||
def get_palette_colours(name: str) -> dict[str, Any]:
|
def get_palette_colours(name: str) -> dict[str, Any]:
|
||||||
"""Return a copy of the colour dict for the named palette."""
|
"""Return a copy of the colour dict for the named palette."""
|
||||||
return dict(_PALETTES.get(name, {}))
|
return dict(_PALETTES.get(name, {}))
|
||||||
@@ -388,4 +402,9 @@ def load_from_config(config: dict[str, Any]) -> None:
|
|||||||
if font_path:
|
if font_path:
|
||||||
apply_font(font_path, font_size)
|
apply_font(font_path, font_size)
|
||||||
set_scale(scale)
|
set_scale(scale)
|
||||||
|
global _shader_config
|
||||||
|
_shader_config["crt"] = t.get("shader_crt", False)
|
||||||
|
_shader_config["bloom"] = t.get("shader_bloom", False)
|
||||||
|
_shader_config["bg"] = t.get("shader_bg", "none")
|
||||||
|
_shader_config["custom_window_frame"] = t.get("custom_window_frame", False)
|
||||||
|
|
||||||
|
|||||||
23
tests/test_shader_config.py
Normal file
23
tests/test_shader_config.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest.mock import patch
|
||||||
|
from src import theme
|
||||||
|
|
||||||
|
def test_shader_config_parsing():
|
||||||
|
config = {
|
||||||
|
"theme": {
|
||||||
|
"shader_crt": True,
|
||||||
|
"shader_bloom": False,
|
||||||
|
"shader_bg": "noise",
|
||||||
|
"custom_window_frame": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch("src.theme.apply"), \
|
||||||
|
patch("src.theme.apply_font"), \
|
||||||
|
patch("src.theme.set_scale"):
|
||||||
|
theme.load_from_config(config)
|
||||||
|
|
||||||
|
assert theme.get_shader_config("crt") is True
|
||||||
|
assert theme.get_shader_config("bloom") is False
|
||||||
|
assert theme.get_shader_config("bg") == "noise"
|
||||||
|
assert theme.get_window_frame_config() is True
|
||||||
Reference in New Issue
Block a user