Add Pattern Templates for Key Colors targets with visual canvas editor
Introduce Pattern Template entity as a reusable rectangle layout that Key Colors targets reference via pattern_template_id. This replaces inline rectangle storage with a shared template system. Backend: - New PatternTemplate data model, store (JSON persistence), CRUD API - KC targets now reference pattern_template_id instead of inline rectangles - ProcessorManager resolves pattern template at KC processing start - Picture source test endpoint supports capture_duration=0 for single frame - Delete protection: 409 when template is referenced by a KC target Frontend: - Pattern Templates section in Key Colors sub-tab with card UI - Visual canvas editor with drag-to-move, 8-point resize handles - Background capture from any picture source for visual alignment - Precise coordinate list synced bidirectionally with canvas - Resizable editor container, viewport-constrained modal - KC target editor uses pattern template dropdown instead of inline rects - Localization (en/ru) for all new UI elements Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,12 @@ from .postprocessing import (
|
||||
PostprocessingTemplateUpdate,
|
||||
PPTemplateTestRequest,
|
||||
)
|
||||
from .pattern_templates import (
|
||||
PatternTemplateCreate,
|
||||
PatternTemplateListResponse,
|
||||
PatternTemplateResponse,
|
||||
PatternTemplateUpdate,
|
||||
)
|
||||
from .picture_sources import (
|
||||
ImageValidateRequest,
|
||||
ImageValidateResponse,
|
||||
@@ -109,6 +115,10 @@ __all__ = [
|
||||
"PostprocessingTemplateResponse",
|
||||
"PostprocessingTemplateUpdate",
|
||||
"PPTemplateTestRequest",
|
||||
"PatternTemplateCreate",
|
||||
"PatternTemplateListResponse",
|
||||
"PatternTemplateResponse",
|
||||
"PatternTemplateUpdate",
|
||||
"ImageValidateRequest",
|
||||
"ImageValidateResponse",
|
||||
"PictureSourceCreate",
|
||||
|
||||
42
server/src/wled_controller/api/schemas/pattern_templates.py
Normal file
42
server/src/wled_controller/api/schemas/pattern_templates.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Pydantic schemas for pattern template API."""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from .picture_targets import KeyColorRectangleSchema
|
||||
|
||||
|
||||
class PatternTemplateCreate(BaseModel):
|
||||
"""Request to create a pattern template."""
|
||||
|
||||
name: str = Field(description="Template name", min_length=1, max_length=100)
|
||||
rectangles: List[KeyColorRectangleSchema] = Field(default_factory=list, description="List of named rectangles")
|
||||
description: Optional[str] = Field(None, description="Template description", max_length=500)
|
||||
|
||||
|
||||
class PatternTemplateUpdate(BaseModel):
|
||||
"""Request to update a pattern template."""
|
||||
|
||||
name: Optional[str] = Field(None, description="Template name", min_length=1, max_length=100)
|
||||
rectangles: Optional[List[KeyColorRectangleSchema]] = Field(None, description="List of named rectangles")
|
||||
description: Optional[str] = Field(None, description="Template description", max_length=500)
|
||||
|
||||
|
||||
class PatternTemplateResponse(BaseModel):
|
||||
"""Pattern template response."""
|
||||
|
||||
id: str = Field(description="Template ID")
|
||||
name: str = Field(description="Template name")
|
||||
rectangles: List[KeyColorRectangleSchema] = Field(description="List of named rectangles")
|
||||
created_at: datetime = Field(description="Creation timestamp")
|
||||
updated_at: datetime = Field(description="Last update timestamp")
|
||||
description: Optional[str] = Field(None, description="Template description")
|
||||
|
||||
|
||||
class PatternTemplateListResponse(BaseModel):
|
||||
"""List of pattern templates."""
|
||||
|
||||
templates: List[PatternTemplateResponse] = Field(description="List of pattern templates")
|
||||
count: int = Field(description="Number of templates")
|
||||
@@ -60,7 +60,7 @@ class PictureSourceListResponse(BaseModel):
|
||||
class PictureSourceTestRequest(BaseModel):
|
||||
"""Request to test a picture source."""
|
||||
|
||||
capture_duration: float = Field(default=5.0, ge=1.0, le=30.0, description="Duration to capture in seconds")
|
||||
capture_duration: float = Field(default=5.0, ge=0.0, le=30.0, description="Duration to capture in seconds (0 = single frame)")
|
||||
border_width: int = Field(default=10, ge=1, le=100, description="Border width in pixels for preview")
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class KeyColorsSettingsSchema(BaseModel):
|
||||
fps: int = Field(default=10, description="Extraction rate (1-60)", ge=1, le=60)
|
||||
interpolation_mode: str = Field(default="average", description="Color mode (average, median, dominant)")
|
||||
smoothing: float = Field(default=0.3, description="Temporal smoothing (0.0-1.0)", ge=0.0, le=1.0)
|
||||
rectangles: List[KeyColorRectangleSchema] = Field(default_factory=list, description="Rectangles to extract colors from")
|
||||
pattern_template_id: str = Field(default="", description="Pattern template ID for rectangle layout")
|
||||
|
||||
|
||||
class ExtractedColorResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user