From 3ea89b5fb1bd1560d4a4db600a686bed2f99212b Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Wed, 22 Jun 2022 16:24:42 +0500 Subject: [PATCH] fix: hide bulk commands if no video can execute them --- gridplayer/player/managers/actions.py | 28 ++++++++++++++++++++++ gridplayer/player/managers/active_block.py | 4 ++-- gridplayer/player/managers/video_blocks.py | 16 +++++++++++++ gridplayer/widgets/video_block.py | 2 +- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/gridplayer/player/managers/actions.py b/gridplayer/player/managers/actions.py index ed57115..62f2572 100644 --- a/gridplayer/player/managers/actions.py +++ b/gridplayer/player/managers/actions.py @@ -311,165 +311,193 @@ "key": "Space", "icon": "play", "func": "all_play_pause", + "show_if": "is_any_videos_initialized", }, "Play Previous File [ALL]": { "title": translate("Actions", "Play Previous File"), "key": Qt.SHIFT + Qt.Key_PageUp, "icon": "previous-video-file", "func": ("all", "previous_video"), + "show_if": "is_any_videos_local_file", }, "Play Next File [ALL]": { "title": translate("Actions", "Play Next File"), "key": Qt.SHIFT + Qt.Key_PageDown, "icon": "next-video-file", "func": ("all", "next_video"), + "show_if": "is_any_videos_local_file", }, "Timecode [ALL]": { "title": translate("Actions", "Timecode"), "key": "Shift+T", "icon": "seek-sync-time", "func": "all_seek_timecode", + "show_if": "is_any_videos_seekable", }, "Random [ALL]": { "title": translate("Actions", "Random"), "key": "Shift+R", "icon": "loop-random", "func": ("all", "seek_random"), + "show_if": "is_any_videos_seekable", }, "Next frame [ALL]": { "title": translate("Actions", "Next frame"), "key": "Shift+S", "icon": "next-frame", "func": ("all", "next_frame"), + "show_if": "is_any_videos_seekable", }, "Previous frame [ALL]": { "title": translate("Actions", "Previous frame"), "key": "Shift+D", "icon": "previous-frame", "func": ("all", "previous_frame"), + "show_if": "is_any_videos_seekable", }, "+1% [ALL]": { "title": "+1%", "key": "Shift+Right", "icon": "seek-plus-1", "func": ("all", "seek_shift_percent", 1), + "show_if": "is_any_videos_seekable", }, "+5% [ALL]": { "title": "+5%", "key": "Shift+]", "icon": "seek-plus-5", "func": ("all", "seek_shift_percent", 5), + "show_if": "is_any_videos_seekable", }, "+10% [ALL]": { "title": "+10%", "key": "Shift+'", "icon": "seek-plus-10", "func": ("all", "seek_shift_percent", 10), + "show_if": "is_any_videos_seekable", }, "-1% [ALL]": { "title": "-1%", "key": "Shift+Left", "icon": "seek-minus-1", "func": ("all", "seek_shift_percent", -1), + "show_if": "is_any_videos_seekable", }, "-5% [ALL]": { "title": "-5%", "key": "Shift+[", "icon": "seek-minus-5", "func": ("all", "seek_shift_percent", -5), + "show_if": "is_any_videos_seekable", }, "-10% [ALL]": { "title": "-10%", "key": "Shift+;", "icon": "seek-minus-10", "func": ("all", "seek_shift_percent", -10), + "show_if": "is_any_videos_seekable", }, "+5s [ALL]": { "title": translate("Actions", "+5s"), "key": "Ctrl+Shift+Right", "icon": "seek-plus-1", "func": ("all", "seek_shift_ms", 5000), + "show_if": "is_any_videos_seekable", }, "+15s [ALL]": { "title": translate("Actions", "+15s"), "key": "Ctrl+Shift+]", "icon": "seek-plus-5", "func": ("all", "seek_shift_ms", 15000), + "show_if": "is_any_videos_seekable", }, "+30s [ALL]": { "title": translate("Actions", "+30s"), "key": "Ctrl+Shift+'", "icon": "seek-plus-10", "func": ("all", "seek_shift_ms", 30000), + "show_if": "is_any_videos_seekable", }, "-5s [ALL]": { "title": translate("Actions", "-5s"), "key": "Ctrl+Shift+Left", "icon": "seek-minus-1", "func": ("all", "seek_shift_ms", -5000), + "show_if": "is_any_videos_seekable", }, "-15s [ALL]": { "title": translate("Actions", "-15s"), "key": "Ctrl+Shift+[", "icon": "seek-minus-5", "func": ("all", "seek_shift_ms", -15000), + "show_if": "is_any_videos_seekable", }, "-30s [ALL]": { "title": translate("Actions", "-30s"), "key": "Ctrl+Shift+;", "icon": "seek-minus-10", "func": ("all", "seek_shift_ms", -30000), + "show_if": "is_any_videos_seekable", }, "Faster [ALL]": { "title": translate("Actions", "Faster"), "key": "Shift+C", "icon": "speed-faster", "func": ("all", "rate_increase"), + "show_if": "is_any_videos_seekable", }, "Slower [ALL]": { "title": translate("Actions", "Slower"), "key": "Shift+X", "icon": "speed-slower", "func": ("all", "rate_decrease"), + "show_if": "is_any_videos_seekable", }, "Normal [ALL]": { "title": translate("Actions", "Normal"), "key": "Shift+Z", "icon": "speed-reset", "func": ("all", "rate_reset"), + "show_if": "is_any_videos_seekable", }, "Zoom In [ALL]": { "title": translate("Actions", "Zoom In"), "key": "Shift++", "icon": "zoom-in", "func": ("all", "scale_increase"), + "show_if": "is_any_videos_initialized", }, "Zoom Out [ALL]": { "title": translate("Actions", "Zoom Out"), "key": "Shift+-", "icon": "zoom-out", "func": ("all", "scale_decrease"), + "show_if": "is_any_videos_initialized", }, "Zoom Reset [ALL]": { "title": translate("Actions", "Zoom Reset"), "key": "Shift+*", "icon": "zoom-reset", "func": ("all", "scale_reset"), + "show_if": "is_any_videos_initialized", }, "Aspect Fit [ALL]": { "title": translate("Actions", "Aspect Fit"), "icon": "aspect-fit", "func": ("all", "set_aspect", VideoAspect.FIT), + "show_if": "is_any_videos_initialized", }, "Aspect Stretch [ALL]": { "title": translate("Actions", "Aspect Stretch"), "icon": "aspect-stretch", "func": ("all", "set_aspect", VideoAspect.STRETCH), + "show_if": "is_any_videos_initialized", }, "Aspect None [ALL]": { "title": translate("Actions", "Aspect None"), "icon": "aspect-none", "func": ("all", "set_aspect", VideoAspect.NONE), + "show_if": "is_any_videos_initialized", }, "Reload [ALL]": { "title": translate("Actions", "Reload"), diff --git a/gridplayer/player/managers/active_block.py b/gridplayer/player/managers/active_block.py index e2d57fc..3dd0346 100644 --- a/gridplayer/player/managers/active_block.py +++ b/gridplayer/player/managers/active_block.py @@ -85,13 +85,13 @@ def is_active_seekable(self): if not self.is_active_initialized(): return False - return not self._ctx.active_block.video_driver.is_live + return not self._ctx.active_block.is_live def is_active_live(self): if not self.is_active_initialized(): return False - return self._ctx.active_block.video_driver.is_live + return self._ctx.active_block.is_live def is_active_local_file(self): if not self.is_active_initialized(): diff --git a/gridplayer/player/managers/video_blocks.py b/gridplayer/player/managers/video_blocks.py index 0170f70..a5ba495 100644 --- a/gridplayer/player/managers/video_blocks.py +++ b/gridplayer/player/managers/video_blocks.py @@ -40,6 +40,10 @@ def index(self, block): def unpaused(self): return [v for v in self._blocks if not v.video_params.is_paused] + @property + def initialized(self): + return [v for v in self._blocks if v.is_video_initialized] + @property def videos(self) -> List[Video]: return [v.video_params for v in self._blocks] @@ -106,6 +110,9 @@ def commands(self): "all_play_pause": self.cmd_all_play_pause, "all_seek_timecode": self.cmd_seek_timecode, "is_videos": lambda: bool(self._ctx.video_blocks), + "is_any_videos_initialized": self.is_any_videos_initialized, + "is_any_videos_seekable": self.is_any_videos_seekable, + "is_any_videos_local_file": self.is_any_videos_local_file, "is_seek_sync_mode_set_to": self.is_seek_sync_mode_set_to, "set_seek_sync_mode": self.set_seek_sync_mode, "reload_all": self.reload_videos, @@ -146,6 +153,15 @@ def is_seek_sync_mode_set_to(self, mode): def set_seek_sync_mode(self, mode): self._ctx.seek_sync_mode = mode + def is_any_videos_initialized(self): + return bool(self._ctx.video_blocks.initialized) + + def is_any_videos_seekable(self): + return any(not vb.is_live for vb in self._ctx.video_blocks.initialized) + + def is_any_videos_local_file(self): + return any(vb.is_local_file for vb in self._ctx.video_blocks.initialized) + def pause_all(self): self.set_pause.emit(True) diff --git a/gridplayer/widgets/video_block.py b/gridplayer/widgets/video_block.py index 156a750..a91db3f 100644 --- a/gridplayer/widgets/video_block.py +++ b/gridplayer/widgets/video_block.py @@ -462,7 +462,7 @@ def is_video_initialized(self): @property def is_local_file(self): - return not isinstance(self.video_params.uri, VideoURL) + return isinstance(self.video_params.uri, Path) @property def title(self):