Files
LihonT/scripts/make_theme_previews.py
cheb0chik 38e7b2551e LihonT 2 Serena alpha 2
Plugin icons for the feed buttons (right ui.icons: like, comment, collect, share), preview cards that a theme author
attaches and the list of looks shows before a theme is picked, the sample plugins lihont.icons-sticker, lihont.theme-win95 and
lihont.theme-sunset with their pictures, docs, SDK, skill and tests for all of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 13:08:56 +03:00

51 lines
1.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Draws the preview cards of the sample theme plugins (lihont.theme-win95, lihont.theme-sunset).
A theme author attaches such pictures to the plugin ("theme": {"preview": ["preview1.png", ...]}); the list of looks in the
settings shows them before the theme is picked. These two are drawn with the same mock of the settings screen as the promo video.
usage: py -X utf8 -B scripts/make_theme_previews.py
"""
import sys
from pathlib import Path
from PIL import Image
sys.path.insert(0, str(Path(__file__).resolve().parent))
import make_serena_promo as S # noqa: E402
ROOT = S.ROOT
CARDS = {
"lihont.theme-win95": "win95",
"lihont.theme-sunset": "sunset",
}
ROWS = {
1: None,
2: ["anna: смотрите, вайб!", "luna: нашёл своих", "boy: огонёк горит", "я: пузыри топ"],
}
def render(look, rows):
img = Image.new("RGBA", (780 + 120, 520 + 150), (0, 0, 0, 0))
S.settings_card(img, look, (60, 70, 60 + 780, 70 + 520), lt=-1, rows=rows)
# crop to the drawn page and scale down to a card that stays well under 400 KB
box = (30, 40, 60 + 780 + 30, 70 + 520 + 30)
card = img.crop(box).convert("RGB")
card.thumbnail((540, 400), Image.Resampling.LANCZOS)
return card
def main():
for folder, look in CARDS.items():
out = ROOT / "plugins" / folder / "assets"
out.mkdir(parents=True, exist_ok=True)
for n, rows in ROWS.items():
path = out / ("preview%d.png" % n)
render(look, rows).save(path, optimize=True)
print(folder, path.name, path.stat().st_size, "bytes")
if __name__ == "__main__":
main()