组件可用性更新
This commit is contained in:
@@ -108,6 +108,7 @@ class Recognition(Composition):
|
||||
return -1
|
||||
|
||||
class BasicEvaluation(Composition):
|
||||
# 不再使用, 仅作为测试
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, reactor, atom)
|
||||
def compose(self):
|
||||
@@ -133,50 +134,68 @@ class BasicEvaluation(Composition):
|
||||
class FillBlank(Composition):
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, reactor, atom)
|
||||
self.inputlist = []
|
||||
self.hashtable = {}
|
||||
self._work()
|
||||
def _work(self):
|
||||
self.puzzle = pz.BlankPuzzle(self.atom[1]["content"], 4)
|
||||
self.puzzle.refresh()
|
||||
self.ans = copy.copy(self.puzzle.answer)
|
||||
random.shuffle(self.ans)
|
||||
def compose(self):
|
||||
self._work()
|
||||
yield Label(self.puzzle.wording, id=self.regid("sentence"))
|
||||
ans = copy.copy(self.puzzle.answer)
|
||||
random.shuffle(ans)
|
||||
for i in ans:
|
||||
yield
|
||||
yield Button("我已知晓", id="ok")
|
||||
yield Label(f"当前输入: {self.inputlist}", id=self.regid("inputpreview"))
|
||||
#yield Label(renderable=f"答案: {self.puzzle.answer}", id=self.regid("ans"))
|
||||
for i in self.ans:
|
||||
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_):
|
||||
if event.button.id == "ok":
|
||||
return 1
|
||||
if type_ == "button":
|
||||
if self.recid(event.button.id) == "delete" and len(self.inputlist) > 0:
|
||||
self.inputlist.pop()
|
||||
else:
|
||||
self.inputlist.append(self.hashtable[self.recid(event.button.id)[6:]])
|
||||
if len(self.inputlist) < len(self.puzzle.answer):
|
||||
return 1
|
||||
else:
|
||||
if self.inputlist == self.puzzle.answer:
|
||||
print("ok")
|
||||
return 0
|
||||
else:
|
||||
self.inputlist = []
|
||||
return 1
|
||||
|
||||
class DrawCard(Composition):
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, reactor, atom)
|
||||
self.inputlist = []
|
||||
self.hashtable = {}
|
||||
self._work()
|
||||
def _work(self):
|
||||
self.puzzle = pz.SelectionPuzzle(self.atom[1]["keyword_note"], [], 2, "选择正确词义: ")
|
||||
self.puzzle.refresh()
|
||||
def compose(self):
|
||||
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"))
|
||||
yield Label(self.atom[1].content, id=self.regid("sentence"))
|
||||
yield Label(self.puzzle.wording[len(self.inputlist)], id=self.regid("puzzle"))
|
||||
yield Label(f"当前输入: {self.inputlist}", id=self.regid("inputpreview"))
|
||||
yield Label(renderable=f"答案: {self.puzzle.answer}", id=self.regid("ans"))
|
||||
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_):
|
||||
if type_ == "button":
|
||||
if self.recid(event.button.id) == "delete" and len(self.inputlist) > 0:
|
||||
self.inputlist.pop()
|
||||
else:
|
||||
self.inputlist.append(self.hashtable[self.recid(event.button.id)[6:]])
|
||||
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
|
||||
return 1
|
||||
else:
|
||||
if self.inputlist == self.puzzle.answer:
|
||||
self.inputlist = []
|
||||
print("ok")
|
||||
return 0
|
||||
else:
|
||||
self.inputlist = []
|
||||
@@ -185,7 +204,7 @@ class DrawCard(Composition):
|
||||
registry = {
|
||||
"sample": Composition,
|
||||
"recognition": Recognition,
|
||||
"fill_blank_test": BasicEvaluation,
|
||||
"fill_blank_test": FillBlank,
|
||||
"draw_card_test": DrawCard,
|
||||
"basic_evaluation": BasicEvaluation,
|
||||
}
|
||||
|
Reference in New Issue
Block a user