first
This commit is contained in:
64
photo_sorter/ui/target_bar.py
Normal file
64
photo_sorter/ui/target_bar.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from PyQt6.QtCore import Qt, QTimer
|
||||
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QWidget
|
||||
|
||||
|
||||
@dataclass
|
||||
class TargetDisplay:
|
||||
key: str
|
||||
label: str
|
||||
|
||||
|
||||
class TargetBar(QWidget):
|
||||
"""Zeigt die konfigurierten Ziele als Leiste an und erlaubt visuelles Highlighting."""
|
||||
|
||||
def __init__(self, parent: Optional[QWidget] = None) -> None:
|
||||
super().__init__(parent)
|
||||
|
||||
self._layout = QHBoxLayout(self)
|
||||
self._layout.setContentsMargins(8, 4, 8, 4)
|
||||
self._layout.setSpacing(12)
|
||||
|
||||
self._labels: Dict[str, QLabel] = {}
|
||||
|
||||
def set_targets(self, targets: List[TargetDisplay]) -> None:
|
||||
# Alte Widgets entfernen
|
||||
while self._layout.count():
|
||||
item = self._layout.takeAt(0)
|
||||
w = item.widget()
|
||||
if w is not None:
|
||||
w.deleteLater()
|
||||
self._labels.clear()
|
||||
|
||||
for t in targets:
|
||||
text = t.label or f"Ziel {t.key}"
|
||||
lbl = QLabel(text, self)
|
||||
lbl.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
lbl.setProperty("targetKey", t.key)
|
||||
lbl.setStyleSheet(
|
||||
"QLabel { padding: 4px 10px; border-radius: 4px; border: 1px solid #888; }"
|
||||
)
|
||||
self._layout.addWidget(lbl)
|
||||
self._labels[t.key] = lbl
|
||||
|
||||
self._layout.addStretch(1)
|
||||
|
||||
def highlight_target(self, key: str, duration_ms: int = 200) -> None:
|
||||
lbl = self._labels.get(key)
|
||||
if not lbl:
|
||||
return
|
||||
|
||||
original = lbl.styleSheet()
|
||||
lbl.setStyleSheet(
|
||||
"QLabel { padding: 4px 10px; border-radius: 4px; border: 2px solid #0078d7; "
|
||||
"background-color: #e0f0ff; }"
|
||||
)
|
||||
|
||||
def reset() -> None:
|
||||
lbl.setStyleSheet(original)
|
||||
|
||||
QTimer.singleShot(duration_ms, reset)
|
||||
Reference in New Issue
Block a user