refactor: 对配置处理器和配置结构进行重构

This commit is contained in:
2026-04-20 01:44:43 +08:00
parent 5c43059518
commit a38fd3d398
36 changed files with 1097 additions and 917 deletions

View File

@@ -58,8 +58,8 @@ class DashboardScreen(Screen):
Label(
f"当前 UNIX 日时间戳: {timer.get_daystamp()}"
),
Label(f"应用时区修正: UTC+{config_var.get()['timezone_offset'] / 3600}"),
Label(f"全局算法设置: {config_var.get()['algorithm']['default']}: {algorithms[config_var.get()['algorithm']['default']].desc}"),
Label(f"应用时区修正: UTC+{config_var.get()['services']['timer']['timezone_offset'] / 3600}"),
Label(f"全局算法设置: {config_var.get()['interface']['global']['algorithm']}: {algorithms[config_var.get()['interface']['global']['algorithm']].desc}"),
classes="column infview",
),
Vertical(
@@ -78,7 +78,7 @@ class DashboardScreen(Screen):
def _load_data(self):
self.repo_dirs = Repo.probe_valid_repos_in_dir(
Path(config_var.get()["paths"]["data"]) / "repo"
Path(config_var.get()['global']["paths"]["data"]) / "repo"
)
for repo_dir in self.repo_dirs:
repo = Repo.create_from_repodir(repo_dir)

View File

@@ -115,7 +115,7 @@ class FavoriteManagerScreen(Screen):
def _get_repo_info(self, repo_path: str, fav: FavoriteItem) -> Optional[dict]:
"""获取仓库信息(标题、原子内容预览)"""
try:
data_repo = Path(config_var.get()["paths"]["data"]) / "repo"
data_repo = Path(config_var.get()['global']["paths"]["data"]) / "repo"
repo_dir = data_repo / repo_path
if not repo_dir.exists():
logger.warning("仓库目录不存在: %s", repo_dir)

View File

@@ -38,7 +38,7 @@ class MemScreen(Screen):
("0,1,2,3", "app.push_screen('about')", ""),
]
if config_var.get()["quick_pass"]:
if config_var.get()['interface']['global']["quick_pass"]:
BINDINGS.append(("k", "quick_pass", "正确应答"))
BINDINGS.append(("f", "quick_fail", "错误应答"))
rating = reactive(-1)
@@ -93,7 +93,7 @@ class MemScreen(Screen):
if self.repo is not None:
fav_status = "已收藏" if self._is_current_atom_favorited() else "未收藏"
s += f"收藏: {fav_status}\n"
if config_var.get().get("debug_topline", 0):
'''if config_var.get().get("debug_topline", 0):
try:
alia = self.fission.get_current_puzzle_inf()["alia"] # type: ignore
s += f"谜题: {alia}\n"
@@ -113,7 +113,7 @@ class MemScreen(Screen):
stat = self.fission.__repr__("simple", "")
s += f"{stat}\n"
except Exception as e:
s = str(e)
s = str(e)'''
s += f"进度: {self.procession.process() + 1}/{self.procession.total_length()}"
return s
@@ -139,9 +139,9 @@ class MemScreen(Screen):
i.remove()
from heurams.interface.widgets.finished import Finished
if config_var.get().get("persist_to_file", 0):
if config_var.get()['interface']['global']["persist_to_file"]:
self.save_func()
container.mount(Finished(is_saved=config_var.get().get("persist_to_file", 0)))
container.mount(Finished(is_saved=['interface']['global']["persist_to_file"]))
def on_button_pressed(self, event):
event.stop()
@@ -156,7 +156,7 @@ class MemScreen(Screen):
from heurams.services.audio_service import play_by_path
from heurams.services.hasher import get_md5
path = Path(config_var.get()["paths"]["data"]) / "cache" / "voice"
path = Path(config_var.get()['global']["paths"]["data"]) / "cache" / "voice"
path = path / f"{get_md5(self.atom.registry['nucleon']["tts_text"])}.wav"
if path.exists():
play_by_path(path)
@@ -226,7 +226,7 @@ class MemScreen(Screen):
return ""
# self.repo.source 是 Path 对象,指向仓库目录
repo_full_path = self.repo.source
data_repo_path = Path(config_var.get()["paths"]["data"]) / "repo"
data_repo_path = Path(config_var.get()['global']["paths"]["data"]) / "repo"
try:
rel_path = repo_full_path.relative_to(data_repo_path)
return str(rel_path)

View File

@@ -13,7 +13,7 @@ import heurams.services.hasher as hasher
from heurams.context import *
# 兼容性缓存路径:优先使用 paths.cache否则使用 data/cache
paths = config_var.get()["paths"]
paths = config_var.get()['global']["paths"]
cache_dir = pathlib.Path(paths.get("cache", paths["data"] + "/cache")) / "voice"
@@ -61,7 +61,7 @@ class PrecachingScreen(Screen):
"""获取所有仓库的总单元数"""
from heurams.context import config_var
from heurams.kernel.repolib import Repo
repo_path = pathlib.Path(config_var.get()["paths"]["data"]) / "repo"
repo_path = pathlib.Path(config_var.get()['global']["paths"]["data"]) / "repo"
repo_dirs = Repo.probe_valid_repos_in_dir(repo_path)
repos = map(Repo.create_from_repodir, repo_dirs)
total = 0
@@ -230,7 +230,7 @@ class PrecachingScreen(Screen):
from heurams.context import config_var, rootdir, workdir
from heurams.kernel.repolib import Repo
repo_path = pathlib.Path(config_var.get()["paths"]["data"]) / "repo"
repo_path = pathlib.Path(config_var.get()['global']["paths"]["data"]) / "repo"
repo_dirs = Repo.probe_valid_repos_in_dir(repo_path)
repos = map(Repo.create_from_repodir, repo_dirs)

View File

@@ -28,7 +28,7 @@ class PreparationScreen(Screen):
("0,1,2,3", "app.push_screen('about')", ""),
]
scheduled_num = reactive(config_var.get()["scheduled_num"])
scheduled_num = reactive(config_var.get()['interface']['global']["scheduled_num"])
def __init__(self, repo: Repo, repostat: dict) -> None:
super().__init__(name=None, id=None, classes=None)
@@ -41,7 +41,7 @@ class PreparationScreen(Screen):
with ScrollableContainer(id="vice_container"):
yield Label(f"准备就绪: [b]{self.repostat['title']}[/b]\n")
yield Label(
f"仓库路径: {config_var.get()['paths']['data']}/repo/[b]{self.repostat['dirname']}[/b]"
f"仓库路径: {config_var.get()['global']['paths']['data']}/repo/[b]{self.repostat['dirname']}[/b]"
)
yield Label(f"\n单元数量: {len(self.repo)}\n")
yield Label(f"最小记忆分组: {self.scheduled_num}\n", id="schnum_label")
@@ -130,7 +130,7 @@ class PreparationScreen(Screen):
def launch(repo, app, scheduled_num):
if scheduled_num == -1:
scheduled_num = config_var.get()["scheduled_num"]
scheduled_num = config_var.get()['interface']['global']["scheduled_num"]
atoms = list()
for i in repo.ident_index:
n = pt.Nucleon.create_on_nucleonic_data(