更新用户界面, 修复总复习

This commit is contained in:
2025-09-14 01:54:33 +08:00
parent 50a5b9b108
commit 19d0e32b6f
12 changed files with 93 additions and 49 deletions

View File

@@ -7,6 +7,7 @@ from textual.widgets import (
DirectoryTree,
ListItem,
Label,
Markdown,
Static,
Button,
)
@@ -17,7 +18,7 @@ import threading
import edge_tts as tts
from playsound import playsound
import particles as pt
from reactor import Reactor, Apparatus
from reactor import Reactor, Apparatus, Glimpse
import auxiliary as aux
import compositions as compo
import builtins
@@ -45,7 +46,13 @@ class MemScreen(Screen):
self.reactor = Reactor(nucleon_file, electron_file, self, tasked_num)
self.stage = 1
self.stage += self.reactor.set_round_templated(self.stage)
self.reactor.forward()
first_forward = self.reactor.forward()
print(first_forward)
if first_forward == -1:
self.stage = 3
self.reactor.set_round_templated(3)
print(self.reactor.forward())
#self._forward_judge(first_forward)
self.compo = next(self.reactor.current_appar)
def compose(self) -> ComposeResult:
@@ -184,28 +191,47 @@ class PreparationScreen(Screen):
)
self.app.push_screen(newscr)
class FileSelectorScreen(Screen):
class DashboardScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(show_clock=True)
yield Container(
Label(f'欢迎使用 "潜进" 辅助记忆软件, 版本 {metadata.ver}', classes="title-label"),
Label("选择要学习的文件:", classes="title-label"),
Label(f'欢迎使用 "潜进" 启发式辅助记忆调度器, 版本 {metadata.ver}', classes="title-label"),
Label(f"当前的 UNIX 日时间戳: {aux.get_daystamp()}"),
Label("选择待学习的记忆单元:", classes="title-label"),
ListView(id="file-list", classes="file-list-view"),
Label(f"\"潜进\" 开放源代码软件项目 | 版本 {metadata.ver} {metadata.stage.capitalize()} | Wang Zhiyu 2025"),
)
yield Footer()
def item_desc_generator(self, path) -> dict:
gmp = Glimpse(pt.NucleonUnion(path))
res = dict()
res[0] = f"{gmp.name}.toml\0"
res[1] = f""
if gmp.is_initialized:
res[1] += f" 已激活单元: {gmp.activated_num}/{gmp.total_num}\n"
res[1] += f" 下一次复习: {gmp.next_date} (最后复习于 {gmp.lastest_date})\n"
res[1] += f" 系数均值: {gmp.avg_efactor}"
else:
res[1] = " 尚未激活"
return res
def on_mount(self) -> None:
file_list_widget = self.query_one("#file-list", ListView)
nucleon_path = pathlib.Path("./nucleon")
nucleon_files = sorted(
[f.name for f in nucleon_path.iterdir() if f.suffix == ".toml"]
[f for f in nucleon_path.iterdir() if f.suffix == ".toml"],
key=lambda f: Glimpse(pt.NucleonUnion(f)).next_date,
reverse=True
)
if nucleon_files:
for filename in nucleon_files:
file_list_widget.append(ListItem(Label(filename)))
for file in nucleon_files:
text = self.item_desc_generator(pathlib.Path(file))
file_list_widget.append(ListItem(
Label(text[0]),
Label(text[1]),
))
else:
file_list_widget.append(
ListItem(Static("在 ./nucleon/ 中未找到任何核子文件. 请放置文件后重启应用."))
@@ -220,7 +246,7 @@ class FileSelectorScreen(Screen):
if "未找到任何 .toml 文件" in str(selected_label.renderable):
return
selected_filename = str(selected_label.renderable)
selected_filename = str(selected_label.renderable).partition('\0')[0].replace('*', "")
nucleon_file = pt.NucleonUnion(
pathlib.Path("./nucleon") / selected_filename
)