Compare commits

..

5 Commits

4 changed files with 74 additions and 35 deletions

View File

@ -12,6 +12,7 @@ class ColorPickerMixin:
ref_hue: float | None
hue_span: float = 45.0 # degrees around the picked hue
selected_colour: tuple[int, int, int] | None = None
def choose_color(self):
rgb, hex_colour = colorchooser.askcolor(title="Farbe wählen")
@ -23,6 +24,7 @@ class ColorPickerMixin:
self.status.config(
text=f"Farbe gewählt: {label} — Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
)
self._update_selected_colour(r, g, b)
def apply_sample_colour(self, hex_colour: str, name: str | None = None) -> None:
"""Apply a predefined colour preset."""
@ -39,6 +41,7 @@ class ColorPickerMixin:
f"Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
)
)
self._update_selected_colour(*rgb)
def enable_pick_mode(self):
if self.preview_img is None:
@ -67,6 +70,7 @@ class ColorPickerMixin:
self.status.config(
text=f"Farbe vom Bild gewählt: Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
)
self._update_selected_colour(r, g, b)
def _apply_rgb_selection(self, r: int, g: int, b: int) -> tuple[float, float, float]:
"""Update slider ranges based on an RGB colour and return HSV summary."""
@ -77,6 +81,15 @@ class ColorPickerMixin:
self.update_preview()
return hue_deg, s * 100.0, v * 100.0
def _update_selected_colour(self, r: int, g: int, b: int) -> None:
self.selected_colour = (r, g, b)
if hasattr(self, "current_colour_sw"):
hex_colour = f"#{r:02x}{g:02x}{b:02x}"
try:
self.current_colour_sw.configure(background=hex_colour)
except Exception:
pass
def _set_slider_targets(self, hue_deg: float, saturation: float, value: float) -> None:
span = getattr(self, "hue_span", 45.0)
self.hue_min.set((hue_deg - span) % 360)

View File

@ -36,9 +36,11 @@ class ThemeMixin:
if self.theme == "dark":
bg, fg = "#0f0f10", "#f1f1f1"
status_fg = "#f5f5f5"
highlight_fg = "#f2c744"
else:
bg, fg = "#ededf2", "#202020"
status_fg = "#1c1c1c"
highlight_fg = "#c56217"
self.root.configure(bg=bg) # type: ignore[attr-defined]
s = self.style
@ -61,6 +63,10 @@ class ThemeMixin:
if callable(status_refresher) and hasattr(self, "status"):
status_refresher(status_fg)
accent_refresher = getattr(self, "_refresh_accent_labels", None)
if callable(accent_refresher) and hasattr(self, "filename_label"):
accent_refresher(highlight_fg)
def detect_system_theme(self) -> str:
"""Best-effort detection of the OS theme preference."""
try:

View File

@ -21,8 +21,8 @@ class UIBuilderMixin:
("🎨", "Farbe wählen", self.choose_color),
("🖱", "Farbe aus Bild klicken", self.enable_pick_mode),
("💾", "Overlay speichern", self.save_overlay),
("🧹", "Excludes löschen", self.clear_excludes),
("", "Letztes Exclude entfernen", self.undo_exclude),
("🧹", "Ausschlüsse löschen", self.clear_excludes),
("", "Letzten Ausschluss entfernen", self.undo_exclude),
("🔄", "Slider zurücksetzen", self.reset_sliders),
("🌓", "Theme umschalten", self.toggle_theme),
]
@ -49,6 +49,17 @@ class UIBuilderMixin:
palette_frame = ttk.Frame(self.root)
palette_frame.pack(fill=tk.X, padx=12, pady=(6, 8))
self.current_colour_sw = tk.Canvas(
palette_frame,
width=24,
height=24,
highlightthickness=0,
background="#f2c744",
bd=0,
)
self.current_colour_sw.pack(side=tk.LEFT, padx=(0, 8), pady=2)
self.current_colour_label = ttk.Label(palette_frame, text="Aktuelle Farbe")
self.current_colour_label.pack(side=tk.LEFT, padx=(0, 8))
ttk.Label(palette_frame, text="Beispielfarben:").pack(side=tk.LEFT, padx=(0, 8))
swatch_container = ttk.Frame(palette_frame)
swatch_container.pack(side=tk.LEFT)
@ -101,7 +112,6 @@ class UIBuilderMixin:
self.filename_label = ttk.Label(
info_frame,
text="",
foreground="#f2c744",
font=("Segoe UI", 10, "bold"),
anchor="center",
justify="center",
@ -111,8 +121,7 @@ class UIBuilderMixin:
self.ratio_label = ttk.Label(
info_frame,
text="Treffer (mit Excludes): —",
foreground="#f2c744",
text="Markierungen (mit Ausschlüssen): —",
font=("Segoe UI", 10, "bold"),
anchor="center",
justify="center",
@ -499,6 +508,13 @@ class UIBuilderMixin:
self.status.configure(foreground=fg)
self._status_palette["fg"] = fg
def _refresh_accent_labels(self, colour: str) -> None:
try:
self.filename_label.configure(foreground=colour)
self.ratio_label.configure(foreground=colour)
except Exception:
pass
def _init_copy_menu(self):
self._copy_target = None
self.copy_menu = tk.Menu(self.root, tearoff=0)

View File

@ -64,16 +64,20 @@ class ImageProcessingMixin:
def show_next_image(self, event=None) -> None:
if not getattr(self, "image_paths", None):
return
next_index = getattr(self, "current_image_index", -1) + 1
if next_index < len(self.image_paths):
self._display_image_by_index(next_index)
if not self.image_paths:
return
current = getattr(self, "current_image_index", -1)
next_index = (current + 1) % len(self.image_paths)
self._display_image_by_index(next_index)
def show_previous_image(self, event=None) -> None:
if not getattr(self, "image_paths", None):
return
prev_index = getattr(self, "current_image_index", -1) - 1
if prev_index >= 0:
self._display_image_by_index(prev_index)
if not self.image_paths:
return
current = getattr(self, "current_image_index", -1)
prev_index = (current - 1) % len(self.image_paths)
self._display_image_by_index(prev_index)
def _set_image_collection(self, paths: Sequence[Path], start_index: int) -> None:
self.image_paths = list(paths)
@ -182,9 +186,9 @@ class ImageProcessingMixin:
excl_match = (matches_ex / total_ex * 100) if total_ex else 0.0
self.ratio_label.config(
text=(
f"Treffer (mit Excludes): {r_with:.2f}% | "
f"Treffer (ohne Excludes): {r_no:.2f}% | "
f"Excluded: {excl_share:.2f}% vom Bild, davon {excl_match:.2f}% Treffer"
f"Markierungen (mit Ausschlüssen): {r_with:.2f}% | "
f"Markierungen (ohne Ausschlüsse): {r_no:.2f}% | "
f"Ausgeschlossen: {excl_share:.2f}% der Pixel, davon {excl_match:.2f}% markiert"
)
)