mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
ws
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from rich.markdown import Markdown
|
||||
|
||||
from textual import events
|
||||
from textual.app import App
|
||||
from textual.widgets import Header, Footer, Placeholder, ScrollView
|
||||
|
||||
@@ -8,24 +7,38 @@ from textual.widgets import Header, Footer, Placeholder, ScrollView
|
||||
class MyApp(App):
|
||||
"""An example of a very simple Textual App"""
|
||||
|
||||
async def on_load(self, event: events.Load) -> None:
|
||||
stylesheet = """
|
||||
|
||||
App > View {
|
||||
layout: dock
|
||||
}
|
||||
|
||||
#body {
|
||||
padding: 1
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
edge left
|
||||
size: 40
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
async def on_load(self) -> None:
|
||||
"""Bind keys with the app loads (but before entering application mode)"""
|
||||
await self.bind("b", "view.toggle('sidebar')", "Toggle sidebar")
|
||||
await self.bind("q", "quit", "Quit")
|
||||
|
||||
async def on_mount(self, event: events.Mount) -> None:
|
||||
async def on_mount(self) -> None:
|
||||
"""Create and dock the widgets."""
|
||||
|
||||
# A scrollview to contain the markdown file
|
||||
body = ScrollView(gutter=1)
|
||||
|
||||
# Header / footer / dock
|
||||
await self.view.dock(Header(), edge="top")
|
||||
await self.view.dock(Footer(), edge="bottom")
|
||||
await self.view.dock(Placeholder(), edge="left", size=30, name="sidebar")
|
||||
|
||||
# Dock the body in the remaining space
|
||||
await self.view.dock(body, edge="right")
|
||||
body = ScrollView()
|
||||
await self.view.mount(
|
||||
Header(),
|
||||
Footer(),
|
||||
body=body,
|
||||
sidebar=Placeholder(),
|
||||
)
|
||||
|
||||
async def get_markdown(filename: str) -> None:
|
||||
with open(filename, "rt") as fh:
|
||||
@@ -35,4 +48,4 @@ class MyApp(App):
|
||||
await self.call_later(get_markdown, "richreadme.md")
|
||||
|
||||
|
||||
MyApp.run(title="Simple App", log="textual.log", css_file="theme.css")
|
||||
MyApp.run(title="Simple App", log="textual.log")
|
||||
|
||||
Reference in New Issue
Block a user