Add exclusion persistence option

Introduce a config flag to reset exclusions when images change (default off), keep shapes when navigating, and theme preview accents accordingly.
This commit is contained in:
lm
2025-10-17 17:29:21 +02:00
parent 987c2e9e4a
commit 1d0acba3c3
6 changed files with 45 additions and 4 deletions
+10 -1
View File
@@ -1,6 +1,14 @@
"""Logic utilities and mixins for processing and configuration."""
from .constants import BASE_DIR, DEFAULTS, IMAGES_DIR, LANGUAGE, PREVIEW_MAX_SIZE, SUPPORTED_IMAGE_EXTENSIONS
from .constants import (
BASE_DIR,
DEFAULTS,
IMAGES_DIR,
LANGUAGE,
PREVIEW_MAX_SIZE,
RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
SUPPORTED_IMAGE_EXTENSIONS,
)
from .image_processing import ImageProcessingMixin
from .reset import ResetMixin
@@ -10,6 +18,7 @@ __all__ = [
"IMAGES_DIR",
"LANGUAGE",
"PREVIEW_MAX_SIZE",
"RESET_EXCLUSIONS_ON_IMAGE_CHANGE",
"SUPPORTED_IMAGE_EXTENSIONS",
"ImageProcessingMixin",
"ResetMixin",
+18
View File
@@ -92,7 +92,25 @@ def _extract_language(data: dict[str, Any]) -> str:
return sorted(supported)[0]
_CONFIG_DATA = _load_config_data()
_OPTION_DEFAULTS = {"reset_exclusions_on_image_change": False}
def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
section = data.get("options")
if not isinstance(section, dict):
return {}
result: dict[str, Any] = {}
value = section.get("reset_exclusions_on_image_change")
if isinstance(value, bool):
result["reset_exclusions_on_image_change"] = value
return result
_CONFIG_DATA = _load_config_data()
DEFAULTS = {**_DEFAULTS_BASE, **_extract_default_overrides(_CONFIG_DATA)}
LANGUAGE = _extract_language(_CONFIG_DATA)
OPTIONS = {**_OPTION_DEFAULTS, **_extract_options(_CONFIG_DATA)}
RESET_EXCLUSIONS_ON_IMAGE_CHANGE = OPTIONS["reset_exclusions_on_image_change"]
+11 -1
View File
@@ -89,6 +89,14 @@ class ImageProcessingMixin:
self.image_paths = list(paths)
if not self.image_paths:
return
self.exclude_shapes = []
self._rubber_start = None
self._rubber_id = None
self._stroke_preview_id = None
self._exclude_canvas_ids = []
self._exclude_mask = None
self._exclude_mask_px = None
self._exclude_mask_dirty = True
self.current_image_index = -1
self._display_image_by_index(max(0, start_index))
@@ -115,10 +123,12 @@ class ImageProcessingMixin:
self.image_path = path
self.orig_img = image
self.exclude_shapes = []
if getattr(self, "reset_exclusions_on_switch", False):
self.exclude_shapes = []
self._rubber_start = None
self._rubber_id = None
self._stroke_preview_id = None
self._exclude_canvas_ids = []
self._exclude_mask = None
self._exclude_mask_px = None
self._exclude_mask_dirty = True