使用 NucleonUnion & ElectronUnion 取代繁琐的 AtomicFiles
This commit is contained in:
20
main.py
20
main.py
@@ -37,8 +37,8 @@ class MemScreen(Screen):
|
||||
btn = dict()
|
||||
def __init__(
|
||||
self,
|
||||
nucleon_file: pt.AtomicFile,
|
||||
electron_file: pt.AtomicFile,
|
||||
nucleon_file: pt.NucleonUnion,
|
||||
electron_file: pt.ElectronUnion,
|
||||
tasked_num
|
||||
):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
@@ -147,7 +147,7 @@ class PreparationScreen(Screen):
|
||||
("escape", "quit_app", "退出")
|
||||
]
|
||||
|
||||
def __init__(self, nucleon_file: pt.AtomicFile, electron_file: pt.AtomicFile) -> None:
|
||||
def __init__(self, nucleon_file: pt.NucleonUnion, electron_file: pt.ElectronUnion) -> None:
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.nucleon_file = nucleon_file
|
||||
self.electron_file = electron_file
|
||||
@@ -158,12 +158,18 @@ class PreparationScreen(Screen):
|
||||
yield Label(f"记忆项目: [b]{self.nucleon_file.name}[/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"核子数量:{self.nucleon_file.get_len()}")
|
||||
yield Label(f"核子数量:{len(self.nucleon_file)}")
|
||||
yield Button("开始记忆", id="start_memorizing_button", variant="primary", classes="start-button")
|
||||
yield Static(f"\n全文如下:\n")
|
||||
yield Static(self.nucleon_file.get_full_content(), classes="full")
|
||||
yield Static(self._get_full_content(), classes="full")
|
||||
yield Footer()
|
||||
|
||||
def _get_full_content(self):
|
||||
content = ""
|
||||
for i in self.nucleon_file.nucleons:
|
||||
content += i['content']
|
||||
return content
|
||||
|
||||
def action_go_back(self):
|
||||
self.app.pop_screen()
|
||||
|
||||
@@ -216,13 +222,13 @@ class FileSelectorScreen(Screen):
|
||||
return
|
||||
|
||||
selected_filename = str(selected_label.renderable)
|
||||
nucleon_file = pt.AtomicFile(pathlib.Path("./nucleon") / selected_filename, "nucleon")
|
||||
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.AtomicFile(pathlib.Path("./electron") / selected_filename, "electron")
|
||||
electron_file = pt.ElectronUnion(pathlib.Path("./electron") / selected_filename)
|
||||
# self.notify(f"已选择: {selected_filename}", timeout=2)
|
||||
self.app.push_screen(PreparationScreen(nucleon_file, electron_file))
|
||||
|
||||
|
Reference in New Issue
Block a user