From e0417981b1fe75ec3c28e2fb15ec2939b6f27f94 Mon Sep 17 00:00:00 2001 From: david-ajax Date: Sun, 21 Dec 2025 06:06:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(interface):=20=E6=9B=B4=E6=94=B9=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.toml | 2 +- pyproject.toml | 1 + src/heurams/interface/__init__.py | 60 +++++++++++++++++++++++ src/heurams/interface/__main__.py | 79 ++----------------------------- 4 files changed, 66 insertions(+), 76 deletions(-) create mode 100644 src/heurams/interface/__init__.py diff --git a/config/config.toml b/config/config.toml index afab582..fc60ff8 100644 --- a/config/config.toml +++ b/config/config.toml @@ -17,7 +17,7 @@ timezone_offset = +28800 # 中国标准时间 (UTC+8) [interface] [interface.memorizor] -autovoice = false # 自动语音播放, 仅限于 recognition 组件 +autovoice = true # 自动语音播放, 仅限于 recognition 组件 [puzzles] # 谜题默认配置 diff --git a/pyproject.toml b/pyproject.toml index a3b3e4d..0156761 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,3 +25,4 @@ readme = "README.md" [tool.setuptools.packages.find] where = ["src"] + diff --git a/src/heurams/interface/__init__.py b/src/heurams/interface/__init__.py new file mode 100644 index 0000000..0a6bb1a --- /dev/null +++ b/src/heurams/interface/__init__.py @@ -0,0 +1,60 @@ +from textual.app import App +from textual.widgets import Button + +from heurams.context import config_var +from heurams.services.logger import get_logger + +from .screens.about import AboutScreen +from .screens.dashboard import DashboardScreen +from .screens.nucreator import NucleonCreatorScreen +from .screens.precache import PrecachingScreen + +logger = get_logger(__name__) + + +def environment_check(): + from pathlib import Path + + logger.debug("检查环境路径") + + for i in config_var.get()["paths"].values(): + i = Path(i) + if not i.exists(): + logger.info("创建目录: %s", i) + print(f"创建 {i}") + i.mkdir(exist_ok=True, parents=True) + else: + logger.debug("目录已存在: %s", i) + print(f"找到 {i}") + logger.debug("环境检查完成") + + +class HeurAMSApp(App): + TITLE = "潜进" + CSS_PATH = "css/main.tcss" + SUB_TITLE = "启发式辅助记忆调度器" + BINDINGS = [ + ("q", "quit", "退出"), + ("d", "toggle_dark", "切换色调"), + ("1", "app.push_screen('dashboard')", "仪表盘"), + ("2", "app.push_screen('precache_all')", "缓存管理器"), + ("3", "app.push_screen('nucleon_creator')", "创建新单元"), + ("0", "app.push_screen('about')", "版本信息"), + ] + SCREENS = { + "dashboard": DashboardScreen, + "nucleon_creator": NucleonCreatorScreen, + "precache_all": PrecachingScreen, + "about": AboutScreen, + } + + def on_mount(self) -> None: + environment_check() + self.push_screen("dashboard") + + def on_button_pressed(self, event: Button.Pressed) -> None: + self.exit(event.button.id) + + def action_do_nothing(self): + print("DO NOTHING") + self.refresh() diff --git a/src/heurams/interface/__main__.py b/src/heurams/interface/__main__.py index 789f9d0..cf62f5a 100644 --- a/src/heurams/interface/__main__.py +++ b/src/heurams/interface/__main__.py @@ -2,6 +2,8 @@ from textual.app import App from textual.widgets import Button from heurams.services.logger import get_logger +from heurams.context import config_var +from heurams.interface import HeurAMSApp from .screens.about import AboutScreen from .screens.dashboard import DashboardScreen @@ -10,80 +12,7 @@ from .screens.precache import PrecachingScreen logger = get_logger(__name__) - -class HeurAMSApp(App): - TITLE = "潜进" - CSS_PATH = "css/main.tcss" - SUB_TITLE = "启发式辅助记忆调度器" - BINDINGS = [ - ("q", "quit", "退出"), - ("d", "toggle_dark", "切换色调"), - ("1", "app.push_screen('dashboard')", "仪表盘"), - ("2", "app.push_screen('precache_all')", "缓存管理器"), - ("3", "app.push_screen('nucleon_creator')", "创建新单元"), - ("0", "app.push_screen('about')", "版本信息"), - ] - SCREENS = { - "dashboard": DashboardScreen, - "nucleon_creator": NucleonCreatorScreen, - "precache_all": PrecachingScreen, - "about": AboutScreen, - } - - def on_mount(self) -> None: - self.push_screen("dashboard") - - def on_button_pressed(self, event: Button.Pressed) -> None: - self.exit(event.button.id) - - def action_do_nothing(self): - print("DO NOTHING") - self.refresh() - - -def environment_check(): - from pathlib import Path - - logger.debug("检查环境路径") - - for i in config_var.get()["paths"].values(): - i = Path(i) - if not i.exists(): - logger.info("创建目录: %s", i) - print(f"创建 {i}") - i.mkdir(exist_ok=True, parents=True) - else: - logger.debug("目录已存在: %s", i) - print(f"找到 {i}") - logger.debug("环境检查完成") - - -def is_subdir(parent, child): - try: - child.relative_to(parent) - logger.debug("is_subdir: %s 是 %s 的子目录", child, parent) - return 1 - except: - logger.debug("is_subdir: %s 不是 %s 的子目录", child, parent) - return 0 - - -import os -from pathlib import Path - -# 开发模式 -from heurams.context import config_var, rootdir, workdir - -if is_subdir(Path(rootdir), Path(os.getcwd())): - os.chdir(Path(rootdir) / ".." / "..") - print(f'转入开发数据目录: {Path(rootdir)/".."/".."}') - -environment_check() - app = HeurAMSApp() + if __name__ == "__main__": - app.run() - - -def main(): - app.run() + app.run() \ No newline at end of file