Merge branch 'main' into list-view

This commit is contained in:
Will McGugan
2022-12-09 10:09:07 +00:00
committed by GitHub
53 changed files with 2682 additions and 394 deletions

View File

@@ -0,0 +1,51 @@
Placeholder {
height: 100%;
}
#top {
height: 50%;
width: 100%;
layout: grid;
grid-size: 2 2;
}
#left {
row-span: 2;
}
#bot {
height: 50%;
width: 100%;
layout: grid;
grid-size: 8 8;
}
#c1 {
row-span: 4;
column-span: 8;
height: 100%;
}
#col1, #col2, #col3 {
width: 1fr;
}
#p1 {
row-span: 4;
column-span: 4;
}
#p2 {
row-span: 2;
column-span: 4;
}
#p3 {
row-span: 2;
column-span: 2;
}
#p4 {
row-span: 1;
column-span: 2;
}

View File

@@ -0,0 +1,39 @@
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical
from textual.widgets import Placeholder
class PlaceholderApp(App):
CSS_PATH = "placeholder.css"
def compose(self) -> ComposeResult:
yield Vertical(
Container(
Placeholder("This is a custom label for p1.", id="p1"),
Placeholder("Placeholder p2 here!", id="p2"),
Placeholder(id="p3"),
Placeholder(id="p4"),
Placeholder(id="p5"),
Placeholder(),
Horizontal(
Placeholder(variant="size", id="col1"),
Placeholder(variant="text", id="col2"),
Placeholder(variant="size", id="col3"),
id="c1",
),
id="bot"
),
Container(
Placeholder(variant="text", id="left"),
Placeholder(variant="size", id="topright"),
Placeholder(variant="text", id="botright"),
id="top",
),
id="content",
)
if __name__ == "__main__":
app = PlaceholderApp()
app.run()

View File

@@ -0,0 +1,66 @@
import csv
import io
from rich.table import Table
from rich.syntax import Syntax
from textual.app import App, ComposeResult
from textual import events
from textual.widgets import TextLog
CSV = """lane,swimmer,country,time
4,Joseph Schooling,Singapore,50.39
2,Michael Phelps,United States,51.14
5,Chad le Clos,South Africa,51.14
6,László Cseh,Hungary,51.14
3,Li Zhuhao,China,51.26
8,Mehdy Metella,France,51.58
7,Tom Shields,United States,51.73
1,Aleksandr Sadovnikov,Russia,51.84"""
CODE = '''\
def loop_first_last(values: Iterable[T]) -> Iterable[tuple[bool, bool, T]]:
"""Iterate and generate a tuple with a flag for first and last value."""
iter_values = iter(values)
try:
previous_value = next(iter_values)
except StopIteration:
return
first = True
for value in iter_values:
yield first, False, previous_value
first = False
previous_value = value
yield first, True, previous_value\
'''
class TextLogApp(App):
def compose(self) -> ComposeResult:
yield TextLog(highlight=True, markup=True)
def on_ready(self) -> None:
"""Called when the DOM is ready."""
text_log = self.query_one(TextLog)
text_log.write(Syntax(CODE, "python", indent_guides=True))
rows = iter(csv.reader(io.StringIO(CSV)))
table = Table(*next(rows))
for row in rows:
table.add_row(*row)
text_log.write(table)
text_log.write("[bold magenta]Write text or any Rich renderable!")
def on_key(self, event: events.Key) -> None:
"""Write Key events to log."""
text_log = self.query_one(TextLog)
text_log.write(event)
if __name__ == "__main__":
app = TextLogApp()
app.run()