Skip to content

[ENH] Added dropdown to select drives and to select files from the tree view while selecting location of new project #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion datashuttle/tui/screens/modal_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@
from datashuttle.tui.app import TuiApp
from datashuttle.utils.custom_types import InterfaceOutput

import platform
from pathlib import Path

import psutil
from textual.containers import Container, Horizontal
from textual.screen import ModalScreen
from textual.widgets import Button, Input, Label, LoadingIndicator, Static
from textual.widgets import (
Button,
Input,
Label,
LoadingIndicator,
Select,
Static,
)

from datashuttle.tui.custom_widgets import CustomDirectoryTree
from datashuttle.tui.utils.tui_decorators import require_double_click
Expand Down Expand Up @@ -165,6 +174,10 @@ def __init__(
path_ = Path().home()
self.path_ = path_

if platform.system() == "Windows":
self.selected_drive = self.path_.drive + "\\"
else:
self.selected_drive = "/"
self.prev_click_time = 0

def compose(self) -> ComposeResult:
Expand All @@ -176,6 +189,12 @@ def compose(self) -> ComposeResult:

yield Container(
Static(label_message, id="select_directory_tree_screen_label"),
Select( # Dropdown for drives
[(drive, drive) for drive in self.get_drives()],
value=self.selected_drive,
allow_blank=False,
id="select_directory_tree_drive_select",
),
CustomDirectoryTree(
self.mainwindow,
self.path_,
Expand All @@ -185,6 +204,24 @@ def compose(self) -> ComposeResult:
id="select_directory_tree_container",
)

@staticmethod
def get_drives():
if platform.system() == "Windows":
return [disk.device for disk in psutil.disk_partitions(all=False)]

elif platform.system() in ["Darwin", "Linux"]:
return ["/"] + [
f"/{dir.name}" for dir in Path("/").iterdir() if dir.is_dir()
]
return ["/"]

def on_select_changed(self, event: Select.Changed) -> None:
"""Updates the directory tree when the drive is changed."""
self.path_ = Path(event.value)
self.query_one("#select_directory_tree_directory_tree").path = (
self.path_
)

@require_double_click
def on_directory_tree_directory_selected(self, node) -> None:
if node.path.is_file():
Expand Down
Loading