From 035bf800713a21fe1edddee0df31b1911da125da Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Thu, 6 Oct 2022 16:37:41 +0100 Subject: [PATCH 1/2] Make clock optional in header --- sandbox/darren/just_a_box.py | 3 ++- src/textual/widgets/_header.py | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sandbox/darren/just_a_box.py b/sandbox/darren/just_a_box.py index c499c5b94..920bf7e40 100644 --- a/sandbox/darren/just_a_box.py +++ b/sandbox/darren/just_a_box.py @@ -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() diff --git a/src/textual/widgets/_header.py b/src/textual/widgets/_header.py index d9ff421c9..3ef5ad29c 100644 --- a/src/textual/widgets/_header.py +++ b/src/textual/widgets/_header.py @@ -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() From 029cfb4e867813e7d665d676dcfce347beb156dc Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Thu, 6 Oct 2022 16:41:23 +0100 Subject: [PATCH 2/2] Add docstring to Header --- src/textual/widgets/_header.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/textual/widgets/_header.py b/src/textual/widgets/_header.py index 3ef5ad29c..b75418a1a 100644 --- a/src/textual/widgets/_header.py +++ b/src/textual/widgets/_header.py @@ -70,7 +70,11 @@ class HeaderTitle(Widget): class Header(Widget): - """A header widget with icon and clock.""" + """A header widget with icon and clock. + + Args: + show_clock (bool, optional): True if the clock should be shown on the right of the header. + """ DEFAULT_CSS = """ Header {