From d6df5e40872f6a25bbd9290168d0b8def302df1f Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Tue, 2 Apr 2024 18:06:58 -0400 Subject: [PATCH] Always four videos, drag over replaces --- gridplayer/player/managers/drag_n_drop.py | 12 ++++++++++-- gridplayer/player/managers/grid.py | 4 ++-- gridplayer/player/player.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gridplayer/player/managers/drag_n_drop.py b/gridplayer/player/managers/drag_n_drop.py index aa8f4e2..0096cf1 100644 --- a/gridplayer/player/managers/drag_n_drop.py +++ b/gridplayer/player/managers/drag_n_drop.py @@ -17,6 +17,7 @@ class DragNDropManager(ManagerBase): playlist_dropped = pyqtSignal(Path) videos_dropped = pyqtSignal(list) + close_this = pyqtSignal(str) videos_swapped = pyqtSignal() @@ -84,6 +85,12 @@ def _drop_files(self, event, drop_files): videos = filter_video_uris(drop_files) self.videos_dropped.emit(videos) + if len(self._ctx.video_blocks) >= 4: + if (self._ctx.active_block): + self._swap_videos(self._ctx.active_block, self._ctx.video_blocks[-1], False) + self._ctx.active_block.close(True) + self.videos_swapped.emit() + event.acceptProposedAction() return True @@ -141,7 +148,7 @@ def _get_drag_video(self): return drag - def _swap_videos(self, src, dst): + def _swap_videos(self, src, dst, emit=True): self._log.debug(f"Swapping {src.id} with {dst.id}") if src == dst: @@ -150,4 +157,5 @@ def _swap_videos(self, src, dst): self._ctx.video_blocks.swap(dst, src) - self.videos_swapped.emit() + if emit: + self.videos_swapped.emit() diff --git a/gridplayer/player/managers/grid.py b/gridplayer/player/managers/grid.py index 0ac15d7..4b636b1 100644 --- a/gridplayer/player/managers/grid.py +++ b/gridplayer/player/managers/grid.py @@ -97,7 +97,7 @@ def visible_count(self): @property def grid_dimensions(self): if self.visible_count <= 1: - return GridDimensions(1, 1) + return GridDimensions(2, 2) if self._grid_size == 0: grid_size = math.ceil(math.sqrt(self.visible_count)) @@ -111,7 +111,7 @@ def grid_dimensions(self): else: cols, rows = grid_size, grid_slices - return GridDimensions(cols, rows) + return GridDimensions(2, 2) @contextlib.contextmanager def slow_ui_operation(self): diff --git a/gridplayer/player/player.py b/gridplayer/player/player.py index 0eb7817..3a2cf55 100644 --- a/gridplayer/player/player.py +++ b/gridplayer/player/player.py @@ -76,6 +76,7 @@ def __init__(self, **kwargs): ("video_blocks.video_count_changed", "update_active_under_mouse") ], "drag_n_drop": [ + ("close_this", "video_blocks.close_single"), ("videos_swapped", "grid.reload_video_grid"), ("videos_dropped", "video_blocks.add_videos"), ("videos_dropped", "window_state.activate_window"),