mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
newline
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from textual import events
|
||||
from textual.app import App
|
||||
from textual.reactive import Reactive
|
||||
from textual.views import DockView
|
||||
from textual.widgets import Footer, Placeholder
|
||||
|
||||
|
||||
@@ -9,33 +8,29 @@ class SmoothApp(App):
|
||||
"""Demonstrates smooth animation"""
|
||||
|
||||
async def on_load(self, event: events.Load) -> None:
|
||||
await self.bind("q,ctrl+c", "quit")
|
||||
await self.bind("x", "bang")
|
||||
await self.bind("b", "toggle_sidebar")
|
||||
"""Bing keys here."""
|
||||
await self.bind("b", "toggle_sidebar", "Toggle sidebar")
|
||||
await self.bind("q", "quit", "Quit")
|
||||
|
||||
show_bar: Reactive[bool] = Reactive(False)
|
||||
|
||||
async def watch_show_bar(self, show_bar: bool) -> None:
|
||||
"""Called when show_bar changes."""
|
||||
self.animator.animate(self.bar, "layout_offset_x", 0 if show_bar else -40)
|
||||
|
||||
async def action_toggle_sidebar(self) -> None:
|
||||
"""Called when user hits b key."""
|
||||
self.show_bar = not self.show_bar
|
||||
|
||||
async def on_startup(self, event: events.Startup) -> None:
|
||||
|
||||
view = await self.push_view(DockView())
|
||||
|
||||
"""Build layout here."""
|
||||
footer = Footer()
|
||||
self.bar = Placeholder(name="left")
|
||||
self.bar.layout_offset_x = -40
|
||||
|
||||
footer.add_key("b", "Toggle sidebar")
|
||||
footer.add_key("q", "Quit")
|
||||
|
||||
await view.dock(footer, edge="bottom")
|
||||
await view.dock(self.bar, edge="left", size=40, z=1)
|
||||
|
||||
await view.dock(Placeholder(), Placeholder(), edge="top")
|
||||
await self.view.dock(footer, edge="bottom")
|
||||
await self.view.dock(self.bar, edge="left", size=40, z=1)
|
||||
await self.view.dock(Placeholder(), Placeholder(), edge="top")
|
||||
|
||||
|
||||
SmoothApp.run()
|
||||
|
||||
@@ -108,22 +108,23 @@ class CalculatorApp(App):
|
||||
async def on_startup(self, event: events.Startup) -> None:
|
||||
"""Sent when the app has gone full screen."""
|
||||
|
||||
# Create the layout which defines where our widgets will go
|
||||
layout = GridLayout(gap=(2, 1), gutter=1, align=("center", "center"))
|
||||
await self.push_view(View(layout=layout))
|
||||
# Create a grid layout
|
||||
grid = await self.view.dock_grid(
|
||||
gap=(2, 1), gutter=1, align=("center", "center")
|
||||
)
|
||||
|
||||
# Create rows / columns / areas
|
||||
layout.add_column("col", max_size=30, repeat=4)
|
||||
layout.add_row("numbers", max_size=15)
|
||||
layout.add_row("row", max_size=15, repeat=5)
|
||||
layout.add_areas(
|
||||
grid.add_column("col", max_size=30, repeat=4)
|
||||
grid.add_row("numbers", max_size=15)
|
||||
grid.add_row("row", max_size=15, repeat=5)
|
||||
grid.add_areas(
|
||||
clear="col1,row1",
|
||||
numbers="col1-start|col4-end,numbers",
|
||||
zero="col1-start|col2-end,row5",
|
||||
)
|
||||
# Place out widgets in to the layout
|
||||
layout.place(clear=self.c)
|
||||
layout.place(
|
||||
grid.place(clear=self.c)
|
||||
grid.place(
|
||||
*self.buttons.values(), clear=self.ac, numbers=self.numbers, zero=self.zero
|
||||
)
|
||||
|
||||
|
||||
@@ -11,25 +11,24 @@ class GridTest(App):
|
||||
|
||||
async def on_startup(self, event: events.Startup) -> None:
|
||||
|
||||
layout = GridLayout()
|
||||
await self.push_view(View(layout=layout))
|
||||
grid = await self.view.dock_grid()
|
||||
|
||||
layout.add_column(fraction=1, name="left", min_size=20)
|
||||
layout.add_column(size=30, name="center")
|
||||
layout.add_column(fraction=1, name="right")
|
||||
grid.add_column(fraction=1, name="left", min_size=20)
|
||||
grid.add_column(size=30, name="center")
|
||||
grid.add_column(fraction=1, name="right")
|
||||
|
||||
layout.add_row(fraction=1, name="top", min_size=2)
|
||||
layout.add_row(fraction=2, name="middle")
|
||||
layout.add_row(fraction=1, name="bottom")
|
||||
grid.add_row(fraction=1, name="top", min_size=2)
|
||||
grid.add_row(fraction=2, name="middle")
|
||||
grid.add_row(fraction=1, name="bottom")
|
||||
|
||||
layout.add_areas(
|
||||
grid.add_areas(
|
||||
area1="left,top",
|
||||
area2="center,middle",
|
||||
area3="left-start|right-end,bottom",
|
||||
area4="right,top-start|middle-end",
|
||||
)
|
||||
|
||||
layout.place(
|
||||
grid.place(
|
||||
area1=Placeholder(name="area1"),
|
||||
area2=Placeholder(name="area2"),
|
||||
area3=Placeholder(name="area3"),
|
||||
|
||||
@@ -11,16 +11,15 @@ class GridTest(App):
|
||||
|
||||
async def on_startup(self, event: events.Startup) -> None:
|
||||
|
||||
layout = GridLayout()
|
||||
await self.push_view(View(layout=layout))
|
||||
grid = await self.view.dock_grid()
|
||||
|
||||
layout.add_column("col", fraction=1, max_size=20)
|
||||
layout.add_row("row", fraction=1, max_size=10)
|
||||
layout.set_repeat(True, True)
|
||||
layout.add_areas(center="col-2-start|col-4-end,row-2-start|row-3-end")
|
||||
layout.set_align("stretch", "center")
|
||||
grid.add_column("col", fraction=1, max_size=20)
|
||||
grid.add_row("row", fraction=1, max_size=10)
|
||||
grid.set_repeat(True, True)
|
||||
grid.add_areas(center="col-2-start|col-4-end,row-2-start|row-3-end")
|
||||
grid.set_align("stretch", "center")
|
||||
|
||||
layout.place(*(Placeholder() for _ in range(20)), center=Placeholder())
|
||||
grid.place(*(Placeholder() for _ in range(20)), center=Placeholder())
|
||||
|
||||
|
||||
GridTest.run(title="Grid Test")
|
||||
|
||||
@@ -2,7 +2,6 @@ from rich.markdown import Markdown
|
||||
|
||||
from textual import events
|
||||
from textual.app import App
|
||||
from textual.views import DockView
|
||||
from textual.widgets import Header, Footer, Placeholder, ScrollView
|
||||
|
||||
|
||||
@@ -10,25 +9,17 @@ class MyApp(App):
|
||||
"""An example of a very simple Textual App"""
|
||||
|
||||
async def on_load(self, event: events.Load) -> None:
|
||||
await self.bind("q,ctrl+c", "quit", "Quit")
|
||||
await self.bind("b", "view.toggle('sidebar')", "Toggle sidebar")
|
||||
await self.bind("q", "quit", "Quit")
|
||||
|
||||
async def on_startup(self, event: events.Startup) -> None:
|
||||
|
||||
view = await self.push_view(DockView())
|
||||
|
||||
footer = Footer()
|
||||
header = Header()
|
||||
body = ScrollView()
|
||||
sidebar = Placeholder()
|
||||
|
||||
footer.add_key("b", "Toggle sidebar")
|
||||
footer.add_key("q", "Quit")
|
||||
|
||||
await view.dock(header, edge="top")
|
||||
await view.dock(footer, edge="bottom")
|
||||
await view.dock(sidebar, edge="left", size=30, name="sidebar")
|
||||
await view.dock(body, edge="right")
|
||||
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")
|
||||
await self.view.dock(body, edge="right")
|
||||
|
||||
async def get_markdown(filename: str) -> None:
|
||||
with open(filename, "rt") as fh:
|
||||
|
||||
Reference in New Issue
Block a user