Skip to content

Commit

Permalink
Make all styles reference examples capable of being run standalone
Browse files Browse the repository at this point in the history
Also move the declarations of the stylesheets into the app classes.

See Textualize#3650
  • Loading branch information
davep committed Nov 8, 2023
1 parent 38e4cc0 commit 4140962
Show file tree
Hide file tree
Showing 63 changed files with 306 additions and 63 deletions.
6 changes: 5 additions & 1 deletion docs/examples/styles/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@


class AlignApp(App):
CSS_PATH = "align.tcss"

def compose(self):
yield Label("Vertical alignment with [b]Textual[/]", classes="box")
yield Label("Take note, browsers.", classes="box")


app = AlignApp(css_path="align.tcss")
if __name__ == "__main__":
app = AlignApp()
app.run()
4 changes: 4 additions & 0 deletions docs/examples/styles/align_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ def compose(self) -> ComposeResult:
yield Container(Label("left bottom"), id="left-bottom")
yield Container(Label("center bottom"), id="center-bottom")
yield Container(Label("right bottom"), id="right-bottom")


if __name__ == "__main__":
AlignAllApp().run()
6 changes: 5 additions & 1 deletion docs/examples/styles/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


class BackgroundApp(App):
CSS_PATH = "background.tcss"

def compose(self):
yield Label("Widget 1", id="static1")
yield Label("Widget 2", id="static2")
yield Label("Widget 3", id="static3")


app = BackgroundApp(css_path="background.tcss")
if __name__ == "__main__":
app = BackgroundApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/background_transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class BackgroundTransparencyApp(App):
"""Simple app to exemplify different transparency settings."""

CSS_PATH = "background_transparency.tcss"

def compose(self) -> ComposeResult:
yield Static("10%", id="t10")
yield Static("20%", id="t20")
Expand All @@ -18,4 +20,6 @@ def compose(self) -> ComposeResult:
yield Static("100%", id="t100")


app = BackgroundTransparencyApp(css_path="background_transparency.tcss")
if __name__ == "__main__":
app = BackgroundTransparencyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/border.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


class BorderApp(App):
CSS_PATH = "border.tcss"

def compose(self):
yield Label("My border is solid red", id="label1")
yield Label("My border is dashed green", id="label2")
yield Label("My border is tall blue", id="label3")


app = BorderApp(css_path="border.tcss")
if __name__ == "__main__":
app = BorderApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/border_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class AllBordersApp(App):
CSS_PATH = "border_all.tcss"

def compose(self):
yield Grid(
Label("ascii", id="ascii"),
Expand All @@ -24,4 +26,6 @@ def compose(self):
)


app = AllBordersApp(css_path="border_all.tcss")
if __name__ == "__main__":
app = AllBordersApp()
app.run()
5 changes: 3 additions & 2 deletions docs/examples/styles/border_sub_title_align_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def make_label_container( # (11)!


class BorderSubTitleAlignAll(App[None]):
CSS_PATH = "border_sub_title_align_all.tcss"

def compose(self):
with Grid():
yield make_label_container( # (1)!
Expand Down Expand Up @@ -68,7 +70,6 @@ def compose(self):
)


app = BorderSubTitleAlignAll(css_path="border_sub_title_align_all.tcss")

if __name__ == "__main__":
app = BorderSubTitleAlignAll()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/border_subtitle_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class BorderSubtitleAlignApp(App):
CSS_PATH = "border_subtitle_align.tcss"

def compose(self):
lbl = Label("My subtitle is on the left.", id="label1")
lbl.border_subtitle = "< Left"
Expand All @@ -17,4 +19,6 @@ def compose(self):
yield lbl


app = BorderSubtitleAlignApp(css_path="border_subtitle_align.tcss")
if __name__ == "__main__":
app = BorderSubtitleAlignApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/border_title_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class BorderTitleAlignApp(App):
CSS_PATH = "border_title_align.tcss"

def compose(self):
lbl = Label("My title is on the left.", id="label1")
lbl.border_title = "< Left"
Expand All @@ -17,4 +19,6 @@ def compose(self):
yield lbl


app = BorderTitleAlignApp(css_path="border_title_align.tcss")
if __name__ == "__main__":
app = BorderTitleAlignApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/box_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@


class BoxSizingApp(App):
CSS_PATH = "box_sizing.tcss"

def compose(self):
yield Static("I'm using border-box!", id="static1")
yield Static("I'm using content-box!", id="static2")


app = BoxSizingApp(css_path="box_sizing.tcss")
if __name__ == "__main__":
app = BoxSizingApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


class ColorApp(App):
CSS_PATH = "color.tcss"

def compose(self):
yield Label("I'm red!", id="label1")
yield Label("I'm rgb(0, 255, 0)!", id="label2")
yield Label("I'm hsl(240, 100%, 50%)!", id="label3")


app = ColorApp(css_path="color.tcss")
if __name__ == "__main__":
app = ColorApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/color_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class ColorApp(App):
CSS_PATH = "color_auto.tcss"

def compose(self):
yield Label("The quick brown fox jumps over the lazy dog!", id="lbl1")
yield Label("The quick brown fox jumps over the lazy dog!", id="lbl2")
Expand All @@ -11,4 +13,6 @@ def compose(self):
yield Label("The quick brown fox jumps over the lazy dog!", id="lbl5")


app = ColorApp(css_path="color_auto.tcss")
if __name__ == "__main__":
app = ColorApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/column_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "column_span.tcss"

def compose(self):
yield Grid(
Placeholder(id="p1"),
Expand All @@ -16,4 +18,6 @@ def compose(self):
)


app = MyApp(css_path="column_span.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/content_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


class ContentAlignApp(App):
CSS_PATH = "content_align.tcss"

def compose(self):
yield Label("With [i]content-align[/] you can...", id="box1")
yield Label("...[b]Easily align content[/]...", id="box2")
yield Label("...Horizontally [i]and[/] vertically!", id="box3")


app = ContentAlignApp(css_path="content_align.tcss")
if __name__ == "__main__":
app = ContentAlignApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/content_align_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class AllContentAlignApp(App):
CSS_PATH = "content_align_all.tcss"

def compose(self):
yield Label("left top", id="left-top")
yield Label("center top", id="center-top")
Expand All @@ -15,4 +17,6 @@ def compose(self):
yield Label("right bottom", id="right-bottom")


app = AllContentAlignApp(css_path="content_align_all.tcss")
if __name__ == "__main__":
app = AllContentAlignApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


class DisplayApp(App):
CSS_PATH = "display.tcss"

def compose(self):
yield Static("Widget 1")
yield Static("Widget 2", classes="remove")
yield Static("Widget 3")


app = DisplayApp(css_path="display.tcss")
if __name__ == "__main__":
app = DisplayApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/dock_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class DockAllApp(App):
CSS_PATH = "dock_all.tcss"

def compose(self):
yield Container(
Container(Label("left"), id="left"),
Expand All @@ -14,4 +16,6 @@ def compose(self):
)


app = DockAllApp(css_path="dock_all.tcss")
if __name__ == "__main__":
app = DockAllApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class GridApp(App):
CSS_PATH = "grid.tcss"

def compose(self):
yield Static("Grid cell 1\n\nrow-span: 3;\ncolumn-span: 2;", id="static1")
yield Static("Grid cell 2", id="static2")
Expand All @@ -13,4 +15,6 @@ def compose(self):
yield Static("Grid cell 7", id="static7")


app = GridApp(css_path="grid.tcss")
if __name__ == "__main__":
app = GridApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "grid_columns.tcss"

def compose(self):
yield Grid(
Label("1fr"),
Expand All @@ -19,4 +21,6 @@ def compose(self):
)


app = MyApp(css_path="grid_columns.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid_gutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "grid_gutter.tcss"

def compose(self):
yield Grid(
Label("1"),
Expand All @@ -17,4 +19,6 @@ def compose(self):
)


app = MyApp(css_path="grid_gutter.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "grid_rows.tcss"

def compose(self):
yield Grid(
Label("1fr"),
Expand All @@ -19,4 +21,6 @@ def compose(self):
)


app = MyApp(css_path="grid_rows.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid_size_both.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "grid_size_both.tcss"

def compose(self):
yield Grid(
Label("1"),
Expand All @@ -14,4 +16,6 @@ def compose(self):
)


app = MyApp(css_path="grid_size_both.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/grid_size_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MyApp(App):
CSS_PATH = "grid_size_columns.tcss"

def compose(self):
yield Grid(
Label("1"),
Expand All @@ -14,4 +16,6 @@ def compose(self):
)


app = MyApp(css_path="grid_size_columns.tcss")
if __name__ == "__main__":
app = MyApp()
app.run()
6 changes: 5 additions & 1 deletion docs/examples/styles/height.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@


class HeightApp(App):
CSS_PATH = "height.tcss"

def compose(self):
yield Widget()


app = HeightApp(css_path="height.tcss")
if __name__ == "__main__":
app = HeightApp()
app.run()
Loading

0 comments on commit 4140962

Please sign in to comment.