布局更新

This commit is contained in:
2025-08-06 04:57:28 +08:00
parent 6c28bd461b
commit b77f3f2abe
2 changed files with 34 additions and 8 deletions

View File

@@ -149,18 +149,44 @@ class FillBlank(Composition):
return 1
class DrawCard(Composition):
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict] = pt.Atom.placeholder()):
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
super().__init__(screen, reactor, atom)
self.inputlist = []
self.hashtable = {}
def _work(self):
self.puzzle = pz.SelectionPuzzle(self.atom[1]["keyword_note"], [], 2, "选择正确词义: ")
self.puzzle.refresh()
def compose(self):
pass
self._work()
print(len(self.inputlist))
yield Label(self.puzzle.wording[len(self.inputlist)], id=self.regid("sentence"))
yield Label(f"当前输入: {self.inputlist}", id=self.regid("sentence"))
for i in self.puzzle.options[len(self.inputlist)]:
self.hashtable[str(hash(i))] = i
yield Button(i, id=self.regid(f"select{hash(i)}"))
yield Button("退格", id=self.regid(f"delete"))
def handler(self, event, type_):
pass
if type_ == "button":
if len(self.inputlist) < len(self.puzzle.answer):
if self.recid(event.button.id) == "delete" and len(self.inputlist) > 0:
self.inputlist.pop()
return 1
else:
self.inputlist.append(self.hashtable[self.recid(event.button.id)[6:]])
return 1
else:
if self.inputlist == self.puzzle.answer:
self.inputlist = []
return 0
else:
self.inputlist = []
return 1
registry = {
"sample": Composition,
"recognition": Recognition,
"fill_blank_test": BasicEvaluation,
"draw_card_test": BasicEvaluation,
"draw_card_test": DrawCard,
"basic_evaluation": BasicEvaluation,
}

View File

@@ -49,7 +49,7 @@ class SelectionPuzzle(Puzzle):
max_riddles_num: 最大生成谜题数 (默认2个)
prefix: 问题前缀
"""
def __init__(self, mapping: dict, jammer: list, max_riddles_num: int = 2, prefix: str = ""):
def __init__(self, mapping, jammer: list, max_riddles_num: int = 2, prefix: str = ""):
self.prefix = prefix
self.mapping = mapping
self.jammer = list(set(jammer + list(mapping.values()))) # 合并干扰项和正确答案并去重
@@ -92,12 +92,12 @@ class SelectionPuzzle(Puzzle):
answers.append(correct_answer)
all_options.append(options)
question_texts = [f"{self.prefix}"]
question_texts = []
for i, (puzzle, options) in enumerate(zip(puzzles, all_options)):
#options_text = "\n".join([f" {chr(97+j)}. {opt}" for j, opt in enumerate(options)])
question_texts.append(f"{i+1}. {puzzle}")
question_texts.append(f"{self.prefix}:\n {i+1}. {puzzle}")
self.wording = "\n".join(question_texts)
self.wording = question_texts
self.answer = answers
self.options = all_options