Skip to content

Commit

Permalink
playing with css
Browse files Browse the repository at this point in the history
  • Loading branch information
ralequi committed Nov 29, 2024
1 parent 031be7f commit 147d6e9
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 103 deletions.
231 changes: 128 additions & 103 deletions pystorclitui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
# See LICENSE for details.

from textual._easing import EASING
from textual.app import App
from textual.reactive import Reactive
from textual.views import DockView, GridView
from textual.view import View
from textual.widgets import Button, Footer, TreeControl, ScrollView, Placeholder
from pystorcli import StorCLI, __version__ as pystorcli_version

from .storcliTree import StorcliTree, StorcliEntry, StorcliClick, SCEntryType
from textual.app import App, ComposeResult
from textual.reactive import var, Reactive
from textual.widgets import DirectoryTree, Button, Footer, Header, Placeholder
from textual.containers import Container, VerticalScroll
from pystorcli2 import StorCLI, __version__ as pystorcli_version

# from .storcliTree import StorcliTree, StorcliEntry, StorcliClick, SCEntryType
from . import header
from .version import __version__
from .storclicmdtui import StorcliCMDTUI, StorcliExec
from .views.drive import DriveView
# from .views.drive import DriveView
from .widgets.messageBox import MessageBox

from typing import Optional


class PyStorCLITUI(App):
"""The pystorclitui application."""
# Global variables
storcli: StorCLI

# Reactives
show_tree = Reactive(True)
CSS_PATH = "pystorclitui.css"

# Widgets
tree: StorcliTree
# Reactives
show_tree = var(True)

# Views
mainView: DockView
treeView: ScrollView
def watch_show_tree(self, show_tree: bool) -> None:
"""Called when show_tree is modified."""
self.set_class(show_tree, "-show-tree")

def __init__(self, storcli: StorCLI = None, *args, **kwargs):
def __init__(self, storcli: Optional[StorCLI] = None, *args, **kwargs):
# Storcli instance
if storcli is None:
cmdRunner = StorcliCMDTUI()
Expand All @@ -45,114 +45,139 @@ def __init__(self, storcli: StorCLI = None, *args, **kwargs):
# super init
super().__init__(*args, **kwargs)

def getEmptyMainView(self):
"""Return the basic view."""
ret = Button(
label="Please, select a Raid Card, Enclosure, Virtual Drive or Physical Drive to begin.",
style="bold white on rgb(50,57,50)",
)
def compose(self) -> ComposeResult:
# Header
yield header.Header()

with Container():
# Content

return ret
# Left tree
yield DirectoryTree('/home/rleira', id="tree-view")

async def on_load(self) -> None:
"""Bind keys here."""
await self.bind("t", "toogle_tree", "Toggle device tree")
await self.bind("r", "reload", "Reload StorCLI")
await self.bind("q", "quit", "Quit")
# Message Box
# yield MessageBox("Loading...", title="Storcli call in progress...")

# Bind storcli events
self.storcli._StorCLI__cmdrunner.set_parent(self)
# Footer
yield Footer()

def action_toogle_tree(self) -> None:
"""Called when user hits 't' key."""
self.show_tree = not self.show_tree
# def getEmptyMainView(self):
# """Return the basic view."""
# ret = Button(
# label="Please, select a Raid Card, Enclosure, Virtual Drive or Physical Drive to begin.",
# style="bold white on rgb(50,57,50)",
# )

def watch_show_tree(self, show_tree: bool) -> None:
"""Called when show_tree changes."""
# self.treeView.animate("layout_offset_x", 0 if show_tree else -40)
self.treeView.visible = show_tree
# return ret

# async def on_load(self) -> None:
# """Bind keys here."""
# await self.bind("t", "toogle_tree", "Toggle device tree")
# await self.bind("r", "reload", "Reload StorCLI")
# await self.bind("q", "quit", "Quit")

# # Bind storcli events
# self.storcli._StorCLI__cmdrunner.set_parent(self)

# def action_toogle_tree(self) -> None:
# """Called when user hits 't' key."""
# self.show_tree = not self.show_tree

async def _set_main_view(self, view: View):
# Clean up layout
self.mainView.layout.docks.clear()
self.mainView.widgets.clear()
# def watch_show_tree(self, show_tree: bool) -> None:
# """Called when show_tree changes."""
# # self.treeView.animate("layout_offset_x", 0 if show_tree else -40)
# self.treeView.visible = show_tree

# Set the new layout/view
await self.mainView.dock(view)
# async def _set_main_view(self, view: View):
# # Clean up layout
# self.mainView.layout.docks.clear()
# self.mainView.widgets.clear()

async def action_reload(self) -> None:
"""Called when user hits 'r' key."""
# Reload the tree
await self.tree.reload()
# # Set the new layout/view
# await self.mainView.dock(view)

# Set default layout
await self._set_main_view(self.getEmptyMainView())
# async def action_reload(self) -> None:
# """Called when user hits 'r' key."""
# # Reload the tree
# await self.tree.reload()

# Refresh
self.refresh()
# # Set default layout
# await self._set_main_view(self.getEmptyMainView())

# # Refresh
# self.refresh()

async def on_mount(self) -> None:
"""Called when application mode is ready."""

# Create the required Views
self.mainView = DockView()
# # Create the required Views
# self.mainView = DockView()
self.query_one(DirectoryTree).focus()

# Header
headr = header.Header()
headr.center_title = f"PyStorCLI-TUI v{__version__}"
headr.left_title = f"PyStorCLI v{pystorcli_version}"
self.query_one(
header.Header).center_title = f"PyStorCLI-TUI v{__version__}"
self.query_one(
header.Header).left_title = f"PyStorCLI v{pystorcli_version}"
storcli_version = self.storcli.version
headr.right_title = f"StorCLI v{storcli_version}"
await self.view.dock(headr, edge="top")
self.query_one(
header.Header).right_title = f"StorCLI v{storcli_version}"
# await self.view.dock(headr, edge="top")

# Footer
footer = Footer()
await self.view.dock(footer, edge="bottom")

# Device Tree
self.tree = StorcliTree()
await self.tree.root.expand()
self.treeView = ScrollView(self.tree)

# Message box
self.messageBox = MessageBox(
"Loading...", title="Storcli call in progress...")
grid = await self.view.dock_grid(z=10)

grid.add_column(fraction=1, name="left")
grid.add_column(min_size=30, max_size=50, name="center")
grid.add_column(fraction=1, name="right")
grid.add_row(fraction=10, name="top")
grid.add_row(fraction=1, name="middle", max_size=5, min_size=3)
grid.add_row(fraction=10, name="bottom")

grid.add_areas(
area1="left,top",
area2="center,middle",
area3="left-start|right-end,bottom",
area4="right,top-start|middle-end",
)
grid.place(area2=self.messageBox)

self.messageBox.visible = False

# Mount the Layout
await self.view.dock(self.treeView, edge="left", size=32)
await self.view.dock(self.mainView)
await self.mainView.dock(self.getEmptyMainView())

async def handle_storcli_click(self, message: StorcliClick) -> None:
"""Called in response to a tree click."""

data: StorcliEntry = message.entry

if data.type == SCEntryType.DriveType:
# Show the drive view
await self._set_main_view(DriveView(data.drive))
# await self.view.dock(footer, edge="bottom")

# # Device Tree
# self.tree = StorcliTree()
# await self.tree.root.expand()
# self.treeView = ScrollView(self.tree)

# # Message box
# self.messageBox = MessageBox(
# "Loading...", title="Storcli call in progress...")
# grid = await self.view.dock_grid(z=10)

# grid.add_column(fraction=1, name="left")
# grid.add_column(min_size=30, max_size=50, name="center")
# grid.add_column(fraction=1, name="right")
# grid.add_row(fraction=10, name="top")
# grid.add_row(fraction=1, name="middle", max_size=5, min_size=3)
# grid.add_row(fraction=10, name="bottom")

# grid.add_areas(
# area1="left,top",
# area2="center,middle",
# area3="left-start|right-end,bottom",
# area4="right,top-start|middle-end",
# )
# grid.place(area2=self.messageBox)

# self.messageBox.visible = False

# # Mount the Layout
# await self.view.dock(self.treeView, edge="left", size=32)
# await self.view.dock(self.mainView)
# await self.mainView.dock(self.getEmptyMainView())

# async def handle_storcli_click(self, message: StorcliClick) -> None:
# """Called in response to a tree click."""

# data: StorcliEntry = message.entry

# if data.type == SCEntryType.DriveType:
# # Show the drive view
# await self._set_main_view(DriveView(data.drive))

def on_storcli_exec_storcli_exec(self, message: StorcliExec) -> None:
sdfsfdf

def on_storcli_exec(self, message: StorcliExec) -> None:
sdfsfdf

async def handle_storcli_exec(self, message: StorcliExec) -> None:
"""Called in response to a storcli operation."""
safasfasf

self.messageBox.content = 'Running: ' + ' '.join(message.cmdArgs)
self.messageBox.visible = not message.finished
self.messageBox.visible = True # not message.finished
# self.messageBox.refresh()
26 changes: 26 additions & 0 deletions pystorclitui/pystorclitui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Screen {
background: $surface-darken-1;
}

#tree-view {
display: none;
scrollbar-gutter: stable;
overflow: auto;
width: auto;
height: 100%;
dock: left;
}

PyStorCLITUI.-show-tree #tree-view {
display: block;
max-width: 50%;
}


#code-view {
overflow: auto scroll;
min-width: 100%;
}
#code {
width: auto;
}

0 comments on commit 147d6e9

Please sign in to comment.