Skip to content

Commit 1c3baa8

Browse files
authored
Keep default drive for SelectDirectoryTreeScreen as home. (#557)
* Keep default drive for SelectDirectoryTreeScreen as home. * Fix tests under new conditions.
1 parent d7c490a commit 1c3baa8

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

datashuttle/tui/screens/modal_dialogs.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import TYPE_CHECKING, Callable, Optional
4+
from typing import TYPE_CHECKING, Callable
55

66
if TYPE_CHECKING:
77
from pathlib import Path
@@ -219,9 +219,7 @@ class SelectDirectoryTreeScreen(ModalScreen):
219219
220220
"""
221221

222-
def __init__(
223-
self, mainwindow: TuiApp, path_: Optional[Path] = None
224-
) -> None:
222+
def __init__(self, mainwindow: TuiApp) -> None:
225223
"""Initialise SelectDirectoryTreeScreen.
226224
227225
Parameters
@@ -236,12 +234,14 @@ def __init__(
236234
super(SelectDirectoryTreeScreen, self).__init__()
237235
self.mainwindow = mainwindow
238236

239-
if path_ is None:
240-
path_ = Path().home()
241-
self.path_ = path_
237+
self.path_ = Path().home()
242238

243239
self.click_info = ClickInfo()
244240

241+
# Flag as the Select triggers `on_select_change` during set up
242+
# which results setting tree back to default drive not home.
243+
self.skip_first_select_trigger = True
244+
245245
def compose(self) -> ComposeResult:
246246
"""Add widgets to the SelectDirectoryTreeScreen."""
247247
label_message = (
@@ -305,10 +305,13 @@ def get_selected_drive(self) -> str:
305305

306306
def on_select_changed(self, event: Select.Changed) -> None:
307307
"""Update the directory tree when the drive is changed."""
308-
self.path_ = Path(event.value)
309-
self.query_one(
310-
"#select_directory_tree_directory_tree"
311-
).path = self.path_
308+
if self.skip_first_select_trigger:
309+
self.skip_first_select_trigger = False
310+
else:
311+
self.path_ = Path(event.value)
312+
self.query_one(
313+
"#select_directory_tree_directory_tree"
314+
).path = self.path_
312315

313316
@require_double_click
314317
def on_directory_tree_directory_selected(

tests/tests_tui/test_tui_selectdirectorytree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import pytest
24

35
from datashuttle.tui.app import TuiApp
@@ -47,9 +49,7 @@ async def test_select_directory_tree(self, monkeypatch):
4749
"#select_directory_tree_drive_select"
4850
)
4951

50-
select.value = "Drive1"
51-
await pilot.pause()
52-
assert str(tree.path) == "Drive1"
52+
assert tree.path == Path().home()
5353

5454
select.value = "Drive2"
5555
await pilot.pause()

0 commit comments

Comments
 (0)