Skip to content

Commit

Permalink
ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
seakrueger committed Sep 4, 2024
1 parent 0f54dcb commit afaae56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tagstudio/src/qt/modals/ffmpeg_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from PySide6.QtGui import QPixmap, QDesktopServices
from PySide6.QtWidgets import QMessageBox


class FfmpegChecker(QMessageBox):
"""A warning dialog for if FFmpeg is missing."""

warning_icon_128: Image.Image = Image.open(
str(Path(__file__).parents[3] / "resources/qt/images/thumb_warning.png")
).resize((math.floor(24 * 1.25), math.floor(24 * 1.25)))
Expand All @@ -20,22 +23,24 @@ class FfmpegChecker(QMessageBox):
def __init__(self):
super().__init__()

#self.warning_icon = QPixmap.fromImage(ImageQt.ImageQt(self.warning_icon_128))
#self.setIconPixmap(self.warning_icon)
# self.warning_icon = QPixmap.fromImage(ImageQt.ImageQt(self.warning_icon_128))
# self.setIconPixmap(self.warning_icon)
self.setIcon(QMessageBox.Warning)

self.setText("Warning: Could not find FFmpeg installation")
self.setStandardButtons(QMessageBox.Help | QMessageBox.Ignore)
self.setDefaultButton(QMessageBox.Ignore)

# Blocks other application interactions until resolved
self.setWindowModality(Qt.ApplicationModal)
self.setWindowTitle("Warning: Missing dependency")

self.ffmpeg_installed = False
self.ffprobe_installed = False

def installed(self):
"""Checks if both FFmpeg and FFprobe are installed"""
"""Checks if both FFmpeg and FFprobe are installed and in the PATH."""
# Same checker that ffmpeg-python uses
if which("ffmpeg"):
self.ffmpeg_installed = True
logging.info(f"FFmpeg found!")
Expand All @@ -45,14 +50,21 @@ def installed(self):
return self.ffmpeg_installed and self.ffprobe_installed

def show_warning(self):
"""Displays the warning to the user and awaits respone."""
if not self.ffmpeg_installed:
self.setText("Warning: Could not find FFmpeg installation")
self.setInformativeText("FFmpeg is required for video/audio thumbnails and playback")
self.setInformativeText(
"FFmpeg is required for video/audio thumbnails and playback"
)
elif not self.ffprobe_installed:
# If ffmpeg is installed but not ffprobe
self.setText("Warning: Could not find FFprobe installation")
self.setInformativeText("FFprobe is required for video/audio thumbnails and playback")
self.setInformativeText(
"FFprobe is required for video/audio thumbnails and playback"
)

# Shows the dialog
selection = self.exec()
# Selection will either be QMessageBox.Help or QMessageBox.Ignore
if selection == QMessageBox.Help:
QDesktopServices.openUrl(QUrl(self.help_url))
1 change: 1 addition & 0 deletions tagstudio/src/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,7 @@ def open_library(self, path: Path):
self.main_window.toggle_landing_page(False)

def check_ffmpeg(self) -> None:
"""Checks if FFmpeg is installed and displays a warning if not."""
self.ffmpeg_checker = FfmpegChecker()
if not self.ffmpeg_checker.installed():
self.ffmpeg_checker.show_warning()
Expand Down

0 comments on commit afaae56

Please sign in to comment.