组件消息现代化
This commit is contained in:
@@ -1,30 +1,17 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.events import Event
|
||||
from textual.widgets import (
|
||||
Collapsible,
|
||||
Header,
|
||||
Footer,
|
||||
Markdown,
|
||||
ListView,
|
||||
ListItem,
|
||||
Label,
|
||||
Static,
|
||||
Button,
|
||||
)
|
||||
from textual.containers import Container, Horizontal, Center
|
||||
from textual.screen import Screen
|
||||
from textual.containers import Center
|
||||
from textual.widget import Widget
|
||||
import uuid
|
||||
from typing import Tuple, Dict
|
||||
from typing import Dict
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.kernel.puzzles as pz
|
||||
import re
|
||||
import random
|
||||
import copy
|
||||
from .base_puzzle_widget import BasePuzzleWidget
|
||||
from heurams.context import config_var
|
||||
from .. import shim
|
||||
from typing import TypedDict, List
|
||||
from textual.message import Message
|
||||
|
||||
class RecognitionConfig(TypedDict):
|
||||
__origin__: str
|
||||
@@ -35,15 +22,18 @@ class RecognitionConfig(TypedDict):
|
||||
|
||||
class Recognition(BasePuzzleWidget):
|
||||
|
||||
rate_mapping = {
|
||||
"ok": 5
|
||||
}
|
||||
|
||||
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)
|
||||
if alia == "":
|
||||
alia = "Recognition"
|
||||
self.alia = alia
|
||||
|
||||
class RatingChanged(Message):
|
||||
"""评分改变消息"""
|
||||
def __init__(self, rating: int) -> None:
|
||||
self.rating = rating
|
||||
super().__init__()
|
||||
|
||||
def compose(self):
|
||||
cfg: RecognitionConfig = self.atom.registry["orbital"]["puzzles"][self.alia]
|
||||
delim = self.atom.registry['nucleon'].metadata["formation"]["delimiter"]
|
||||
@@ -64,8 +54,8 @@ class Recognition(BasePuzzleWidget):
|
||||
primary = nucleon[cfg["primary"]]
|
||||
|
||||
with Center():
|
||||
yield Static(f"[dim]{nucleon[cfg["top_dim"]]}[/]")
|
||||
yield Label(f"")
|
||||
yield Static(f"[dim]{nucleon[cfg['top_dim']]}[/]")
|
||||
yield Label("")
|
||||
|
||||
for old, new in replace_dict.items():
|
||||
primary = primary.replace(old, new)
|
||||
@@ -80,7 +70,7 @@ class Recognition(BasePuzzleWidget):
|
||||
for item in nucleon[cfg["secondary"]]:
|
||||
if isinstance(item, list):
|
||||
for j in item:
|
||||
yield Markdown(f"### {metadata["annotation"][item]}: {j}")
|
||||
yield Markdown(f"### {metadata['annotation'][item]}: {j}")
|
||||
continue
|
||||
if isinstance(item, Dict):
|
||||
total = ""
|
||||
@@ -93,9 +83,6 @@ class Recognition(BasePuzzleWidget):
|
||||
with Center():
|
||||
yield Button("我已知晓", id="ok")
|
||||
|
||||
def handler(self, event, type_):
|
||||
if type_ == "button":
|
||||
if event.button.id == "ok":
|
||||
shim.report_to_staging(self.atom, 5)
|
||||
return 0
|
||||
return -1
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
if event.button.id == "ok":
|
||||
self.post_message(self.RatingChanged(5))
|
||||
Reference in New Issue
Block a user