Make clock optional in header

This commit is contained in:
Darren Burns
2022-10-06 16:37:41 +01:00
parent 82d68c43a9
commit 035bf80071
2 changed files with 21 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Static, Footer
from textual.widgets import Static, Footer, Header
class JustABox(App):
@@ -12,6 +12,7 @@ class JustABox(App):
]
def compose(self) -> ComposeResult:
yield Header()
yield Static("Hello, world!", id="box1")
yield Footer()

View File

@@ -54,6 +54,7 @@ class HeaderTitle(Widget):
HeaderTitle {
content-align: center middle;
width: 100%;
margin-right: 10;
}
"""
@@ -88,10 +89,27 @@ class Header(Widget):
DEFAULT_CLASSES = "-tall"
def __init__(
self,
show_clock: bool = False,
*,
name: str | None = None,
id: str | None = None,
classes: str | None = None,
):
super().__init__(name=name, id=id, classes=classes)
self.show_clock = show_clock
def compose(self):
yield HeaderIcon()
yield HeaderTitle()
if self.show_clock:
yield HeaderClock()
def watch_tall(self, tall: bool) -> None:
self.set_class(tall, "-tall")
async def on_click(self, event):
def on_click(self):
self.toggle_class("-tall")
def on_mount(self) -> None:
@@ -103,8 +121,3 @@ class Header(Widget):
watch(self.app, "title", set_title)
watch(self.app, "sub_title", set_sub_title)
def compose(self):
yield HeaderIcon()
yield HeaderTitle()
yield HeaderClock()