Skip to content

Commit

Permalink
feat: cycle widget color feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pommee committed Aug 8, 2024
1 parent 63c1991 commit c024ef4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
35 changes: 32 additions & 3 deletions application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
26 changes: 11 additions & 15 deletions application/styles.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -77,15 +72,16 @@ RichLog {
}

LogLines {
border: round cornflowerblue;
border: gray 10%;
border-title-color: white 100%;
scrollbar-size: 1 1;
border-subtitle-color: white 50%;

.loglines--filter-highlight {
background: #111111;
}
.loglines--filter-highlight-selected {
background: orange;
background: cornflowerblue;
color: auto;
}
}
Expand Down
16 changes: 0 additions & 16 deletions application/widget/containers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions application/widget/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Label,
ListItem,
ListView,
Static,
)

from application.docker_manager import DockerManager
Expand All @@ -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:
Expand Down

0 comments on commit c024ef4

Please sign in to comment.