diff --git a/random_file_picker/openers.py b/random_file_picker/openers.py index f5e59fe..b108bef 100644 --- a/random_file_picker/openers.py +++ b/random_file_picker/openers.py @@ -1,8 +1,17 @@ import os import pathlib +import shutil import subprocess +def is_geeqie_available() -> bool: + """ + Check if the Geeqie image viewer is available on the system. + + :return: True if Geeqie is available, False otherwise. + """ + return shutil.which("geeqie") is not None + def open_file_with_default_app(file_path: pathlib.Path) -> bool: """ Open the specified file path with the default application associated with its file type. diff --git a/random_file_picker/tui.py b/random_file_picker/tui.py index 6e28e21..8e8b5e0 100644 --- a/random_file_picker/tui.py +++ b/random_file_picker/tui.py @@ -16,12 +16,19 @@ from textual.binding import BindingType from textual.widgets import Footer, Header, Label from random_file_picker.core import collect_files, move_file_to_move_folder, upload_file -from random_file_picker.openers import open_file_in_dolphin, open_file_with_default_app, open_file_with_geeqie +from random_file_picker.openers import ( + is_geeqie_available, + open_file_in_dolphin, + open_file_with_default_app, + open_file_with_geeqie, +) IMG_EXTENSIONS = [ ".jpg", ".jpeg", ".webp", ".png", ".gif", ] +GEEQIE_AVAILABLE = is_geeqie_available() + class Args(tap.TypedArgs): file_size: int = tap.arg("-s", default=10, help="Maximum file size in MB") directory: str = tap.arg("-d", default=".", help="Directory to search for files") @@ -219,6 +226,10 @@ class MenuApp(App[None]): def main_with_tap(args: Args) -> None: + if args.use_geeqie and not GEEQIE_AVAILABLE: + print("❌ Geeqie is not available on this system. Please install it or run without --use-geeqie.") + return + app = MenuApp( directory=args.directory, file_limit=args.file_size,