Call thumbnailer

This commit is contained in:
Jan Hamal Dvořák 2025-03-09 18:39:41 +01:00
parent dc37e26256
commit 85950648b9

View file

@ -8,6 +8,7 @@ from typing import Any, cast
import gi
from .file_model import FileItem, FileListModel, FileType
from .thumbnailer import Thumbnailer
from .video_player import VideoPlayer
gi.require_version("Gdk", "4.0")
@ -29,8 +30,9 @@ class MainWindow(Gtk.ApplicationWindow):
overlay_hide_time: float
last_position_save: float
def __init__(self, *args: Any, **kwargs: Any):
def __init__(self, *args: Any, thumbnailer: Thumbnailer, **kwargs: Any):
super().__init__(*args, **kwargs)
self.thumbnailer = thumbnailer
# Directory history stack
self.directory_history: list[Path] = []
@ -441,7 +443,10 @@ class MainWindow(Gtk.ApplicationWindow):
if path.is_dir():
items.append(FileItem(path.name, FileType.DIRECTORY, path.resolve()))
elif path.suffix in (".mkv", ".mp4", ".avi"):
items.append(FileItem(path.name, FileType.VIDEO, path.resolve()))
file_item = FileItem(path.name, FileType.VIDEO, path.resolve())
if not file_item.saved_thumbnail:
self.thumbnailer.generate_thumbnail(file_item)
items.append(file_item)
# Sort directories first, then files, both alphabetically
items.sort(key=lambda x: (x.file_type != FileType.DIRECTORY, x.name.lower()))
@ -459,6 +464,9 @@ class App(Gtk.Application):
# Initialize GStreamer
Gst.init(None)
# Create thumbnailer
self.thumbnailer = Thumbnailer()
# Load CSS
css_provider = Gtk.CssProvider()
css_file = Path(__file__).parent / "style.css"
@ -475,7 +483,7 @@ class App(Gtk.Application):
)
def do_activate(self):
win = MainWindow(application=self)
win = MainWindow(application=self, thumbnailer=self.thumbnailer)
win.present()