You've already forked HeurAMS-legacy
fix: 完善
This commit is contained in:
@@ -51,11 +51,11 @@ class MemScreen(Screen):
|
||||
|
||||
def puzzle_widget(self):
|
||||
try:
|
||||
print(self.phaser.state)
|
||||
#print(self.phaser.state)
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
# print(1)
|
||||
puzzle_info = next(self.fission.generate())
|
||||
print(puzzle_info)
|
||||
#print(puzzle_info)
|
||||
return shim.puzzle2widget[puzzle_info["puzzle"]](
|
||||
atom=self.procession.current_atom, alia=puzzle_info["alia"]
|
||||
)
|
||||
@@ -90,7 +90,9 @@ class MemScreen(Screen):
|
||||
forwards = 1 if new_rating >= 4 else 0
|
||||
self.rating = -1
|
||||
if forwards:
|
||||
self.procession.forward(1)
|
||||
ret = self.procession.forward(1)
|
||||
if ret == 0:
|
||||
self.procession = self.phaser.current_procession() # type: ignore
|
||||
self.load_puzzle()
|
||||
|
||||
def action_play_voice(self):
|
||||
|
||||
@@ -4,14 +4,11 @@ from textual.widgets import (
|
||||
Header,
|
||||
Footer,
|
||||
Label,
|
||||
Input,
|
||||
Select,
|
||||
Button,
|
||||
Markdown,
|
||||
Static,
|
||||
ProgressBar,
|
||||
)
|
||||
from textual.containers import Container, Horizontal, Center
|
||||
from textual.containers import Container, Horizontal
|
||||
from textual.containers import Container
|
||||
from textual.screen import Screen
|
||||
import pathlib
|
||||
@@ -19,7 +16,7 @@ import pathlib
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.services.hasher as hasher
|
||||
from heurams.context import *
|
||||
from textual.worker import Worker, get_current_worker
|
||||
from textual.worker import get_current_worker
|
||||
|
||||
|
||||
class PrecachingScreen(Screen):
|
||||
|
||||
48
src/heurams/interface/screens/synctool.py
Normal file
48
src/heurams/interface/screens/synctool.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
from textual.app import ComposeResult
|
||||
from textual.widgets import (
|
||||
Header,
|
||||
Footer,
|
||||
Label,
|
||||
Button,
|
||||
Static,
|
||||
ProgressBar,
|
||||
)
|
||||
from textual.containers import Container, Horizontal
|
||||
from textual.containers import Container
|
||||
from textual.screen import Screen
|
||||
import pathlib
|
||||
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.services.hasher as hasher
|
||||
from heurams.context import *
|
||||
from textual.worker import get_current_worker
|
||||
|
||||
|
||||
class SyncScreen(Screen):
|
||||
|
||||
BINDINGS = [("q", "go_back", "返回")]
|
||||
|
||||
def __init__(self, nucleons: list = [], desc: str = ""):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
with Container(id="sync_container"):
|
||||
pass
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self):
|
||||
"""挂载时初始化状态"""
|
||||
|
||||
def update_status(self, status, current_item="", progress=None):
|
||||
"""更新状态显示"""
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
event.stop()
|
||||
|
||||
def action_go_back(self):
|
||||
self.app.pop_screen()
|
||||
|
||||
def action_quit_app(self):
|
||||
self.app.exit()
|
||||
@@ -1,13 +1,18 @@
|
||||
# 单项选择题
|
||||
from textual.widgets import (
|
||||
Label,
|
||||
Button,
|
||||
)
|
||||
from textual.containers import (
|
||||
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
|
||||
|
||||
class Setting(TypedDict):
|
||||
__origin__: str
|
||||
@@ -42,7 +47,7 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
)
|
||||
self.inputlist = []
|
||||
self.alia = alia
|
||||
self.hashtable = {}
|
||||
self.hashmap = bidict()
|
||||
self._load()
|
||||
|
||||
def _load(self):
|
||||
@@ -53,9 +58,7 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
self.puzzle.refresh()
|
||||
|
||||
def compose(self):
|
||||
setting: Setting = self.atom.registry["nucleon"].metadata["orbital"]["puzzle"][
|
||||
self.alia
|
||||
]
|
||||
setting: Setting = self.atom.registry["nucleon"].metadata["orbital"]["puzzle"][self.alia]
|
||||
yield Label(setting["primary"], id="sentence")
|
||||
yield Label(self.puzzle.wording[len(self.inputlist)], id="puzzle")
|
||||
yield Label(f"当前输入: {self.inputlist}", id="inputpreview")
|
||||
@@ -63,8 +66,8 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
# 渲染当前问题的选项
|
||||
current_options = self.puzzle.options[len(self.inputlist)]
|
||||
for i in current_options:
|
||||
self.hashtable[str(hash(i))] = i
|
||||
yield Button(i, id=f"select{hash(i)}")
|
||||
self.hashmap[str(hash(i))] = i
|
||||
yield Button(i, id=f"select-{hash(i)}")
|
||||
|
||||
yield Button("退格", id="delete")
|
||||
|
||||
@@ -79,12 +82,9 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
if current_question_index < len(self.puzzle.wording):
|
||||
puzzle_label.update(self.puzzle.wording[current_question_index]) # type: ignore
|
||||
|
||||
# 发送输入变化消息
|
||||
|
||||
# 如果还有下一题,发送题目切换消息
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
"""处理按钮点击事件"""
|
||||
event.stop()
|
||||
button_id = event.button.id
|
||||
|
||||
if button_id == "delete":
|
||||
@@ -93,9 +93,10 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
self.inputlist.pop()
|
||||
self.refresh_buttons()
|
||||
self.update_display()
|
||||
|
||||
elif button_id.startswith("select"): # type: ignore
|
||||
# 选项选择处理
|
||||
answer_text = self.hashtable[button_id[6:]] # type: ignore
|
||||
answer_text = self.hashmap[button_id[7:]] # type: ignore
|
||||
self.inputlist.append(answer_text)
|
||||
|
||||
# 检查是否完成所有题目
|
||||
@@ -103,16 +104,7 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
is_correct = self.inputlist == self.puzzle.answer
|
||||
rating = 4 if is_correct else 2
|
||||
|
||||
# 发送完成消息
|
||||
self.post_message(
|
||||
self.PuzzleCompleted(
|
||||
atom=self.atom,
|
||||
rating=rating,
|
||||
is_correct=is_correct,
|
||||
user_answers=self.inputlist.copy(),
|
||||
correct_answers=self.puzzle.answer.copy(),
|
||||
)
|
||||
)
|
||||
self.screen.rating = rating # type: ignore
|
||||
|
||||
# 重置输入(如果回答错误)
|
||||
if not is_correct:
|
||||
@@ -132,6 +124,7 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
for child in self.children
|
||||
if hasattr(child, "id") and child.id and child.id.startswith("select")
|
||||
]
|
||||
|
||||
for button in buttons_to_remove:
|
||||
self.remove_child(button) # type: ignore
|
||||
|
||||
@@ -140,8 +133,8 @@ class MCQPuzzle(BasePuzzleWidget):
|
||||
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)}"
|
||||
if button_id not in self.hashtable:
|
||||
self.hashtable[button_id] = option
|
||||
button_id = f"select-{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)
|
||||
|
||||
Reference in New Issue
Block a user