Skip to content

Commit

Permalink
Allow selection of folders for extract paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallHarterAtWork committed Nov 19, 2024
1 parent 6feac14 commit 63fd597
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
40 changes: 31 additions & 9 deletions surfactant/cmd/config_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,49 @@ def handle_no(self) -> None:
self.dismiss(False)


class SelectFileButtons(textual.widgets.Static):
def __init__(self, allow_folder_selection: bool):
super().__init__()
self.allow_folder_selection = allow_folder_selection

def compose(self) -> textual.app.ComposeResult:
yield textual.widgets.Button("Go up a directory", id="up_dir")
if self.allow_folder_selection:
yield textual.widgets.Button("Select directory", id="select_dir")

class SelectFile(textual.screen.ModalScreen[Optional[textual.widgets.DirectoryTree.FileSelected]]):
"""Pop-up to select a file"""
def __init__(self, allow_folder_selection: bool):
super().__init__()
self.allow_folder_selection = allow_folder_selection
self.dir_selected = './'

def compose(self) -> textual.app.ComposeResult:
yield textual.widgets.DirectoryTree("./", id="file_dir")
yield textual.widgets.Button("Go up a directory", id="up_dir")
yield SelectFileButtons(self.allow_folder_selection)

@textual.on(textual.widgets.Button.Pressed, "#up_dir")
def handle_up_dir(self):
tree = self.get_child_by_id("file_dir", textual.widgets.DirectoryTree)
tree.path = tree.path.parent.resolve()
tree.reload()

@textual.on(textual.widgets.Button.Pressed, "#select_dir")
def handle_select_dir(self):
self.dismiss(self.dir_selected)

def on_directory_tree_directory_selected(
self, path: textual.widgets.DirectoryTree.DirectorySelected
) -> None:
self.dir_selected = path.path.as_posix()

def on_directory_tree_file_selected(
self, path: textual.widgets.DirectoryTree.FileSelected
) -> None:
self.dismiss(path)
self.dir_selected = path.path.as_posix()

def on_key(self, event: textual.events.Key):
if event.key == "escape":
if event.key == "escape" :
self.dismiss(None)


Expand All @@ -77,10 +100,10 @@ def compose(self) -> textual.app.ComposeResult:
def on_select_path(self):
def set_path(path: Optional[textual.widgets.DirectoryTree.FileSelected]):
if path:
self.path = path.path.as_posix()
self.path = path
self.get_child_by_id("path", textual.widgets.Label).update(f"Path: {self.path}")

self.app.push_screen(SelectFile(), set_path)
self.app.push_screen(SelectFile(True), set_path)

@textual.on(textual.widgets.Button.Pressed, "#delete_path")
def on_delete_path(self):
Expand Down Expand Up @@ -125,13 +148,12 @@ def compose(self) -> textual.app.ComposeResult:
def on_archive_button(self):
def set_archive(path: Optional[textual.widgets.DirectoryTree.FileSelected]):
if path:
loc = path.path.as_posix()
self.archive_loc = loc
self.archive_loc = path
self.get_child_by_id("archive_label", textual.widgets.Label).update(
f"Archive: {loc}"
f"Archive: {path}"
)

self.app.push_screen(SelectFile(), set_archive)
self.app.push_screen(SelectFile(False), set_archive)


class InstallPrefix(textual.widgets.Static):
Expand Down
4 changes: 4 additions & 0 deletions surfactant/web-files/config_tui.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ InstallPrefix {
.selected {
background: red;
}

SelectFileButtons {
layout: horizontal;
}

0 comments on commit 63fd597

Please sign in to comment.