Files
UnheardCity/tools/screenshots.py
2026-10-09 02:57:04 +02:00

90 lines
3.3 KiB
Python

"""Render the user-guide screenshots headless (docs/img/*.png). Read-only: never applies anything.
python tools/screenshots.py [--game DIR]
"""
import argparse
import os
import sys
import tempfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
if sys.platform == "win32":
os.environ.setdefault("QT_QPA_FONTDIR", os.path.join(os.environ.get("WINDIR", r"C:\Windows"), "Fonts"))
os.environ["ACKIT_NO_AUDIO"] = "1"
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--game")
a = ap.parse_args()
from PySide6.QtWidgets import QApplication
from ackit import audio
from app.dialogs import SettingsDialog
from app.mainwindow import MainWindow
from app.workers import Runner
import numpy as np
out = os.path.join(ROOT, "docs", "img")
os.makedirs(out, exist_ok=True)
from app import theme
app = QApplication([])
with tempfile.TemporaryDirectory() as td:
os.environ["ACKIT_HOME"] = td # do not touch the real settings/notes
# docs show no wallpaper (the app still shows it)
st = {"full_backup": True, "background_enabled": False}
theme.apply(app)
w = MainWindow(settings=st, runner=Runner(sync=True), game_dir=a.game)
w.resize(1500, 950)
w.show()
app.processEvents() # the game loads here
# status bar: show the store where users have it, not this temporary folder (no local user names)
w.lbl_game.setText(w.lbl_game.text().replace(os.path.join(td, "data"), r"%APPDATA%\UnheardCity"))
# 1: browser filtered by character
w.cmb_char.setCurrentText("Joker")
w._filters_changed()
w.search.setText("cinematic")
w._filter_text()
w.fit_editor()
target = next(w.proxy.sound_at(w.proxy.index(r, 1)) for r in range(w.proxy.rowCount())
if w.proxy.sound_at(w.proxy.index(r, 1)).seconds > 4)
w.select_name(target.name)
app.processEvents()
# a replacement loaded for display only (not applied)
x, sr = w.editor.orig
t = np.arange(len(x)) / sr
rep = (0.5 * x[:, :1] * (0.6 + 0.4 * np.sin(2 * np.pi * 0.7 * t))[:, None]).astype(np.float32)
path = os.path.join(td, "my_line.wav")
audio.save_wav(path, rep, sr)
w.editor.load_file(path)
w.editor.cb_match.setChecked(True)
w.editor._update_new()
w.editor.sp_a.setValue(0.2)
app.processEvents()
w.grab().save(os.path.join(out, "main.png"))
w.editor.grab().save(os.path.join(out, "editor.png"))
# 2: category browsing
w.clear_filters()
w.cmb_group.setCurrentText("Speech")
w._group_changed(None)
w.cmb_cat.setCurrentText("Interview tapes")
w._filters_changed()
w.search.setText("joker")
w._filter_text()
app.processEvents()
w.grab().save(os.path.join(out, "browse.png"))
# 3: settings
d = SettingsDialog(w.settings, w)
d.bg_on.setChecked(True) # show the user's default (on), only the screenshots run without it
d.show()
app.processEvents()
d.grab().save(os.path.join(out, "settings.png"))
d.close()
w.close()
print("screenshots in", out)
if __name__ == "__main__":
main()