改进
This commit is contained in:
@@ -4,10 +4,11 @@ from textual.widgets import Header, Footer, ListView, ListItem, Label, Static, B
|
||||
from textual.containers import Container, Horizontal
|
||||
from textual.screen import Screen
|
||||
import pathlib
|
||||
from typing import Tuple, Dict
|
||||
import particles as pt
|
||||
|
||||
class Composition():
|
||||
def __init__(self, screen: Screen, atom):
|
||||
def __init__(self, screen: Screen, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
self.screen = screen
|
||||
self.atom = atom
|
||||
def compose(self):
|
||||
@@ -17,16 +18,55 @@ class Composition():
|
||||
print(event.button.id)
|
||||
self.screen.query_one("#testlabel", Label).update("hi")
|
||||
|
||||
class Placeholder(Composition):
|
||||
def __init__(self, screen: Screen):
|
||||
self.screen = screen
|
||||
def compose(self):
|
||||
yield Label("示例标签", id="testlabel")
|
||||
yield Button("示例按钮", id="testbtn")
|
||||
def handler(self, event):
|
||||
print(event.button.id)
|
||||
self.screen.query_one("#testlabel", Label).update("hi")
|
||||
|
||||
class Recognition(Composition):
|
||||
def __init__(self, screen: Screen, atom):
|
||||
pass
|
||||
def __init__(self, screen: Screen, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, atom)
|
||||
def compose(self):
|
||||
yield Label(self.atom[1]["content"], id="sentence")
|
||||
for i in self.atom[2]["testdata"]["additional_inf"]:
|
||||
yield Label("[" + self.atom[2]["keydata"][i] + "] " + str(self.atom[1][i]), id=f"label_{i}")
|
||||
yield Button("我已知晓", id="ok")
|
||||
def handler(self, event):
|
||||
if event.button.id == "ok":
|
||||
return 1
|
||||
|
||||
class FillBlank(Composition):
|
||||
def __init__(self, screen: Screen, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, atom)
|
||||
def compose(self):
|
||||
yield Label(self.atom[1]["content"], id="sentence")
|
||||
for i in self.atom[2]["testdata"]["additional_inf"]:
|
||||
yield Label(f"{self.atom[2]["keydata"][i]}: {self.atom[1][i]}", id=f"label_{i}")
|
||||
yield Button("我已知晓", id="ok")
|
||||
def handler(self, event):
|
||||
if event.button.id == "ok":
|
||||
return 1
|
||||
|
||||
|
||||
registry = {
|
||||
"sample": Composition,
|
||||
"recognition": Recognition,
|
||||
"fill_blank_test": FillBlank,
|
||||
"draw_card_test": Composition,
|
||||
}
|
||||
|
||||
|
||||
# TEST
|
||||
|
||||
class TestScreen(Screen):
|
||||
def __init__(self):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.comp = Composition(self, pt.Atom.advanced_placeholder())
|
||||
self.comp = Recognition(self, pt.Atom.advanced_placeholder())
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
yield from self.comp.compose()
|
||||
|
Reference in New Issue
Block a user