Skip to content

Commit

Permalink
Init Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jeckel committed Oct 31, 2024
1 parent bd0e52a commit 5c2f288
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/presentation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, TabbedContent, TabPane
from textual.containers import Container

from models import Project

from .composer import ComposerContainer
from .docker import DockerContainer
from .summary import ProjectSummaryContainer
from .component import Sidebar


class MainApp(App):

class MainApp(App[None]):
"""A Textual app to manage stopwatches."""

TITLE = "DX Companion"
BINDINGS = [
("d", "toggle_dark", "Toggle dark mode"),
("ctrl+s", "toggle_sidebar", "Toggle sidebar"),
]
DEFAULT_CSS = """
Screen {
layers: sidebar;
}
"""
CSS_PATH = "../tcss/layout.tcss"
_project: Project

Expand All @@ -24,6 +33,7 @@ def __init__(self, project: Project):
self.title = f"DX Companion - {project.name}"

def compose(self) -> ComposeResult:
yield Sidebar(project=self._project, classes="-hidden")
yield Header()
with TabbedContent(initial="summary-pan"):
with TabPane(title="Summary", id="summary-pan"):
Expand All @@ -33,3 +43,6 @@ def compose(self) -> ComposeResult:
with TabPane(title="Docker", id="docker-pan"):
yield DockerContainer(project=self._project)
yield Footer()

def action_toggle_sidebar(self) -> None:
self.query_one(Sidebar).toggle_class("-hidden")
1 change: 1 addition & 0 deletions src/presentation/component/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .terminal_modal import TerminalModal
from .terminal import Terminal, ShellCommand, NonShellCommand, CommandType
from .sidebar import Sidebar
58 changes: 58 additions & 0 deletions src/presentation/component/sidebar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from textual.app import ComposeResult
from textual.containers import Container
from textual.widgets import OptionList
from textual.widgets.option_list import Option, Separator


from models import Project


class Sidebar(Container):
DEFAULT_CSS = """
Sidebar {
width: 30;
height: 100%;
dock: left;
background: $primary-background;
layer: sidebar;
OptionList {
margin: 1 0;
border: none;
}
}
Sidebar.-hidden {
display: none;
}
"""

def __init__(self, project: Project, **kwargs):
self.project = project
super().__init__(**kwargs)
self.add_class("-hidden")

def compose(self) -> ComposeResult:
yield OptionList(
*(Option(action.label) for action in self.project.actions)
)
# yield OptionList(
# Option("Aerilon", id="aer"),
# Option("Aquaria", id="aqu"),
# Separator(),
# Option("Canceron", id="can"),
# Option("Caprica", id="cap", disabled=True),
# Separator(),
# Option("Gemenon", id="gem"),
# Separator(),
# Option("Leonis", id="leo"),
# Option("Libran", id="lib"),
# Separator(),
# Option("Picon", id="pic"),
# Separator(),
# Option("Sagittaron", id="sag"),
# Option("Scorpia", id="sco"),
# Separator(),
# Option("Tauron", id="tau"),
# Separator(),
# Option("Virgon", id="vir"),
# )
10 changes: 9 additions & 1 deletion src/presentation/composer/composer_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@


class ComposerContainer(Container):
BINDINGS = [
("ctrl+r", "refresh", "Refresh"),
]
DEFAULT_CSS = """
ComposerContainer {
Container {
Expand Down Expand Up @@ -46,10 +49,13 @@ def compose(self) -> ComposeResult:
)
yield Horizontal(id="composer-actions")

async def on_mount(self):
def action_refresh(self) -> None:
self.loading = True
self._load_composer()

async def on_mount(self):
self.action_refresh()

@work(exclusive=True, thread=True)
async def _load_composer(self) -> dict[str, str]:
return ServiceContainer.composer_client().updatable_packages(self.project)
Expand Down Expand Up @@ -91,6 +97,8 @@ async def refresh_listview(self, event: Worker.StateChanged) -> None:
# self.log(f"Bouton {script}")
new_button = ComposerScriptButton(script_name=script)
await scripts.mount(new_button)
await scripts.mount(Label(" "))
await scripts.mount(Button.success('Refresh'))

self.loading = False

Expand Down

0 comments on commit 5c2f288

Please sign in to comment.