Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions datashuttle/tui/screens/modal_dialogs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING, Callable, Optional
from typing import TYPE_CHECKING, Callable

if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -219,9 +219,7 @@ class SelectDirectoryTreeScreen(ModalScreen):

"""

def __init__(
self, mainwindow: TuiApp, path_: Optional[Path] = None
) -> None:
def __init__(self, mainwindow: TuiApp) -> None:
"""Initialise SelectDirectoryTreeScreen.

Parameters
Expand All @@ -236,12 +234,14 @@ def __init__(
super(SelectDirectoryTreeScreen, self).__init__()
self.mainwindow = mainwindow

if path_ is None:
path_ = Path().home()
self.path_ = path_
self.path_ = Path().home()

self.click_info = ClickInfo()

# Flag as the Select triggers `on_select_change` during set up
# which results setting tree back to default drive not home.
self.skip_first_select_trigger = True

def compose(self) -> ComposeResult:
"""Add widgets to the SelectDirectoryTreeScreen."""
label_message = (
Expand Down Expand Up @@ -305,10 +305,13 @@ def get_selected_drive(self) -> str:

def on_select_changed(self, event: Select.Changed) -> None:
"""Update the directory tree when the drive is changed."""
self.path_ = Path(event.value)
self.query_one(
"#select_directory_tree_directory_tree"
).path = self.path_
if self.skip_first_select_trigger:
self.skip_first_select_trigger = False
else:
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(
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_tui/test_tui_selectdirectorytree.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest

from datashuttle.tui.app import TuiApp
Expand Down Expand Up @@ -47,9 +49,7 @@ async def test_select_directory_tree(self, monkeypatch):
"#select_directory_tree_drive_select"
)

select.value = "Drive1"
await pilot.pause()
assert str(tree.path) == "Drive1"
assert tree.path == Path().home()

select.value = "Drive2"
await pilot.pause()
Expand Down
Loading