You've already forked HeurAMS-legacy
fix: 改进
This commit is contained in:
@@ -23,7 +23,7 @@ logger = get_logger(__name__)
|
||||
class MemScreen(Screen):
|
||||
BINDINGS = [
|
||||
("q", "pop_screen", "返回"),
|
||||
("p", "prev", "复习上一个"),
|
||||
#("p", "prev", "复习上一个"),
|
||||
("d", "toggle_dark", "改变色调"),
|
||||
("v", "play_voice", "朗读"),
|
||||
]
|
||||
@@ -46,6 +46,8 @@ class MemScreen(Screen):
|
||||
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
||||
# logger.debug(self.phaser.state)
|
||||
# self.procession.forward(1)
|
||||
for i in atoms:
|
||||
i.do_eval()
|
||||
|
||||
def on_mount(self):
|
||||
self.load_puzzle()
|
||||
@@ -53,11 +55,10 @@ class MemScreen(Screen):
|
||||
|
||||
def puzzle_widget(self):
|
||||
try:
|
||||
# logger.debug(self.phaser.state)
|
||||
#logger.debug(self.procession.cursor)
|
||||
#logger.debug(self.procession.current_atom)
|
||||
logger.debug(self.phaser.state)
|
||||
logger.debug(self.procession.cursor)
|
||||
logger.debug(self.procession.current_atom)
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
# logger.debug(1)
|
||||
puzzle_debug = next(self.fission.generate())
|
||||
#logger.debug(puzzle_debug)
|
||||
return shim.puzzle2widget[puzzle_debug["puzzle"]](
|
||||
@@ -71,21 +72,33 @@ class MemScreen(Screen):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
with ScrollableContainer():
|
||||
with Center():
|
||||
yield Static(
|
||||
f"当前进度: {self.procession.process()}/{self.procession.total_length()}"
|
||||
)
|
||||
yield Label(self._get_progress_text(), id="progress")
|
||||
|
||||
# self.mount(self.current_widget()) # type: ignore
|
||||
yield ScrollableContainer(id="puzzle-container")
|
||||
# yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||
yield Footer()
|
||||
|
||||
def _get_progress_text(self):
|
||||
return f"当前进度: {self.procession.process() + 1}/{self.procession.total_length()}"
|
||||
|
||||
def update_display(self):
|
||||
progress_widget = self.query_one("#progress")
|
||||
progress_widget.update(self._get_progress_text()) # type: ignore
|
||||
|
||||
def load_puzzle(self):
|
||||
container = self.query_one("#puzzle-container")
|
||||
for i in container.children:
|
||||
i.remove()
|
||||
container.mount(self.puzzle_widget())
|
||||
|
||||
def load_finished_widget(self):
|
||||
container = self.query_one("#puzzle-container")
|
||||
for i in container.children:
|
||||
i.remove()
|
||||
from heurams.interface.widgets.finished import Finished
|
||||
container.mount(Finished())
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
event.stop()
|
||||
|
||||
@@ -98,7 +111,13 @@ class MemScreen(Screen):
|
||||
ret = self.procession.forward(1)
|
||||
if ret == 0:
|
||||
self.procession = self.phaser.current_procession() # type: ignore
|
||||
logger.debug(f"建立新队列 {self.procession.phase}")
|
||||
if self.procession == 0:
|
||||
logger.debug(f"记忆进程结束")
|
||||
self.load_finished_widget()
|
||||
return
|
||||
else:
|
||||
logger.debug(f"建立新队列 {self.procession.phase}")
|
||||
self.update_display()
|
||||
self.load_puzzle()
|
||||
|
||||
def action_play_voice(self):
|
||||
|
||||
@@ -3,15 +3,16 @@ from textual.widgets import (
|
||||
Label,
|
||||
Button,
|
||||
)
|
||||
from textual.containers import ScrollableContainer
|
||||
from textual.containers import ScrollableContainer, Container
|
||||
from textual.widget import Widget
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.kernel.puzzles as pz
|
||||
from .base_puzzle_widget import BasePuzzleWidget
|
||||
from typing import TypedDict
|
||||
from bidict import bidict
|
||||
from heurams.services.hasher import hash
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
class Setting(TypedDict):
|
||||
__origin__: str
|
||||
@@ -46,7 +47,8 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
)
|
||||
self.inputlist = []
|
||||
self.alia = alia
|
||||
self.hashmap = bidict()
|
||||
self.hashmap = dict()
|
||||
self.cursor = 0
|
||||
self._load()
|
||||
|
||||
def _load(self):
|
||||
@@ -57,18 +59,23 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
self.puzzle.refresh()
|
||||
|
||||
def compose(self):
|
||||
self.atom.registry["nucleon"].do_eval()
|
||||
setting: Setting = self.atom.registry["nucleon"].metadata["orbital"]["puzzles"][
|
||||
self.alia
|
||||
]
|
||||
logger.debug(f"Puzzle Setting: {setting}")
|
||||
yield Label(setting["primary"], id="sentence")
|
||||
yield Label(self.puzzle.wording[len(self.inputlist)], id="puzzle")
|
||||
yield Label(f"当前输入: {self.inputlist}", id="inputpreview")
|
||||
|
||||
# 渲染当前问题的选项
|
||||
current_options = self.puzzle.options[len(self.inputlist)]
|
||||
for i in current_options:
|
||||
self.hashmap[str(hash(i))] = i
|
||||
yield Button(i, id=f"select-{hash(i)}")
|
||||
with Container(id="btn-container"):
|
||||
for i in current_options:
|
||||
self.hashmap[str(hash(i))] = i
|
||||
btnid = f"sel{str(self.cursor).zfill(3)}-{hash(i)}"
|
||||
logger.debug(f"建立按钮 {btnid}")
|
||||
yield Button(i, id=f"{btnid}")
|
||||
|
||||
yield Button("退格", id="delete")
|
||||
|
||||
@@ -76,7 +83,7 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
# 更新预览标签
|
||||
preview = self.query_one("#inputpreview")
|
||||
preview.update(f"当前输入: {self.inputlist}") # type: ignore
|
||||
|
||||
logger.debug("已经更新预览标签")
|
||||
# 更新问题标签
|
||||
puzzle_label = self.query_one("#puzzle")
|
||||
current_question_index = len(self.inputlist)
|
||||
@@ -95,11 +102,11 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
self.refresh_buttons()
|
||||
self.update_display()
|
||||
|
||||
elif button_id.startswith("select"): # type: ignore
|
||||
elif button_id.startswith("sel"): # type: ignore
|
||||
# 选项选择处理
|
||||
answer_text = self.hashmap[button_id[7:]] # type: ignore
|
||||
self.inputlist.append(answer_text)
|
||||
|
||||
logger.debug(f"{self.inputlist}")
|
||||
# 检查是否完成所有题目
|
||||
if len(self.inputlist) >= len(self.puzzle.answer):
|
||||
is_correct = self.inputlist == self.puzzle.answer
|
||||
@@ -120,22 +127,26 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
def refresh_buttons(self):
|
||||
"""刷新按钮显示(用于题目切换)"""
|
||||
# 移除所有选项按钮
|
||||
logger.debug("刷新按钮")
|
||||
self.cursor += 1
|
||||
container = self.query_one("#btn-container")
|
||||
buttons_to_remove = [
|
||||
child
|
||||
for child in self.children
|
||||
if hasattr(child, "id") and child.id and child.id.startswith("select")
|
||||
for child in container.children
|
||||
if hasattr(child, "id") and child.id and child.id.startswith("sel")
|
||||
]
|
||||
|
||||
for button in buttons_to_remove:
|
||||
self.remove_child(button) # type: ignore
|
||||
logger.info(button)
|
||||
container.remove_children("#"+button.id) # type: ignore
|
||||
|
||||
# 添加当前题目的选项按钮
|
||||
current_question_index = len(self.inputlist)
|
||||
if current_question_index < len(self.puzzle.options):
|
||||
current_options = self.puzzle.options[current_question_index]
|
||||
for option in current_options:
|
||||
button_id = f"select-{hash(option)}"
|
||||
button_id = f"sel{str(self.cursor).zfill(3)}-{hash(option)}"
|
||||
if button_id not in self.hashmap:
|
||||
self.hashmap[button_id] = option
|
||||
new_button = Button(option, id=button_id)
|
||||
self.mount(new_button)
|
||||
container.mount(new_button)
|
||||
|
||||
Reference in New Issue
Block a user