重构布局系统并改进界面
This commit is contained in:
@@ -1,16 +1,29 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.events import Event
|
||||
from textual.widgets import Header, Footer, ListView, ListItem, Label, Static, Button
|
||||
from textual.containers import Container, Horizontal
|
||||
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.widget import Widget
|
||||
import pathlib
|
||||
from typing import Tuple, Dict
|
||||
import particles as pt
|
||||
import uuid
|
||||
from functools import wraps
|
||||
|
||||
class Composition():
|
||||
def __init__(self, screen: Screen, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
self.screen = screen
|
||||
self.atom = atom
|
||||
self.atom = atom
|
||||
from reactor import Reactor
|
||||
self.reactor: Reactor = reactor
|
||||
self.reg = dict()
|
||||
def regid(self, id_):
|
||||
self.reg[id_] = id_ + str(uuid.uuid4())
|
||||
return self.reg[id_]
|
||||
def getid(self, id_):
|
||||
if id_ not in self.reg.keys():
|
||||
return "None"
|
||||
return self.reg[id_]
|
||||
def compose(self):
|
||||
yield Label("示例标签", id="testlabel")
|
||||
yield Button("示例按钮", id="testbtn")
|
||||
@@ -23,18 +36,50 @@ class Placeholder(Composition):
|
||||
self.screen = screen
|
||||
def compose(self):
|
||||
yield Label("示例标签", id="testlabel")
|
||||
yield Button("示例按钮", id="testbtn")
|
||||
yield Button("示例按钮", id="testbtn", classes="choice")
|
||||
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: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, atom)
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, reactor, atom)
|
||||
def compose(self):
|
||||
with Center():
|
||||
yield Static(f"[dim]{self.atom[1]['translation']}[/]")
|
||||
yield Label(f"")
|
||||
with Center():
|
||||
yield Label(f"[b][b]{self.atom[1]['content']}[/][/]", id=self.regid("sentence")) # 致敬传奇去重串 uuid
|
||||
#with Collapsible(title="附加信息", collapsed=True):
|
||||
for i in self.atom[2]["testdata"]["additional_inf"]:
|
||||
if self.atom[1][i]:
|
||||
print(type(self.atom[1][i]))
|
||||
print(self.atom[1][i])
|
||||
if isinstance(self.atom[1][i], list):
|
||||
for j in self.atom[1][i]:
|
||||
print(999)
|
||||
yield Markdown(f"### {self.atom[2]["keydata"][i]}: {j}")
|
||||
continue
|
||||
if isinstance(self.atom[1][i], Dict):
|
||||
t = ""
|
||||
for j, k in self.atom[1][i].items():
|
||||
t += f"> **{j}**: {k} \n"
|
||||
yield Markdown(t, id=self.regid("tran"))
|
||||
with Center():
|
||||
yield Button("我已知晓", id=self.regid("ok"))
|
||||
def handler(self, event):
|
||||
if event.button.id == self.getid("ok"):
|
||||
print(1)
|
||||
""""""#assessment = self.reactor.report(self.reactor.current_atom, -1)
|
||||
return 0
|
||||
|
||||
class BasicEvaluation(Composition):
|
||||
def __init__(self, screen: Screen, reactor, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, reactor, 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 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":
|
||||
@@ -42,7 +87,7 @@ class Recognition(Composition):
|
||||
|
||||
class FillBlank(Composition):
|
||||
def __init__(self, screen: Screen, atom: Tuple[pt.Electron, pt.Nucleon, Dict]):
|
||||
super().__init__(screen, atom)
|
||||
""""""#super().__init__(screen, atom)
|
||||
def compose(self):
|
||||
yield Label(self.atom[1]["content"], id="sentence")
|
||||
for i in self.atom[2]["testdata"]["additional_inf"]:
|
||||
@@ -57,7 +102,8 @@ registry = {
|
||||
"sample": Composition,
|
||||
"recognition": Recognition,
|
||||
"fill_blank_test": FillBlank,
|
||||
"draw_card_test": Composition,
|
||||
"draw_card_test": BasicEvaluation,
|
||||
"basic_evaluation": BasicEvaluation,
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +112,7 @@ registry = {
|
||||
class TestScreen(Screen):
|
||||
def __init__(self):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.comp = Recognition(self, pt.Atom.advanced_placeholder())
|
||||
self.comp = Recognition(self, None, 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