"""Utility to regenerate the DPSCoach banner image (app/banner.png)."""
from __future__ import annotations
from pathlib import Path
from PySide6.QtCore import Qt, QRectF
from PySide6.QtGui import (
QColor,
QFont,
QGuiApplication,
QImage,
QLinearGradient,
QPainter,
QPixmap,
)
from app.constants import BANNER_IMAGE_PATH
ROOT = Path(__file__).resolve().parents[1]
VISUALS = ROOT / "visuals"
def build_banner(width: int = 1280, height: int = 320) -> None:
image = QImage(width, height, QImage.Format_RGB32)
gradient = QLinearGradient(0, 0, width, height)
gradient.setColorAt(0.0, QColor("#05060d"))
gradient.setColorAt(0.45, QColor("#0f1c3a"))
gradient.setColorAt(1.0, QColor("#2a4d7d"))
painter = QPainter(image)
painter.fillRect(0, 0, width, height, gradient)
painter.setRenderHint(QPainter.Antialiasing)
title_font = QFont("Segoe UI", 56)
title_font.setBold(True)
painter.setFont(title_font)
painter.setPen(QColor("#f8fafc"))
painter.drawText(
QRectF(40, 32, width / 2, 160), int(Qt.AlignLeft | Qt.AlignVCenter), "DPSCoach"
)
subtitle_font = QFont("Segoe UI", 22)
painter.setFont(subtitle_font)
painter.setPen(QColor("#c3d7ff"))
painter.drawText(
QRectF(40, 180, width / 2 + 80, 120),
int(Qt.AlignLeft | Qt.AlignTop),
"Local AI coach · DuckDB analytics · FastMCP tools",
)
screenshot = VISUALS / "dps-coach.png"
if screenshot.exists():
pixmap = QPixmap(str(screenshot))
if not pixmap.isNull():
scaled = pixmap.scaledToHeight(260, Qt.SmoothTransformation)
x = width - scaled.width() - 40
y = (height - scaled.height()) // 2
painter.setOpacity(0.35)
painter.fillRect(x - 20, y - 20, scaled.width() + 40, scaled.height() + 40, QColor("#05060d"))
painter.setOpacity(1.0)
painter.drawPixmap(x, y, scaled)
painter.end()
BANNER_IMAGE_PATH.parent.mkdir(parents=True, exist_ok=True)
image.save(str(BANNER_IMAGE_PATH), "PNG")
print(f"Wrote {BANNER_IMAGE_PATH}")
if __name__ == "__main__":
app = QGuiApplication([])
build_banner()
app.quit()