Skip to content

Commit

Permalink
How to (#2592)
Browse files Browse the repository at this point in the history
* words

* how to

* Apply suggestions from code review

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

---------

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
  • Loading branch information
willmcgugan and rodrigogiraoserrao committed May 17, 2023
1 parent c12fa0e commit f820598
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/custom_theme/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@
<meta property="og:description" content="Textual is a TUI framework for Python, inspired by modern web development.">
<meta property="og:image" content="https://raw.githubusercontent.com/Textualize/textual/main/imgs/textual.png">

<style>

@font-face {
font-family: "Virgil";
src: url("https://unpkg.com/@excalidraw/excalidraw@0.12.0/dist/excalidraw-assets/Virgil.woff2");
}
@font-face {
font-family: "Cascadia";
src: url("https://unpkg.com/@excalidraw/excalidraw@0.12.0/dist/excalidraw-assets/Cascadia.woff2");
}

</style>

{% endblock %}
Empty file added docs/examples/how-to/layout.css
Empty file.
69 changes: 69 additions & 0 deletions docs/examples/how-to/layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from textual.app import App, ComposeResult
from textual.containers import HorizontalScroll, VerticalScroll
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class Tweet(Placeholder):
DEFAULT_CSS = """
Tweet {
height: 5;
width: 1fr;
border: tall $background;
}
"""


class Column(VerticalScroll):
DEFAULT_CSS = """
Column {
height: 1fr;
width: 32;
margin: 0 2;
}
"""

def compose(self) -> ComposeResult:
for tweet_no in range(1, 20):
yield Tweet(id=f"Tweet{tweet_no}")


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")
with HorizontalScroll():
yield Column()
yield Column()
yield Column()
yield Column()


class LayoutApp(App):
CSS_PATH = "layout.css"

def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
27 changes: 27 additions & 0 deletions docs/examples/how-to/layout01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder): # (1)!
pass


class Footer(Placeholder): # (2)!
pass


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header") # (3)!
yield Footer(id="Footer") # (4)!


class LayoutApp(App):
def on_mount(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
37 changes: 37 additions & 0 deletions docs/examples/how-to/layout02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")


class LayoutApp(App):
def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
48 changes: 48 additions & 0 deletions docs/examples/how-to/layout03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class ColumnsContainer(Placeholder):
DEFAULT_CSS = """
ColumnsContainer {
width: 1fr;
height: 1fr;
border: solid white;
}
""" # (1)!


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")
yield ColumnsContainer(id="Columns")


class LayoutApp(App):
def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
39 changes: 39 additions & 0 deletions docs/examples/how-to/layout04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from textual.app import App, ComposeResult
from textual.containers import HorizontalScroll
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")
yield HorizontalScroll() # (1)!


class LayoutApp(App):
def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
55 changes: 55 additions & 0 deletions docs/examples/how-to/layout05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from textual.app import App, ComposeResult
from textual.containers import HorizontalScroll, VerticalScroll
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class Tweet(Placeholder):
pass


class Column(VerticalScroll):
def compose(self) -> ComposeResult:
for tweet_no in range(1, 20):
yield Tweet(id=f"Tweet{tweet_no}")


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")
with HorizontalScroll():
yield Column()
yield Column()
yield Column()
yield Column()


class LayoutApp(App):
CSS_PATH = "layout.css"

def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
69 changes: 69 additions & 0 deletions docs/examples/how-to/layout06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from textual.app import App, ComposeResult
from textual.containers import HorizontalScroll, VerticalScroll
from textual.screen import Screen
from textual.widgets import Placeholder


class Header(Placeholder):
DEFAULT_CSS = """
Header {
height: 3;
dock: top;
}
"""


class Footer(Placeholder):
DEFAULT_CSS = """
Footer {
height: 3;
dock: bottom;
}
"""


class Tweet(Placeholder):
DEFAULT_CSS = """
Tweet {
height: 5;
width: 1fr;
border: tall $background;
}
"""


class Column(VerticalScroll):
DEFAULT_CSS = """
Column {
height: 1fr;
width: 32;
margin: 0 2;
}
"""

def compose(self) -> ComposeResult:
for tweet_no in range(1, 20):
yield Tweet(id=f"Tweet{tweet_no}")


class TweetScreen(Screen):
def compose(self) -> ComposeResult:
yield Header(id="Header")
yield Footer(id="Footer")
with HorizontalScroll():
yield Column()
yield Column()
yield Column()
yield Column()


class LayoutApp(App):
CSS_PATH = "layout.css"

def on_ready(self) -> None:
self.push_screen(TweetScreen())


if __name__ == "__main__":
app = LayoutApp()
app.run()
Loading

0 comments on commit f820598

Please sign in to comment.