改进
This commit is contained in:
51
main.py
51
main.py
@@ -1,5 +1,5 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Header, Footer, ListView, ListItem, Label, Static, Button
|
||||
from textual.widgets import Header, Footer, ListView, DirectoryTree, ListItem, Label, Static, Button
|
||||
from textual.containers import Container, Horizontal
|
||||
from textual.screen import Screen
|
||||
import pathlib
|
||||
@@ -9,8 +9,9 @@ from playsound import playsound
|
||||
from textual.logging import TextualHandler
|
||||
|
||||
import particles as pt
|
||||
from reactor import Reactor
|
||||
from reactor import Reactor, Apparatus
|
||||
import auxiliary as aux
|
||||
import compositions as compo
|
||||
|
||||
ver = '0.3.0'
|
||||
|
||||
@@ -42,57 +43,32 @@ class MemScreen(Screen):
|
||||
tasked_num
|
||||
):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.reactor = Reactor(nucleon_file, electron_file, tasked_num)
|
||||
self.reactor = Reactor(nucleon_file, electron_file, self, tasked_num)
|
||||
self.stage = 1
|
||||
self.stage += self.reactor.set_round_templated(self.stage)
|
||||
#print(self.reactor.procession)
|
||||
self.reactor.forward()
|
||||
self.compo:compo.Composition = compo.Placeholder(self)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
self.compo = next(self.reactor.current_appar)
|
||||
yield Header(show_clock=True)
|
||||
with Container(id="main_container"):
|
||||
yield Label(self.reactor.round_title, id="round_title")
|
||||
yield Label("记住了吗?", id="question")
|
||||
yield Static(self.reactor.current_atom[1].content, id="sentence")
|
||||
yield Static("", id="feedback") # 用于显示反馈
|
||||
yield Label(self._get_progress_text(), id="progress")
|
||||
with Container(id="button_container"):
|
||||
if 1:
|
||||
self.btn['5'] = Button("完美回想", variant="success", id="q5", classes="choice")
|
||||
self.btn['4'] = Button("犹豫后正确", variant="success", id="q4", classes="choice")
|
||||
self.btn['3'] = Button("困难地正确", variant="warning", id="q3", classes="choice")
|
||||
self.btn['2'] = Button("错误但熟悉", variant="warning", id="q2", classes="choice")
|
||||
self.btn['1'] = Button("错误且不熟", variant="error", id="q1", classes="choice")
|
||||
self.btn['0'] = Button("完全空白", variant="error", id="q0", classes="choice")
|
||||
yield Horizontal(self.btn['5'], self.btn['4'])
|
||||
yield Horizontal(self.btn['3'], self.btn['2'])
|
||||
yield Horizontal(self.btn['1'], self.btn['0'])
|
||||
yield from self.compo.compose()
|
||||
yield Footer()
|
||||
|
||||
|
||||
"""
|
||||
def _get_progress_text(self):
|
||||
return f"{len(self.reactor.procession) - self.reactor.index}/{len(self.reactor.procession)}"
|
||||
"""
|
||||
|
||||
def on_mount(self):
|
||||
# 首次挂载时调用
|
||||
self._update_ui()
|
||||
|
||||
def _update_ui(self):
|
||||
self.query_one("#round_title", Label).update(self.reactor.round_title)
|
||||
self.query_one("#sentence", Static).update(self.reactor.current_atom[1].content)
|
||||
self.query_one("#progress", Label).update(self._get_progress_text())
|
||||
self.query_one("#feedback", Static).update("") # 清除任何之前的反馈消息
|
||||
|
||||
def _show_finished_screen(self, message):
|
||||
self.query_one("#question", Label).update(message)
|
||||
self.query_one("#sentence", Static).update("已经完成记忆任务")
|
||||
self.query_one("#round_title").display = False
|
||||
self.query_one("#progress").display = False
|
||||
for i in range(6):
|
||||
self.query_one(f"#q{i}", Button).display = False
|
||||
pass
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
feedback_label = self.query_one("#feedback", Static)
|
||||
self.compo.handler(event)
|
||||
"""feedback_label = self.query_one("#feedback", Static)
|
||||
if type(event) == str:
|
||||
btnid = event
|
||||
else:
|
||||
@@ -119,7 +95,8 @@ class MemScreen(Screen):
|
||||
self.stage += 1
|
||||
return
|
||||
#feedback_label.update("") # 清除反馈消息
|
||||
self._update_ui()
|
||||
self._update_ui()"""
|
||||
|
||||
def action_press(self, btnid):
|
||||
self.on_button_pressed(btnid)
|
||||
|
||||
|
Reference in New Issue
Block a user