|
1 | 1 | import asyncio |
2 | 2 | from datetime import datetime |
3 | 3 | from pathlib import Path |
4 | | -from typing import Any, Iterable, Literal |
| 4 | +from typing import Any, Iterable |
5 | 5 |
|
6 | 6 | from OTAnalytics.adapter_ui.file_export_dto import ExportFileDto |
7 | 7 | from OTAnalytics.adapter_ui.flow_dto import FlowDto |
|
17 | 17 | from OTAnalytics.application.resources.resource_manager import ResourceManager |
18 | 18 | from OTAnalytics.application.use_cases.generate_flows import FlowNameGenerator |
19 | 19 | from OTAnalytics.domain.geometry import RelativeOffsetCoordinate |
| 20 | +from OTAnalytics.helpers.file_helpers import ( |
| 21 | + get_all_files_with_correct_file_ending_in_directory, |
| 22 | +) |
20 | 23 | from OTAnalytics.plugin_ui.nicegui_gui.dialogs.edit_flow_dialog import EditFlowDialog |
21 | 24 | from OTAnalytics.plugin_ui.nicegui_gui.dialogs.edit_section_dialog import ( |
22 | 25 | EditSectionDialog, |
|
27 | 30 | from OTAnalytics.plugin_ui.nicegui_gui.dialogs.file_chooser_dialog import ( |
28 | 31 | FileChooserDialog, |
29 | 32 | ) |
| 33 | +from OTAnalytics.plugin_ui.nicegui_gui.dialogs.file_picker import LocalFilePicker |
30 | 34 | from OTAnalytics.plugin_ui.nicegui_gui.nicegui.elements.dialog import DialogResult |
31 | 35 |
|
32 | 36 |
|
@@ -88,24 +92,29 @@ async def askopenfilenames( |
88 | 92 | title: str, |
89 | 93 | filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]], |
90 | 94 | extension_options: dict[str, list[str] | None] | None = None, |
91 | | - ) -> Literal[""] | tuple[str, ...]: |
| 95 | + ) -> list[Path]: |
92 | 96 | # For now, we'll just support selecting a single file |
93 | 97 | # In a real implementation, this would allow selecting multiple files |
94 | 98 | # Convert list/tuple of extensions to individual (desc, ext) pairs |
95 | 99 | converted_filetypes = [] |
96 | 100 | for desc, ext in filetypes: |
97 | 101 | if isinstance(ext, str): |
98 | | - converted_filetypes.append((desc, ext)) |
| 102 | + converted_filetypes.append(ext) |
99 | 103 | elif isinstance(ext, (list, tuple)) and ext: |
100 | 104 | # Use the first extension from the list/tuple |
101 | | - converted_filetypes.append((desc, ext[0])) |
| 105 | + converted_filetypes.append(ext[0]) |
102 | 106 |
|
103 | | - file_path = await self.askopenfilename( |
104 | | - title, converted_filetypes, "", extension_options |
| 107 | + file_paths = await LocalFilePicker( |
| 108 | + directory=Path.home(), |
| 109 | + show_hidden_files=False, |
| 110 | + show_files_only_of_type=None, # Show all files |
| 111 | + show_only_directories=False, |
| 112 | + extension_options=extension_options, |
| 113 | + multiple=True, |
| 114 | + ) |
| 115 | + return get_all_files_with_correct_file_ending_in_directory( |
| 116 | + file_paths, converted_filetypes |
105 | 117 | ) |
106 | | - if file_path: |
107 | | - return (file_path,) |
108 | | - return "" |
109 | 118 |
|
110 | 119 | async def ask_for_save_file_path( |
111 | 120 | self, |
|
0 commit comments