Skip to content

Commit

Permalink
change css, format/validation tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hausman-gdit committed Feb 7, 2024
1 parent 697ea6e commit 97405a9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 102 deletions.
73 changes: 40 additions & 33 deletions bmds_server/desktop/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class QuitModal(ModalScreen):

def compose(self) -> ComposeResult:
yield Grid(
Label("Are you sure you want to quit?", id="modal-quit-question"),
Label("Are you sure you want to quit?", classes="modal-label"),
Button("Quit", variant="error", id="btn-modal-quit"),
Button("Cancel", variant="primary", id="btn-modal-cancel"),
id="quit-modal",
classes="modal-grid",
)

def on_button_pressed(self, event: Button.Pressed) -> None:
Expand All @@ -110,10 +110,18 @@ def get_update(self):

def compose(self) -> ComposeResult:
yield Grid(
Label(f"Check for Updates: {version('bmds_server')}", id="modal-update-lbl"),
# Button("Get Updates", variant="primary", id="btn-update-download"),
Label(
f"Check for Updates: {version('bmds_server')}",
classes="modal-label",
),
Button(
"Get Updates",
variant="primary",
id="btn-update-download",
disabled=True,
),
Button("Cancel", variant="primary", id="btn-update-cancel"),
id="update-modal",
classes="modal-grid",
)

def on_button_pressed(self, event: Button.Pressed) -> None:
Expand Down Expand Up @@ -270,24 +278,21 @@ def btn_path_parent(self):

@on(Button.Pressed, "#btn-save-dir")
def btn_update_config(self, event: Button.Pressed) -> None:
_selected = self.query_one("#disp-selected").renderable.__str__()
if Path(_selected).is_dir():
selected = self.query_one("#disp-selected").renderable.__str__()
if Path(selected).is_dir():
# Select a different folder for projects/db's
self.change_config(self.query_one("#disp-selected").renderable, kind="dir")
if Path(_selected).is_file():
self.change_config(selected, kind="dir")
if Path(selected).is_file():
# Select different project/db
self.change_config(
PurePath(self.query_one("#disp-selected").renderable.__str__()).name,
kind="file",
)
self.change_config(PurePath(selected).name, kind="file")

def compose(self) -> ComposeResult:
yield Button("<<", id="btn-path-parent")
yield Label("Selected Folder:")
yield Static(str(get_data_folder()), id="disp-selected", classes="disp-selected")
yield ConfigTree(id="config-tree", path=Path(get_data_folder()), classes="config-tree")
with Horizontal(classes="save-btns"):
yield Button("Select Directory / DB", id="btn-save-dir", classes="save")
with Horizontal(classes="center-top"):
yield Button("Select Directory / DB", id="btn-save-dir", classes="btn-auto save")

def on_directory_tree_directory_selected(self, DirectorySelected):
self.query_one("#disp-selected").update(rf"{DirectorySelected.path!s}")
Expand Down Expand Up @@ -325,8 +330,6 @@ def change_config(self, value, kind):
class FileNameContainer(Container):
"""Filename"""

# TODO: fix input validation/clear it after save?

# TODO: check if file exists before creating new one

@on(Button.Pressed, "#btn-save-fn")
Expand Down Expand Up @@ -367,22 +370,27 @@ def compose(self) -> ComposeResult:
),
],
)
with Horizontal(classes="save-btns"):
with Horizontal(classes="center-top"):
yield Button("save", id="btn-save-fn", classes="btn-auto save", disabled=True)

def create_project(self):
db_name = self.query_one(Input).value + ".sqlite3"
input = self.query_one("#input-filename")
db_name = input.value + ".sqlite3"
cf = Path(get_data_folder()) / db_name
config = load_config()
config["desktop"]["file_name"] = str(db_name)
cf = Path(get_data_folder()) / db_name

try:
cf.touch()
with open(Path(APP_ROOT / "config.ini"), "w") as configfile:
config.write(configfile)
cf.touch()
self.query_one("#disp-fn").update(get_project_filename())
self.query_one("#input-filename").clear()
self.query_one("#disp-fn-validation").update("")
# Stop on input changed validation
with input.prevent(Input.Changed):
input.clear()
input.set_class(False, "-valid")
input.set_class(False, "-invalid")
self.query_one("#btn-save-fn").disabled = True
self.notify(
f"{db_name} : project created.",
title="Project Created",
Expand All @@ -399,21 +407,21 @@ def create_project(self):
class ConfigTab(Static):
"""Configuration Tab"""

@on(Button.Pressed, "#dir-container,#fn-container")
@on(Button.Pressed, "#btn-dir-container,#btn-fn-container")
def btn_container_switch(self, event: Button.Pressed) -> None:
# Content Switch
self.query_one(ContentSwitcher).current = event.button.id
self.query_one(DirectoryContainer).reload()

def compose(self) -> ComposeResult:
with Horizontal(classes="config-tab"):
with Vertical(classes="config-btns"):
with Horizontal():
with Vertical(classes="config-switch"):
yield Button(
"Change Directory / Project",
id="dir-container",
"Directory / Project",
id="btn-dir-container",
classes="btn-auto",
)
yield Button("Create New Project", id="fn-container", classes="btn-auto")
yield Button("Create New Project", id="btn-fn-container", classes="btn-auto")
yield Rule(orientation="vertical")

with ContentSwitcher(initial="dir-container"):
Expand All @@ -439,8 +447,7 @@ def compose(self) -> ComposeResult:
Label("", id="project"),
Label(f"[b]Port:[/b]\n {self._app.config.port}", id="port"),
Label(f"[b]Host:[/b]\n {self._app.config.host}", id="host"),
classes="app-box",
id="app-box",
classes="app-info-box",
)

with TabPane("Logging"):
Expand Down Expand Up @@ -495,15 +502,15 @@ def action_key_start(self):

def action_quit(self):
"""Exit the application."""
self.push_screen(QuitModal())
self.push_screen(QuitModal(classes="modal-window"))

def action_toggle_dark(self):
"""An action to toggle dark mode."""
self.dark = not self.dark

def action_update_check(self):
"""Check for updates"""
self.push_screen(UpdateModal())
self.push_screen(UpdateModal(classes="modal-window"))

def on_mount(self) -> None:
self.log_app.start()
Expand Down
86 changes: 18 additions & 68 deletions bmds_server/desktop/content/app.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ Button.btn-auto {
height: auto;
}

Button.btn-config{
width:5;
height:3;
margin:-1 -1 -1 -1;
padding:0;
Button.btn-config {
width: 5;
height: 3;
margin: -1 -1 -1 -1;
padding: 0;
border: none;
}

.center-top {
align: center top;
}

.save {
background: $primary 50%;
}
Expand All @@ -31,30 +35,23 @@ Button.btn-config{
background: $secondary 50%;
}

.config-btns {
.config-switch {
align: center top;
width: auto;
}


.save-btns {
align: center top;
}

#log {
height: 15;
}

#tabs {
margin: 0 5;
background: $boost;
height: 30;

}

.app {
layout: horizontal;
}

.app-box {
.app-info-box {
padding: 0 1;
margin: 1;
border: double grey;
Expand All @@ -63,26 +60,7 @@ Button.btn-config{
overflow: auto;
}

.config-tab {
/* */
height: 40;
}

.dir-container {
margin: 1;
/* border: double grey;
width: 70;
height: 30; */
overflow: auto;
background: $panel;
}

.fn-container {
margin: 1;
/* border: double grey; */
/* width: 70; */
/* height: 30; */
overflow: auto;
.dir-container, .fn-container {
background: $panel;
}

Expand All @@ -91,9 +69,7 @@ Button.btn-config{
height: 4fr;
}



.selected-disp {
.disp-selected {
border: ascii gray;
background: $boost;
}
Expand All @@ -106,37 +82,11 @@ Input.-valid:focus {
border: ascii $success;
}

QuitModal {
align: center middle;
}

#quit-modal {
grid-size: 2;
grid-gutter: 1 2;
grid-rows: 1fr 3;
padding: 0 1;
width: 37;
height: 11;
border: thick $background 80%;
background: $surface;
}

#modal-quit-question {
column-span: 2;
height: 1fr;
width: 1fr;
content-align: center middle;
}

.input-filename {
width: 1fr;
}

UpdateModal {
.modal-window{
align: center middle;
}

#update-modal {
.modal-grid {
grid-size: 2;
grid-gutter: 1 2;
grid-rows: 1fr 3;
Expand All @@ -147,7 +97,7 @@ UpdateModal {
background: $surface;
}

#modal-update-lbl {
.modal-label {
column-span: 2;
height: 1fr;
width: 1fr;
Expand Down
2 changes: 1 addition & 1 deletion tests/desktop/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ async def test_tab_navigation_keyboard():
btn_fn = app.query_one("#btn-fn-container")
assert btn_fn.label.__str__() == "Create New Project"
btn_dir = app.query_one("#btn-dir-container")
assert btn_dir.label.__str__() == "Change Directory / Project"
assert btn_dir.label.__str__() == "Directory / Project"

0 comments on commit 97405a9

Please sign in to comment.