|
94 | 94 | WeatherType, |
95 | 95 | ) |
96 | 96 | from OTAnalytics.application.project_location import UnsupportedProjectLocation |
| 97 | +from OTAnalytics.application.state import CurrentOrthophoto |
97 | 98 | from OTAnalytics.application.use_cases.config import ConfigValidationError |
98 | 99 | from OTAnalytics.application.use_cases.config_has_changed import NoExistingConfigFound |
99 | 100 | from OTAnalytics.application.use_cases.cut_tracks_with_sections import CutTracksDto |
|
137 | 138 | from OTAnalytics.domain.files import DifferentDrivesException |
138 | 139 | from OTAnalytics.domain.filter import FilterElement |
139 | 140 | from OTAnalytics.domain.flow import Flow, FlowId, FlowListObserver |
| 141 | +from OTAnalytics.domain.orthophoto import Orthophoto, OrthophotoError |
140 | 142 | from OTAnalytics.domain.section import ( |
141 | 143 | COORDINATES, |
142 | 144 | ID, |
|
148 | 150 | SectionRepositoryEvent, |
149 | 151 | ) |
150 | 152 | from OTAnalytics.domain.track import TrackImage |
| 153 | +from OTAnalytics.domain.track_dataset.track_dataset import ( |
| 154 | + IncompatibleGeoreferenceMetadataError, |
| 155 | +) |
151 | 156 | from OTAnalytics.domain.track_repository import TrackListObserver, TrackRepositoryEvent |
152 | 157 | from OTAnalytics.domain.types import EventType |
153 | 158 | from OTAnalytics.domain.video import Video, VideoListObserver |
@@ -340,8 +345,10 @@ def __init__( |
340 | 345 | update_section_coordinates: UpdateSectionCoordinates, |
341 | 346 | provide_track_files: ProvideTrackFiles, |
342 | 347 | provide_video_files: ProvideVideoFiles, |
| 348 | + current_orthophoto: CurrentOrthophoto, |
343 | 349 | ) -> None: |
344 | 350 | self._application = application |
| 351 | + self._current_orthophoto = current_orthophoto |
345 | 352 | self._ui_factory = ui_factory |
346 | 353 | self._provide_track_files = provide_track_files |
347 | 354 | self._provide_video_files = provide_video_files |
@@ -382,6 +389,10 @@ def notify_videos(self, videos: list[Video]) -> None: |
382 | 389 | self.treeview_videos.update_items() |
383 | 390 | self._update_enabled_buttons() |
384 | 391 |
|
| 392 | + def notify_orthophoto(self, _: Orthophoto | None) -> None: |
| 393 | + """Re-enable the buttons that wait for a background to draw on.""" |
| 394 | + self._update_enabled_buttons() |
| 395 | + |
385 | 396 | def notify_files(self) -> None: |
386 | 397 | self.treeview_files.update_items() |
387 | 398 | self._update_enabled_buttons() |
@@ -432,12 +443,11 @@ def _update_enabled_video_buttons(self) -> None: |
432 | 443 |
|
433 | 444 | def _update_enabled_section_buttons(self) -> None: |
434 | 445 | action_running = self._application.action_state.action_running.get() |
435 | | - videos_exist = len(self._application.get_all_videos()) > 0 |
436 | 446 | selected_section_ids = self.get_selected_section_ids() |
437 | 447 | single_section_selected = len(selected_section_ids) == 1 |
438 | 448 | any_section_selected = len(selected_section_ids) > 0 |
439 | 449 |
|
440 | | - add_section_enabled = (not action_running) and videos_exist |
| 450 | + add_section_enabled = (not action_running) and self._background_exists() |
441 | 451 | single_section_enabled = add_section_enabled and single_section_selected |
442 | 452 | multiple_sections_enabled = add_section_enabled and any_section_selected |
443 | 453 |
|
@@ -469,10 +479,14 @@ def _update_enabled_flow_buttons(self) -> None: |
469 | 479 |
|
470 | 480 | def _update_enabled_video_control_buttons(self) -> None: |
471 | 481 | action_running = self._application.action_state.action_running.get() |
472 | | - videos_exist = len(self._application.get_all_videos()) > 0 |
473 | | - general_activated = not action_running and videos_exist |
| 482 | + general_activated = not action_running and self._background_exists() |
474 | 483 | self.frame_video_control.set_enabled_general_buttons(general_activated) |
475 | 484 |
|
| 485 | + def _background_exists(self) -> bool: |
| 486 | + """Whether a Video or an Orthophoto is there to draw Sections on.""" |
| 487 | + videos_exist = len(self._application.get_all_videos()) > 0 |
| 488 | + return videos_exist or self._current_orthophoto.get() is not None |
| 489 | + |
476 | 490 | def _on_section_changed(self, section: SectionId) -> None: |
477 | 491 | self._refresh_sections_in_ui() |
478 | 492 |
|
@@ -586,7 +600,13 @@ async def add_video(self) -> None: |
586 | 600 | if not video_files: |
587 | 601 | return |
588 | 602 | logger().info(f"Video files to load: {video_files}") |
589 | | - self._application.add_videos(files=video_files) |
| 603 | + try: |
| 604 | + self._application.add_videos(files=video_files) |
| 605 | + except OrthophotoError as cause: |
| 606 | + logger().warning(str(cause)) |
| 607 | + self._ui_factory.info_box( |
| 608 | + message=str(cause), initial_position=self._get_window_position() |
| 609 | + ) |
590 | 610 |
|
591 | 611 | def remove_videos(self) -> None: |
592 | 612 | self._application.remove_videos() |
@@ -900,7 +920,13 @@ async def load_tracks(self) -> None: |
900 | 920 | if not track_files: |
901 | 921 | return |
902 | 922 | logger().info(f"Tracks files to load: {track_files}") |
903 | | - await self._application.add_tracks_of_files_async(track_files=track_files) |
| 923 | + try: |
| 924 | + await self._application.add_tracks_of_files_async(track_files=track_files) |
| 925 | + except (OrthophotoError, IncompatibleGeoreferenceMetadataError) as cause: |
| 926 | + logger().warning(str(cause)) |
| 927 | + self._ui_factory.info_box( |
| 928 | + message=str(cause), initial_position=self._get_window_position() |
| 929 | + ) |
904 | 930 |
|
905 | 931 | async def load_configuration(self) -> None: # sourcery skip: avoid-builtin-shadow |
906 | 932 | # INFO: Current behavior: Overwrites existing sections |
|
0 commit comments