试图移植
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
from textual.app import ComposeResult
|
||||
from textual.widgets import (
|
||||
Header,
|
||||
Footer,
|
||||
Label,
|
||||
ListView,
|
||||
ListItem,
|
||||
Button,
|
||||
Static,
|
||||
)
|
||||
from textual.containers import Container
|
||||
from textual.screen import Screen
|
||||
|
||||
from heurams.kernel.particles import *
|
||||
from heurams.context import *
|
||||
|
||||
class DashboardScreen(Screen):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
yield Container(
|
||||
Label(f'欢迎使用 "潜进" 启发式辅助记忆调度器', classes="title-label"),
|
||||
Label(f"当前的 UNIX 日时间戳: 0"),
|
||||
Label(f'包含时间戳修正: UTC+0'),
|
||||
Label("选择待学习或待修改的记忆单元集:", classes="title-label"),
|
||||
ListView(id="union-list", classes="union-list-view"),
|
||||
Label(f'"潜进" 开放源代码软件项目 | 版本 0.0.1 | Wang Zhiyu 2025'),
|
||||
)
|
||||
yield Footer()
|
||||
|
||||
def item_desc_generator(self, path) -> dict:
|
||||
res = dict()
|
||||
res[0] = f"{path.name}\0"
|
||||
res[1] = f""
|
||||
res[1] = " 尚未激活"
|
||||
return res
|
||||
|
||||
def on_mount(self) -> None:
|
||||
union_list_widget = self.query_one("#union-list", ListView)
|
||||
probe = probe_all(0)
|
||||
|
||||
if len(probe["nucleon"]):
|
||||
for file in probe["nucleon"]:
|
||||
text = self.item_desc_generator(file)
|
||||
union_list_widget.append(ListItem(
|
||||
Label(text[0] + '\n' + text[1]),
|
||||
))
|
||||
else:
|
||||
union_list_widget.append(
|
||||
ListItem(Static("在 ./nucleon/ 中未找到任何内容源数据文件.\n请放置文件后重启应用.\n或者新建空的单元集."))
|
||||
)
|
||||
union_list_widget.disabled = True
|
||||
|
||||
def on_list_view_selected(self, event) -> None:
|
||||
if not isinstance(event.item, ListItem):
|
||||
return
|
||||
|
||||
selected_label = event.item.query_one(Label)
|
||||
if "未找到任何 .toml 文件" in str(selected_label.renderable):
|
||||
return
|
||||
|
||||
selected_filename = str(selected_label.renderable).partition('\0')[0].replace('*', "")
|
||||
# 这里需要导入相应的文件处理逻辑
|
||||
# nucleon_file = pt.NucleonUnion(pathlib.Path("./nucleon") / selected_filename)
|
||||
# electron_file_path = pathlib.Path("./electron") / selected_filename
|
||||
# if electron_file_path.exists():
|
||||
# pass
|
||||
# else:
|
||||
# electron_file_path.touch()
|
||||
# electron_file = pt.ElectronUnion(pathlib.Path("./electron") / selected_filename)
|
||||
# self.app.push_screen(PreparationScreen(nucleon_file, electron_file))
|
||||
|
||||
def on_button_pressed(self, event) -> None:
|
||||
if event.button.id == "new_nucleon_button":
|
||||
from .nucleon_creator import NucleonCreatorScreen
|
||||
newscr = NucleonCreatorScreen()
|
||||
self.app.push_screen(newscr)
|
||||
elif event.button.id == "precache_all_button":
|
||||
self.action_precache_all()
|
||||
|
||||
def action_precache_all(self):
|
||||
"""预缓存所有单元集的音频"""
|
||||
from .precache import PrecachingScreen
|
||||
precache_screen = PrecachingScreen()
|
||||
self.app.push_screen(precache_screen)
|
||||
|
||||
def action_quit_app(self) -> None:
|
||||
self.app.exit()
|
||||
Reference in New Issue
Block a user