You've already forked HeurAMS-legacy
style: 代码格式化
This commit is contained in:
@@ -9,9 +9,28 @@ import heurams.kernel.particles as pt
|
||||
from .base_puzzle_widget import BasePuzzleWidget
|
||||
from textual.message import Message
|
||||
|
||||
|
||||
class BasicEvaluation(BasePuzzleWidget):
|
||||
def __init__(self, *children: Widget, atom: pt.Atom, alia: str = "", 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 __init__(
|
||||
self,
|
||||
*children: Widget,
|
||||
atom: pt.Atom,
|
||||
alia: str = "",
|
||||
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,
|
||||
)
|
||||
|
||||
class RatingChanged(Message):
|
||||
def __init__(self, rating: int) -> None:
|
||||
@@ -31,10 +50,10 @@ class BasicEvaluation(BasePuzzleWidget):
|
||||
def compose(self):
|
||||
# 显示主要内容
|
||||
yield Label(self.atom.registry["nucleon"]["content"], id="main")
|
||||
|
||||
|
||||
# 显示评估说明(可选)
|
||||
yield Static("请评估你对这个内容的记忆程度:", classes="instruction")
|
||||
|
||||
|
||||
# 按钮容器
|
||||
with Container(id="button_container"):
|
||||
btn = {}
|
||||
@@ -56,7 +75,7 @@ class BasicEvaluation(BasePuzzleWidget):
|
||||
btn["0"] = Button(
|
||||
"完全空白", variant="error", id="feedback_0", classes="choice"
|
||||
)
|
||||
|
||||
|
||||
# 布局按钮
|
||||
yield Horizontal(btn["5"], btn["4"])
|
||||
yield Horizontal(btn["3"], btn["2"])
|
||||
@@ -68,13 +87,15 @@ class BasicEvaluation(BasePuzzleWidget):
|
||||
|
||||
if button_id in self.feedback_mapping:
|
||||
feedback_info = self.feedback_mapping[button_id]
|
||||
|
||||
self.post_message(self.RatingChanged(
|
||||
rating=feedback_info["rating"],
|
||||
))
|
||||
|
||||
|
||||
self.post_message(
|
||||
self.RatingChanged(
|
||||
rating=feedback_info["rating"],
|
||||
)
|
||||
)
|
||||
|
||||
event.button.add_class("selected")
|
||||
|
||||
|
||||
self.disable_other_buttons(button_id)
|
||||
|
||||
def disable_other_buttons(self, selected_button_id: str) -> None:
|
||||
@@ -91,6 +112,8 @@ class BasicEvaluation(BasePuzzleWidget):
|
||||
button_id = f"feedback_{event.key}"
|
||||
if button_id in self.feedback_mapping:
|
||||
# 模拟按钮点击
|
||||
self.post_message(self.RatingChanged(
|
||||
rating=self.feedback_mapping[button_id]["rating"],
|
||||
))
|
||||
self.post_message(
|
||||
self.RatingChanged(
|
||||
rating=self.feedback_mapping[button_id]["rating"],
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user