中途改进
This commit is contained in:
57
compositions.py
Normal file
57
compositions.py
Normal file
@@ -0,0 +1,57 @@
|
||||
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.screen import Screen
|
||||
import pathlib
|
||||
import particles as pt
|
||||
|
||||
class Composition():
|
||||
def __init__(self, screen: Screen, atom):
|
||||
self.screen = screen
|
||||
self.atom = atom
|
||||
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
|
||||
|
||||
# TEST
|
||||
|
||||
class TestScreen(Screen):
|
||||
def __init__(self):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.comp = Composition(self, pt.Atom.advanced_placeholder())
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
yield from self.comp.compose()
|
||||
yield Footer()
|
||||
def on_mount(self) -> None:
|
||||
pass
|
||||
|
||||
def on_button_pressed(self, event: Event) -> None:
|
||||
self.comp.handler(event)
|
||||
|
||||
def action_quit_app(self) -> None:
|
||||
self.app.exit()
|
||||
|
||||
class AppLauncher(App):
|
||||
CSS_PATH = "styles.tcss"
|
||||
TITLE = '测试布局'
|
||||
BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")]
|
||||
SCREENS = {
|
||||
"testscreen": TestScreen,
|
||||
}
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.action_toggle_dark()
|
||||
self.push_screen("testscreen")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = AppLauncher()
|
||||
app.run()
|
Reference in New Issue
Block a user