adding requirements for file menu; improving brush color palette.

This commit is contained in:
vb
2025-11-06 15:43:24 +01:00
parent bedcc40596
commit db4fc94385
8 changed files with 327 additions and 26 deletions

View File

@@ -54,6 +54,7 @@ class BrushHandler:
# UI element references (will be set by GUI)
self._colorPreview = None
self._brushStatusLabel = None
self._colorSwatches = [] # List of color swatch buttons
def create_ui_panel(self, parent_frame: tk.Frame) -> None:
"""Create the brush settings UI panel.
@@ -70,20 +71,68 @@ class BrushHandler:
tk.Label(color_section, text="Brush Color:", font=("Arial", 10), bg="lightgray").pack(anchor="w")
color_frame = tk.Frame(color_section, bg="lightgray")
color_frame.pack(pady=5)
# Color preview
self._colorPreview = tk.Label(color_frame, bg=self._brushColor, width=15, height=3, relief="sunken", bd=2)
self._colorPreview.pack(side="left", padx=5)
preview_frame = tk.Frame(color_section, bg="lightgray")
preview_frame.pack(pady=5, fill="x")
def choose_color():
color = colorchooser.askcolor(title="Choose Brush Color", color=self._brushColor)
self._colorPreview = tk.Label(preview_frame, bg=self._brushColor, width=20, height=2, relief="sunken", bd=2)
self._colorPreview.pack(pady=5)
# Color palette
palette_frame = tk.Frame(color_section, bg="lightgray")
palette_frame.pack(pady=5, fill="x")
# Define color palette - common colors arranged in a grid
color_palette = [
# Row 1: Basic colors
["#000000", "#FFFFFF", "#FF0000", "#00FF00", "#0000FF", "#FFFF00"],
# Row 2: Secondary colors
["#FF00FF", "#00FFFF", "#FFA500", "#800080", "#FFC0CB", "#A52A2A"],
# Row 3: Grays and browns
["#808080", "#C0C0C0", "#D3D3D3", "#8B4513", "#654321", "#DEB887"],
# Row 4: Blues and greens
["#000080", "#008080", "#008000", "#00CED1", "#4682B4", "#32CD32"],
# Row 5: Reds and oranges
["#DC143C", "#FF4500", "#FF6347", "#FF1493", "#8B0000", "#CD5C5C"],
# Row 6: Yellows and purples
["#FFD700", "#FFA500", "#DA70D6", "#9370DB", "#4B0082", "#9932CC"]
]
# Create color swatches
self._colorSwatches = []
for row_idx, row_colors in enumerate(color_palette):
row_frame = tk.Frame(palette_frame, bg="lightgray")
row_frame.pack(pady=2)
row_swatches = []
for col_idx, color in enumerate(row_colors):
swatch = tk.Button(
row_frame,
bg=color,
activebackground=color,
width=3,
height=1,
relief="raised",
bd=2,
cursor="hand2",
command=lambda c=color: self._select_color(c)
)
swatch.pack(side="left", padx=1, pady=1)
row_swatches.append(swatch)
self._colorSwatches.append(row_swatches)
# Custom color button (still allow custom color selection)
custom_frame = tk.Frame(color_section, bg="lightgray")
custom_frame.pack(pady=5, fill="x")
def choose_custom_color():
color = colorchooser.askcolor(title="Choose Custom Color", color=self._brushColor)
if color[1]: # color[1] is the hex string
self._brushColor = color[1]
self._colorPreview.config(bg=self._brushColor)
self._select_color(color[1])
tk.Button(color_frame, text="Choose Color", command=choose_color, width=12).pack(side="left", padx=5)
tk.Button(custom_frame, text="Custom Color...", command=choose_custom_color, width=15).pack(pady=2)
# Initialize color selection highlighting
self._select_color(self._brushColor)
# Size selection section
size_section = tk.Frame(parent_frame, bg="lightgray")
@@ -116,6 +165,29 @@ class BrushHandler:
self._brushStatusLabel = tk.Label(info_frame, text="Inactive", fg="red", bg="lightgray", font=("Arial", 9))
self._brushStatusLabel.pack(anchor="w", pady=5)
def _select_color(self, color: str) -> None:
"""Select a color from the palette or custom color.
Args:
color: Hex color string (e.g., "#FF0000")
"""
self._brushColor = color
if self._colorPreview:
self._colorPreview.config(bg=self._brushColor)
# Update visual feedback on swatches (highlight selected if in palette)
color_found = False
for row_swatches in self._colorSwatches:
for swatch in row_swatches:
swatch_color = swatch.cget("bg")
if swatch_color.upper() == color.upper():
swatch.config(relief="sunken", bd=3)
color_found = True
else:
swatch.config(relief="raised", bd=2)
# If custom color not in palette, all swatches remain raised (normal state)
def toggle_brush_mode(self) -> None:
"""Toggle brush mode on/off."""
self._brushMode = not self._brushMode