改进
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
from textual.app import App
|
||||
import screens
|
||||
import os
|
||||
|
||||
class AppLauncher(App):
|
||||
CSS_PATH = "styles.css"
|
||||
TITLE = "潜进 - 辅助记忆调度器"
|
||||
BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")]
|
||||
SCREENS = {
|
||||
"dashboard": screens.DashboardScreen,
|
||||
}
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.push_screen("dashboard")
|
||||
|
||||
if __name__ == "__main__":
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(script_dir)
|
||||
os.makedirs("electron", exist_ok=True)
|
||||
os.makedirs("nucleon", exist_ok=True)
|
||||
os.makedirs("cache/voice", exist_ok=True)
|
||||
app = AppLauncher()
|
||||
app.run()
|
||||
@@ -19,22 +19,13 @@ class HeurAMSApp(App):
|
||||
"dashboard": DashboardScreen,
|
||||
"nucleon_creator": NucleonCreatorScreen,
|
||||
"precache_all": PrecachingScreen,
|
||||
"preparation": PreparationScreen, # type: ignore
|
||||
"memscreen": MemScreen, # type: ignore
|
||||
}
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock = True)
|
||||
|
||||
yield Footer(show_command_palette = True)
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.push_screen("dashboard")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = HeurAMSApp()
|
||||
app.run()
|
||||
app = HeurAMSApp()
|
||||
app.run()
|
||||
@@ -14,6 +14,9 @@ from textual.screen import Screen
|
||||
|
||||
from heurams.kernel.particles import *
|
||||
from heurams.context import *
|
||||
import heurams.services.version as version
|
||||
import heurams.services.timer as timer
|
||||
from .preparation import PreparationScreen
|
||||
|
||||
class DashboardScreen(Screen):
|
||||
|
||||
@@ -21,16 +24,17 @@ class DashboardScreen(Screen):
|
||||
yield Header(show_clock=True)
|
||||
yield Container(
|
||||
Label(f'欢迎使用 "潜进" 启发式辅助记忆调度器', classes="title-label"),
|
||||
Label(f"当前的 UNIX 日时间戳: 0"),
|
||||
Label(f'包含时间戳修正: UTC+0'),
|
||||
Label(f"当前的 UNIX 日时间戳: {timer.get_daystamp()}"),
|
||||
Label(f'时区修正: UTC+{config_var.get()["timezone_offset"] / 3600}'),
|
||||
Label("选择待学习或待修改的记忆单元集:", classes="title-label"),
|
||||
ListView(id="union-list", classes="union-list-view"),
|
||||
Label(f'"潜进" 开放源代码软件项目 | 版本 0.0.1 | Wang Zhiyu 2025'),
|
||||
Label(f'"潜进" 开放源代码软件项目 | 版本 {version.ver} {version.codename.capitalize()} | Wang Zhiyu 2025'),
|
||||
)
|
||||
yield Footer()
|
||||
|
||||
def item_desc_generator(self, path) -> dict:
|
||||
res = dict()
|
||||
path = pathlib.Path(path)
|
||||
res[0] = f"{path.name}\0"
|
||||
res[1] = f""
|
||||
res[1] = " 尚未激活"
|
||||
@@ -60,16 +64,17 @@ class DashboardScreen(Screen):
|
||||
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))
|
||||
selected_filename = pathlib.Path(str(selected_label.renderable).partition('\0')[0].replace('*', ""))
|
||||
|
||||
nucleon_file_path = pathlib.Path(config_var.get()["paths"]["nucleon_dir"]) / selected_filename
|
||||
electron_file_path = pathlib.Path(config_var.get()["paths"]["electron_dir"]) / (str(selected_filename.stem) + ".json")
|
||||
if electron_file_path.exists():
|
||||
pass
|
||||
else:
|
||||
electron_file_path.touch()
|
||||
with open(electron_file_path, 'w') as f:
|
||||
f.write("{}")
|
||||
self.app.push_screen(PreparationScreen(nucleon_file_path, electron_file_path))
|
||||
|
||||
def on_button_pressed(self, event) -> None:
|
||||
if event.button.id == "new_nucleon_button":
|
||||
|
||||
@@ -28,7 +28,8 @@ class PreparationScreen(Screen):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.nucleon_file = nucleon_file
|
||||
self.electron_file = electron_file
|
||||
self.nucleon_union = pt.load_nucleon(self.nucleon_file)
|
||||
self.nucleons_with_orbital = pt.load_nucleon(self.nucleon_file)
|
||||
self.electrons = pt.load_electron(self.electron_file)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
@@ -36,7 +37,7 @@ class PreparationScreen(Screen):
|
||||
yield Label(f"准备就绪: [b]{self.nucleon_file.stem}[/b]\n")
|
||||
yield Label(f"内容源文件对象: ./nucleon/[b]{self.nucleon_file.name}[/b].toml")
|
||||
yield Label(f"元数据文件对象: ./electron/[b]{self.electron_file.name}[/b].toml")
|
||||
yield Label(f"\n单元数量:{len(self.nucleon_union)}\n")
|
||||
yield Label(f"\n单元数量:{len(self.nucleons_with_orbital)}\n")
|
||||
|
||||
yield Button(
|
||||
"开始记忆",
|
||||
@@ -57,8 +58,10 @@ class PreparationScreen(Screen):
|
||||
|
||||
def _get_full_content(self):
|
||||
content = ""
|
||||
for i in self.nucleon_union:
|
||||
content += " - " + i["content"] + " \n"
|
||||
for nucleon, orbital in self.nucleons_with_orbital:
|
||||
nucleon: pt.Nucleon
|
||||
print(nucleon.payload)
|
||||
content += " - " + nucleon["content"] + " \n"
|
||||
return content
|
||||
|
||||
def action_go_back(self):
|
||||
@@ -74,10 +77,24 @@ class PreparationScreen(Screen):
|
||||
|
||||
def on_button_pressed(self, event) -> None:
|
||||
if event.button.id == "start_memorizing_button":
|
||||
atoms = list()
|
||||
for nucleon, orbital in self.nucleons_with_orbital:
|
||||
atom = pt.Atom(nucleon.ident)
|
||||
atom.link("nucleon", nucleon)
|
||||
try:
|
||||
atom.link("electron", self.electrons[nucleon.ident])
|
||||
except KeyError:
|
||||
atom.link("electron", pt.Electron(nucleon.ident))
|
||||
atom.link("orbital", orbital)
|
||||
atom.link("nucleon_fmt", "toml")
|
||||
atom.link("electron_fmt", "json")
|
||||
atom.link("orbital_fmt", "toml")
|
||||
atom.link("nucleon_path", self.nucleon_file)
|
||||
atom.link("electron_path", self.electron_file)
|
||||
atom.link("orbital_path", None)
|
||||
atoms.append(atom)
|
||||
from .memorizor import MemScreen
|
||||
newscr = MemScreen(
|
||||
self.nucleon_file, self.electron_file, 6
|
||||
)
|
||||
self.app.push_screen(newscr)
|
||||
memscreen = MemScreen(atoms)
|
||||
self.app.push_screen(memscreen)
|
||||
elif event.button.id == "precache_button":
|
||||
self.action_precache()
|
||||
0
src/heurams/interface/screens/type43.py
Normal file
0
src/heurams/interface/screens/type43.py
Normal file
@@ -8,19 +8,34 @@ import json
|
||||
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
toml.load(f, dictdata) # type: ignore
|
||||
dictdata = toml.load(f) # type: ignore
|
||||
lst = list()
|
||||
for item, attr in dictdata.items():
|
||||
nested_data = dict()
|
||||
# 修正 toml 解析器的不管嵌套行为
|
||||
for key, value in dictdata.items():
|
||||
if "__metadata__" in key: # 以免影响句号
|
||||
if '.' in key:
|
||||
parts = key.split('.')
|
||||
current = nested_data
|
||||
for part in parts[:-1]:
|
||||
if part not in current:
|
||||
current[part] = {}
|
||||
current = current[part]
|
||||
current[parts[-1]] = value
|
||||
else:
|
||||
nested_data[key] = value
|
||||
# print(nested_data)
|
||||
for item, attr in nested_data.items():
|
||||
if item == "__metadata__":
|
||||
continue
|
||||
lst.append((Nucleon(hasher.hash(item), attr), dictdata["__metadata__"]["orbital"]))
|
||||
lst.append((Nucleon(hasher.hash(item), attr), nested_data["__metadata__"]["orbital"]))
|
||||
return lst
|
||||
|
||||
def load_electron(path: pathlib.Path, fmt = "json"):
|
||||
def load_electron(path: pathlib.Path, fmt = "json") -> dict:
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
json.load(f, dictdata) # type: ignore
|
||||
lst = list()
|
||||
dictdata = json.load(f) # type: ignore
|
||||
dic = dict()
|
||||
for item, attr in dictdata.items():
|
||||
lst.append(Electron(hasher.hash(item), attr))
|
||||
return lst
|
||||
dic["item"] = (Electron(hasher.hash(item), attr))
|
||||
return dic
|
||||
@@ -1,4 +1,4 @@
|
||||
from base import BasePuzzle
|
||||
from .base import BasePuzzle
|
||||
import random
|
||||
|
||||
class ClozePuzzle(BasePuzzle):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# mcq.py
|
||||
from base import BasePuzzle
|
||||
from .base import BasePuzzle
|
||||
import random
|
||||
|
||||
class MCQPuzzle(BasePuzzle):
|
||||
|
||||
Reference in New Issue
Block a user