进一步实现 interface

This commit is contained in:
2025-11-04 00:07:40 +08:00
parent 0e08fb3a41
commit 4eaff18685
13 changed files with 153 additions and 132 deletions

View File

@@ -21,10 +21,12 @@ import heurams.kernel.puzzles as pz
import re
import random
import copy
from .base_puzzle_widget import BasePuzzleWidget
from .. import shim
class Recognition(Composition):
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict], extra = {}):
super().__init__(screen, reactor, atom)
class Recognition(BasePuzzleWidget):
def __init__(self, *children: Widget, atom: pt.Atom, name: str | None = None, id: str | None = None, classes: str | None = None, disabled: bool = False, markup: bool = True) -> None:
super().__init__(*children, atom=atom, name=name, id=id, classes=classes, disabled=disabled, markup=markup)
def compose(self):
with Center():
@@ -49,7 +51,7 @@ class Recognition(Composition):
with Center():
yield Label(
f"[b][b]{i.replace('/', ' ')}[/][/]",
id=self.regid("sentence" + str(hash(i))),
id="sentence" + str(hash(i)),
)
for i in self.atom[2]["testdata"]["additional_inf"]:
if self.atom[1][i]:
@@ -60,15 +62,14 @@ class Recognition(Composition):
if isinstance(self.atom[1][i], Dict):
t = ""
for j, k in self.atom[1][i].items(): # type: ignore
# 弱智的 Pylance 类型推导
t += f"> **{j}**: {k} \n"
yield Markdown(t, id=self.regid("tran"))
yield Markdown(t, id="tran")
with Center():
yield Button("我已知晓", id=self.regid("ok"))
yield Button("我已知晓", id="ok")
def handler(self, event, type_):
if type_ == "button":
if event.button.id == self.getid("ok"):
self.reactor.report(self.atom, 5)
if event.button.id == "ok":
shim.report_to_staging(self.atom, 5)
return 0
return -1