Show current colour swatch in palette header
This commit is contained in:
parent
e3013bd305
commit
e9db16be46
|
|
@ -12,6 +12,7 @@ class ColorPickerMixin:
|
||||||
|
|
||||||
ref_hue: float | None
|
ref_hue: float | None
|
||||||
hue_span: float = 45.0 # degrees around the picked hue
|
hue_span: float = 45.0 # degrees around the picked hue
|
||||||
|
selected_colour: tuple[int, int, int] | None = None
|
||||||
|
|
||||||
def choose_color(self):
|
def choose_color(self):
|
||||||
rgb, hex_colour = colorchooser.askcolor(title="Farbe wählen")
|
rgb, hex_colour = colorchooser.askcolor(title="Farbe wählen")
|
||||||
|
|
@ -23,6 +24,7 @@ class ColorPickerMixin:
|
||||||
self.status.config(
|
self.status.config(
|
||||||
text=f"Farbe gewählt: {label} — Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
|
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:
|
def apply_sample_colour(self, hex_colour: str, name: str | None = None) -> None:
|
||||||
"""Apply a predefined colour preset."""
|
"""Apply a predefined colour preset."""
|
||||||
|
|
@ -39,6 +41,7 @@ class ColorPickerMixin:
|
||||||
f"Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
|
f"Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self._update_selected_colour(*rgb)
|
||||||
|
|
||||||
def enable_pick_mode(self):
|
def enable_pick_mode(self):
|
||||||
if self.preview_img is None:
|
if self.preview_img is None:
|
||||||
|
|
@ -67,6 +70,7 @@ class ColorPickerMixin:
|
||||||
self.status.config(
|
self.status.config(
|
||||||
text=f"Farbe vom Bild gewählt: Hue {hue_deg:.1f}°, S {sat_pct:.0f}%, V {val_pct:.0f}%"
|
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]:
|
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."""
|
"""Update slider ranges based on an RGB colour and return HSV summary."""
|
||||||
|
|
@ -77,6 +81,15 @@ class ColorPickerMixin:
|
||||||
self.update_preview()
|
self.update_preview()
|
||||||
return hue_deg, s * 100.0, v * 100.0
|
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:
|
def _set_slider_targets(self, hue_deg: float, saturation: float, value: float) -> None:
|
||||||
span = getattr(self, "hue_span", 45.0)
|
span = getattr(self, "hue_span", 45.0)
|
||||||
self.hue_min.set((hue_deg - span) % 360)
|
self.hue_min.set((hue_deg - span) % 360)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,16 @@ class UIBuilderMixin:
|
||||||
|
|
||||||
palette_frame = ttk.Frame(self.root)
|
palette_frame = ttk.Frame(self.root)
|
||||||
palette_frame.pack(fill=tk.X, padx=12, pady=(6, 8))
|
palette_frame.pack(fill=tk.X, padx=12, pady=(6, 8))
|
||||||
ttk.Label(palette_frame, text="Beispielfarben:").pack(side=tk.LEFT, padx=(0, 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)
|
||||||
|
ttk.Label(palette_frame, text="Aktuelle Farbe | Beispielfarben:").pack(side=tk.LEFT, padx=(0, 8))
|
||||||
swatch_container = ttk.Frame(palette_frame)
|
swatch_container = ttk.Frame(palette_frame)
|
||||||
swatch_container.pack(side=tk.LEFT)
|
swatch_container.pack(side=tk.LEFT)
|
||||||
for name, hex_code in self._preset_colours():
|
for name, hex_code in self._preset_colours():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue