A bunch of changes
This commit is contained in:
@@ -11,6 +11,7 @@ Classes:
|
||||
interacts with the ImagePreloader.
|
||||
"""
|
||||
import os
|
||||
import logging
|
||||
import math
|
||||
from PySide6.QtCore import QThread, Signal, QMutex, QWaitCondition, QObject, Qt
|
||||
from PySide6.QtGui import QImage, QImageReader, QPixmap, QTransform
|
||||
@@ -22,6 +23,8 @@ from constants import (
|
||||
)
|
||||
from metadatamanager import XattrManager, load_common_metadata
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ImagePreloader(QThread):
|
||||
"""
|
||||
@@ -111,8 +114,8 @@ class ImagePreloader(QThread):
|
||||
# Load tags and rating here to avoid re-reading in main thread
|
||||
tags, rating = load_common_metadata(path)
|
||||
self.image_ready.emit(idx, path, img, tags, rating)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.warning(f"ImagePreloader failed to load {path}: {e}")
|
||||
|
||||
|
||||
class ImageController(QObject):
|
||||
@@ -156,6 +159,12 @@ class ImageController(QObject):
|
||||
def cleanup(self):
|
||||
"""Stops the background preloader thread."""
|
||||
self.preloader.stop()
|
||||
self._current_metadata_path = None
|
||||
self._loaded_path = None
|
||||
self._current_tags = []
|
||||
self._current_rating = 0
|
||||
self._cached_next_image = None
|
||||
self._cached_next_index = -1
|
||||
|
||||
def _trigger_preload(self):
|
||||
"""Identifies the next image in the list and asks the preloader to load it."""
|
||||
@@ -209,19 +218,13 @@ class ImageController(QObject):
|
||||
|
||||
# Optimization: Check if image is already loaded
|
||||
if path and self._loaded_path == path and not self.pixmap_original.isNull():
|
||||
self.rotation = 0
|
||||
self.flip_h = False
|
||||
self.flip_v = False
|
||||
self.faces = []
|
||||
|
||||
# Ensure metadata is consistent with current path
|
||||
if self._current_metadata_path != path:
|
||||
self._current_tags, self._current_rating = load_common_metadata(path)
|
||||
self._current_metadata_path = path
|
||||
|
||||
self.load_faces()
|
||||
self._trigger_preload()
|
||||
return True
|
||||
return True, False
|
||||
|
||||
self.pixmap_original = QPixmap()
|
||||
self._loaded_path = None
|
||||
@@ -231,7 +234,7 @@ class ImageController(QObject):
|
||||
self.faces = []
|
||||
|
||||
if not path:
|
||||
return False
|
||||
return False, False
|
||||
|
||||
# Check cache
|
||||
if self.index == self._cached_next_index and self._cached_next_image:
|
||||
@@ -250,7 +253,7 @@ class ImageController(QObject):
|
||||
image = reader.read()
|
||||
if image.isNull():
|
||||
self._trigger_preload()
|
||||
return False
|
||||
return False, False
|
||||
self.pixmap_original = QPixmap.fromImage(image)
|
||||
|
||||
# Load tags and rating if not already set for this path
|
||||
@@ -261,7 +264,7 @@ class ImageController(QObject):
|
||||
self._loaded_path = path
|
||||
self.load_faces()
|
||||
self._trigger_preload()
|
||||
return True
|
||||
return True, True
|
||||
|
||||
def load_faces(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user