Skip to content

Commit 147d6e9

Browse files
committed
playing with css
1 parent 031be7f commit 147d6e9

File tree

2 files changed

+154
-103
lines changed

2 files changed

+154
-103
lines changed

pystorclitui/app.py

Lines changed: 128 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44
# See LICENSE for details.
55

66
from textual._easing import EASING
7-
from textual.app import App
8-
from textual.reactive import Reactive
9-
from textual.views import DockView, GridView
10-
from textual.view import View
11-
from textual.widgets import Button, Footer, TreeControl, ScrollView, Placeholder
12-
from pystorcli import StorCLI, __version__ as pystorcli_version
13-
14-
from .storcliTree import StorcliTree, StorcliEntry, StorcliClick, SCEntryType
7+
from textual.app import App, ComposeResult
8+
from textual.reactive import var, Reactive
9+
from textual.widgets import DirectoryTree, Button, Footer, Header, Placeholder
10+
from textual.containers import Container, VerticalScroll
11+
from pystorcli2 import StorCLI, __version__ as pystorcli_version
12+
13+
# from .storcliTree import StorcliTree, StorcliEntry, StorcliClick, SCEntryType
1514
from . import header
1615
from .version import __version__
1716
from .storclicmdtui import StorcliCMDTUI, StorcliExec
18-
from .views.drive import DriveView
17+
# from .views.drive import DriveView
1918
from .widgets.messageBox import MessageBox
2019

20+
from typing import Optional
21+
2122

2223
class PyStorCLITUI(App):
2324
"""The pystorclitui application."""
2425
# Global variables
2526
storcli: StorCLI
2627

27-
# Reactives
28-
show_tree = Reactive(True)
28+
CSS_PATH = "pystorclitui.css"
2929

30-
# Widgets
31-
tree: StorcliTree
30+
# Reactives
31+
show_tree = var(True)
3232

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

37-
def __init__(self, storcli: StorCLI = None, *args, **kwargs):
37+
def __init__(self, storcli: Optional[StorCLI] = None, *args, **kwargs):
3838
# Storcli instance
3939
if storcli is None:
4040
cmdRunner = StorcliCMDTUI()
@@ -45,114 +45,139 @@ def __init__(self, storcli: StorCLI = None, *args, **kwargs):
4545
# super init
4646
super().__init__(*args, **kwargs)
4747

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

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

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

63-
# Bind storcli events
64-
self.storcli._StorCLI__cmdrunner.set_parent(self)
61+
# Footer
62+
yield Footer()
6563

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

70-
def watch_show_tree(self, show_tree: bool) -> None:
71-
"""Called when show_tree changes."""
72-
# self.treeView.animate("layout_offset_x", 0 if show_tree else -40)
73-
self.treeView.visible = show_tree
71+
# return ret
72+
73+
# async def on_load(self) -> None:
74+
# """Bind keys here."""
75+
# await self.bind("t", "toogle_tree", "Toggle device tree")
76+
# await self.bind("r", "reload", "Reload StorCLI")
77+
# await self.bind("q", "quit", "Quit")
78+
79+
# # Bind storcli events
80+
# self.storcli._StorCLI__cmdrunner.set_parent(self)
81+
82+
# def action_toogle_tree(self) -> None:
83+
# """Called when user hits 't' key."""
84+
# self.show_tree = not self.show_tree
7485

75-
async def _set_main_view(self, view: View):
76-
# Clean up layout
77-
self.mainView.layout.docks.clear()
78-
self.mainView.widgets.clear()
86+
# def watch_show_tree(self, show_tree: bool) -> None:
87+
# """Called when show_tree changes."""
88+
# # self.treeView.animate("layout_offset_x", 0 if show_tree else -40)
89+
# self.treeView.visible = show_tree
7990

80-
# Set the new layout/view
81-
await self.mainView.dock(view)
91+
# async def _set_main_view(self, view: View):
92+
# # Clean up layout
93+
# self.mainView.layout.docks.clear()
94+
# self.mainView.widgets.clear()
8295

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

88-
# Set default layout
89-
await self._set_main_view(self.getEmptyMainView())
99+
# async def action_reload(self) -> None:
100+
# """Called when user hits 'r' key."""
101+
# # Reload the tree
102+
# await self.tree.reload()
90103

91-
# Refresh
92-
self.refresh()
104+
# # Set default layout
105+
# await self._set_main_view(self.getEmptyMainView())
106+
107+
# # Refresh
108+
# self.refresh()
93109

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

97-
# Create the required Views
98-
self.mainView = DockView()
113+
# # Create the required Views
114+
# self.mainView = DockView()
115+
self.query_one(DirectoryTree).focus()
99116

100117
# Header
101-
headr = header.Header()
102-
headr.center_title = f"PyStorCLI-TUI v{__version__}"
103-
headr.left_title = f"PyStorCLI v{pystorcli_version}"
118+
self.query_one(
119+
header.Header).center_title = f"PyStorCLI-TUI v{__version__}"
120+
self.query_one(
121+
header.Header).left_title = f"PyStorCLI v{pystorcli_version}"
104122
storcli_version = self.storcli.version
105-
headr.right_title = f"StorCLI v{storcli_version}"
106-
await self.view.dock(headr, edge="top")
123+
self.query_one(
124+
header.Header).right_title = f"StorCLI v{storcli_version}"
125+
# await self.view.dock(headr, edge="top")
107126

108127
# Footer
109-
footer = Footer()
110-
await self.view.dock(footer, edge="bottom")
111-
112-
# Device Tree
113-
self.tree = StorcliTree()
114-
await self.tree.root.expand()
115-
self.treeView = ScrollView(self.tree)
116-
117-
# Message box
118-
self.messageBox = MessageBox(
119-
"Loading...", title="Storcli call in progress...")
120-
grid = await self.view.dock_grid(z=10)
121-
122-
grid.add_column(fraction=1, name="left")
123-
grid.add_column(min_size=30, max_size=50, name="center")
124-
grid.add_column(fraction=1, name="right")
125-
grid.add_row(fraction=10, name="top")
126-
grid.add_row(fraction=1, name="middle", max_size=5, min_size=3)
127-
grid.add_row(fraction=10, name="bottom")
128-
129-
grid.add_areas(
130-
area1="left,top",
131-
area2="center,middle",
132-
area3="left-start|right-end,bottom",
133-
area4="right,top-start|middle-end",
134-
)
135-
grid.place(area2=self.messageBox)
136-
137-
self.messageBox.visible = False
138-
139-
# Mount the Layout
140-
await self.view.dock(self.treeView, edge="left", size=32)
141-
await self.view.dock(self.mainView)
142-
await self.mainView.dock(self.getEmptyMainView())
143-
144-
async def handle_storcli_click(self, message: StorcliClick) -> None:
145-
"""Called in response to a tree click."""
146-
147-
data: StorcliEntry = message.entry
148-
149-
if data.type == SCEntryType.DriveType:
150-
# Show the drive view
151-
await self._set_main_view(DriveView(data.drive))
128+
# await self.view.dock(footer, edge="bottom")
129+
130+
# # Device Tree
131+
# self.tree = StorcliTree()
132+
# await self.tree.root.expand()
133+
# self.treeView = ScrollView(self.tree)
134+
135+
# # Message box
136+
# self.messageBox = MessageBox(
137+
# "Loading...", title="Storcli call in progress...")
138+
# grid = await self.view.dock_grid(z=10)
139+
140+
# grid.add_column(fraction=1, name="left")
141+
# grid.add_column(min_size=30, max_size=50, name="center")
142+
# grid.add_column(fraction=1, name="right")
143+
# grid.add_row(fraction=10, name="top")
144+
# grid.add_row(fraction=1, name="middle", max_size=5, min_size=3)
145+
# grid.add_row(fraction=10, name="bottom")
146+
147+
# grid.add_areas(
148+
# area1="left,top",
149+
# area2="center,middle",
150+
# area3="left-start|right-end,bottom",
151+
# area4="right,top-start|middle-end",
152+
# )
153+
# grid.place(area2=self.messageBox)
154+
155+
# self.messageBox.visible = False
156+
157+
# # Mount the Layout
158+
# await self.view.dock(self.treeView, edge="left", size=32)
159+
# await self.view.dock(self.mainView)
160+
# await self.mainView.dock(self.getEmptyMainView())
161+
162+
# async def handle_storcli_click(self, message: StorcliClick) -> None:
163+
# """Called in response to a tree click."""
164+
165+
# data: StorcliEntry = message.entry
166+
167+
# if data.type == SCEntryType.DriveType:
168+
# # Show the drive view
169+
# await self._set_main_view(DriveView(data.drive))
170+
171+
def on_storcli_exec_storcli_exec(self, message: StorcliExec) -> None:
172+
sdfsfdf
173+
174+
def on_storcli_exec(self, message: StorcliExec) -> None:
175+
sdfsfdf
152176

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

156181
self.messageBox.content = 'Running: ' + ' '.join(message.cmdArgs)
157-
self.messageBox.visible = not message.finished
182+
self.messageBox.visible = True # not message.finished
158183
# self.messageBox.refresh()

pystorclitui/pystorclitui.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Screen {
2+
background: $surface-darken-1;
3+
}
4+
5+
#tree-view {
6+
display: none;
7+
scrollbar-gutter: stable;
8+
overflow: auto;
9+
width: auto;
10+
height: 100%;
11+
dock: left;
12+
}
13+
14+
PyStorCLITUI.-show-tree #tree-view {
15+
display: block;
16+
max-width: 50%;
17+
}
18+
19+
20+
#code-view {
21+
overflow: auto scroll;
22+
min-width: 100%;
23+
}
24+
#code {
25+
width: auto;
26+
}

0 commit comments

Comments
 (0)