fix: 改进
This commit is contained in:
@@ -3,6 +3,7 @@ from textual.app import ComposeResult
|
||||
from textual.widgets import Header, Footer, Label, Static, Button
|
||||
from textual.containers import Center
|
||||
from textual.screen import Screen
|
||||
from textual.reactive import reactive
|
||||
from enum import Enum, auto
|
||||
|
||||
from heurams.context import config_var
|
||||
@@ -33,8 +34,10 @@ class MemScreen(Screen):
|
||||
#print(self.phaser.state)
|
||||
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
||||
#print(self.phaser.state)
|
||||
self.rating = reactive(0)
|
||||
|
||||
def current_widget(self):
|
||||
|
||||
def puzzle_widget(self):
|
||||
try:
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
puzzle_info = next(self.fission.generate())
|
||||
@@ -49,16 +52,25 @@ class MemScreen(Screen):
|
||||
yield Header(show_clock=True)
|
||||
with Center():
|
||||
yield Static(f"当前进度: {self.procession.process()}/{self.procession.total_length()}")
|
||||
self.mount(self.current_widget()) # type: ignore
|
||||
#self.mount(self.current_widget()) # type: ignore
|
||||
yield Container(id="puzzle-container")
|
||||
yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self):
|
||||
pass
|
||||
def load_puzzle(self):
|
||||
container = self.query_one("puzzle-container")
|
||||
for i in puz_container.children:
|
||||
i.remove()
|
||||
container.mount(self.puzzle_widget())
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
event.stop()
|
||||
if
|
||||
|
||||
def watch_rating(self, old_value, new_value) -> None:
|
||||
forwards = 1 if new_value >= 4 else 0
|
||||
if forwards:
|
||||
self.procession.forward(1)
|
||||
self.load_puzzle()
|
||||
|
||||
def action_play_voice(self):
|
||||
"""朗读当前内容"""
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from textual.widgets import (
|
||||
Label,
|
||||
Button,
|
||||
)
|
||||
from textual.widget import Widget
|
||||
|
||||
@@ -9,4 +10,10 @@ class Finished(Widget):
|
||||
super().__init__(*children, name=name, id=id, classes=classes, disabled=disabled, markup=markup)
|
||||
|
||||
def compose(self):
|
||||
yield Label("本次记忆进程结束, 下次再会!", id="finished_msg")
|
||||
yield Label("本次记忆进程结束", id="finished_msg")
|
||||
yield Button("返回上一级", id="back-to-menu")
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
button_id = event.button.id
|
||||
if button_id == 'back-to-menu':
|
||||
self.app.pop_screen()
|
||||
|
||||
@@ -158,4 +158,4 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
if button_id not in self.hashtable:
|
||||
self.hashtable[button_id] = option
|
||||
new_button = Button(option, id=button_id)
|
||||
self.mount(new_button)
|
||||
self.mount(new_button)
|
||||
|
||||
@@ -11,4 +11,7 @@ class Placeholder(Widget):
|
||||
|
||||
def compose(self):
|
||||
yield Label("示例标签", id="testlabel")
|
||||
yield Button("示例按钮", id="testbtn", classes="choice")
|
||||
yield Button("示例按钮", id="testbtn", classes="choice")
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
pass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from textual.reactive import reactive
|
||||
from textual.widgets import (
|
||||
Markdown,
|
||||
Label,
|
||||
@@ -84,4 +85,4 @@ class Recognition(BasePuzzleWidget):
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
if event.button.id == "ok":
|
||||
self.post_message(self.RatingChanged(5))
|
||||
self.post_message(self.RatingChanged(5))
|
||||
|
||||
Reference in New Issue
Block a user