From c024ef45e02db9886f5135478edda94d65c75cb5 Mon Sep 17 00:00:00 2001 From: pommee Date: Thu, 8 Aug 2024 21:23:33 +0200 Subject: [PATCH] feat: cycle widget color feedback --- application/main.py | 35 +++++++++++++++++++++++++++++--- application/styles.tcss | 26 ++++++++++-------------- application/widget/containers.py | 16 --------------- application/widget/images.py | 2 -- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/application/main.py b/application/main.py index 2f76c80..d4aa4bd 100644 --- a/application/main.py +++ b/application/main.py @@ -10,12 +10,13 @@ from textual.app import App, ComposeResult from textual.binding import Binding from textual.containers import Vertical +from textual.events import DescendantFocus from textual.logging import TextualHandler from textual.widgets import ( ContentSwitcher, Footer, Input, - Rule, + ListView, TabbedContent, ) from yaspin import yaspin @@ -127,8 +128,11 @@ def compose(self) -> ComposeResult: yield TopBar(get_current_version()) with Vertical(id="containers-and-images"): - yield PockerContainers(id="PockerContainers", docker_manager=docker_manager) - yield Rule("horizontal") + yield PockerContainers( + id="PockerContainers", + docker_manager=docker_manager, + classes="active-widget", + ) yield PockerImages(id="PockerImages", docker_manager=docker_manager) yield self.content_window yield Footer() @@ -140,6 +144,31 @@ async def on_mount(self) -> None: self.list_view = self.query_one(PockerContainers).query_one( "#ContainersAndImagesListView" ) + self.currently_focused_widget = self.focused + + @on(DescendantFocus) + def focus_switched(self, focus: DescendantFocus): + widget = focus.widget + + try: + self.currently_focused_widget.remove_class("active-widget") + except AttributeError: + pass # Previous widget might not have a border. + + if type(widget) is ListView: + next_focused_widget = widget.parent + widget.parent.add_class("active-widget") + elif "ContentTabs" in str(type(widget)): + underline = widget.query_one("Underline") + underline.add_class("active-widget") + next_focused_widget = underline + else: + self.log(widget) + pass + next_focused_widget = widget + widget.add_class("active-widget") + + self.currently_focused_widget = next_focused_widget def read_and_apply_config(self): logs = self.query_one("#logs", LogLines) diff --git a/application/styles.tcss b/application/styles.tcss index d4363f2..394449a 100644 --- a/application/styles.tcss +++ b/application/styles.tcss @@ -23,32 +23,27 @@ TopBar { } } +.active-widget { + border: cornflowerblue; +} + #containers-and-images { width: 20%; margin: 1; } -.containers-and-images-header { - margin-bottom: 1; - width: auto; - align: center middle; - text-style: bold; -} - PockerContainers { border-title-align: center; + border-title-color: white 100%; height: 50%; -} - -Rule { - margin: 0; - padding: 0; + border: gray 10%; } PockerImages { border-title-align: center; + border-title-color: white 100%; height: 50%; - border: none; + border: gray 10%; } VerticalScroll { @@ -77,7 +72,8 @@ RichLog { } LogLines { - border: round cornflowerblue; + border: gray 10%; + border-title-color: white 100%; scrollbar-size: 1 1; border-subtitle-color: white 50%; @@ -85,7 +81,7 @@ LogLines { background: #111111; } .loglines--filter-highlight-selected { - background: orange; + background: cornflowerblue; color: auto; } } diff --git a/application/widget/containers.py b/application/widget/containers.py index e6bf83b..0bf221a 100644 --- a/application/widget/containers.py +++ b/application/widget/containers.py @@ -1,13 +1,10 @@ from docker.models.containers import Container from textual.app import ComposeResult -from textual.containers import Horizontal from textual.widget import Widget from textual.widgets import ( - Button, Label, ListItem, ListView, - Static, ) from application.docker_manager import DockerManager @@ -35,7 +32,6 @@ def __init__( def compose(self) -> ComposeResult: self.list_view = ListView(id="ContainersAndImagesListView") - yield Static("Containers", classes="containers-and-images-header") with self.list_view: container: Container for name, container in self.docker_manager.containers.items(): @@ -44,9 +40,6 @@ def compose(self) -> ComposeResult: id=name, classes=self.docker_manager.status(container), ) - with Horizontal(id="startstopbuttons"): - yield Button("Start all", id="startAllContainers") - yield Button("Stop all", id="stopAllContainers") def on_list_view_highlighted(self, highlighted: ListView.Highlighted): if self.first_run: @@ -67,15 +60,6 @@ async def on_mount(self) -> None: reverse=True, ) - def on_button_pressed(self, event: Button.Pressed) -> None: - id = str(event.button.id) - if id == "stopAllContainers": - for container in self.docker_manager.containers.values(): - container.stop() - elif id == "startAllContainers": - for container in self.docker_manager.containers.values(): - container.start() - def live_status_events_task(self): event: dict[str, str] for event in self.docker_manager.client.events(decode=True): diff --git a/application/widget/images.py b/application/widget/images.py index 48edec3..e5a089f 100644 --- a/application/widget/images.py +++ b/application/widget/images.py @@ -5,7 +5,6 @@ Label, ListItem, ListView, - Static, ) from application.docker_manager import DockerManager @@ -29,7 +28,6 @@ def __init__( ) def compose(self) -> ComposeResult: - yield Static("Images", classes="containers-and-images-header") with ListView(id="ContainersAndImagesListView"): image: Image for image in self.docker_manager.images: