"""Check the section index added to Settings and the Task editor, offscreen. The index is navigation only, so the test is again a subtraction test: every input control must still be there, and every index row must actually scroll to its section. Both dialogs are built with .show(), never .exec() — exec() blocks. Run: python tools/check_dialogs.py """ from __future__ import annotations import os import sys from pathlib import Path REPO = Path(__file__).resolve().parent.parent sys.path.insert(0, str(REPO.parent)) sys.path.insert(0, str(Path(__file__).resolve().parent)) os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") from capture_screens import _isolate_home, _load_fonts # noqa: E402 def controls(dlg): from PySide6.QtWidgets import (QCheckBox, QComboBox, QLineEdit, QListWidget, QPlainTextEdit, QPushButton, QSpinBox) n = 0 for cls in (QComboBox, QLineEdit, QCheckBox, QSpinBox, QPlainTextEdit, QPushButton, QListWidget): n += len(dlg.findChildren(cls)) return n def check(name, dlg, app, expect_rows): fails = [] print(f"--- {name} ---") n_ctl = controls(dlg) idx = dlg.section_list rows = [idx.item(i).text() for i in range(idx.count())] print(f"muc luc : {rows}") print(f"tong control trong hop thoai: {n_ctl}") if len(rows) != expect_rows: fails.append(f"{name}: cho {expect_rows} muc, thay {len(rows)}") if any(not r or r.endswith(".g_basic") or r.startswith("settings.") for r in rows): fails.append(f"{name}: co muc chua dich") # Each row must scroll somewhere different (and the last one furthest down). from PySide6.QtWidgets import QScrollArea scroll = dlg.findChildren(QScrollArea)[0] positions = [] for i in range(idx.count()): idx.itemClicked.emit(idx.item(i)) app.processEvents() positions.append(scroll.verticalScrollBar().value()) print(f"vi tri cuon theo tung muc : {positions}") if positions != sorted(positions): fails.append(f"{name}: muc luc nhay khong theo thu tu tren xuong") if len(set(positions)) < 2: fails.append(f"{name}: bam muc nao cung dung mot cho — muc luc khong chay") return n_ctl, fails def main() -> int: sandbox = _isolate_home() from PySide6.QtWidgets import QApplication app = QApplication([]) _load_fonts() from cowork_local.config import AppConfig, CONFIG_DIR assert str(sandbox) in str(CONFIG_DIR), f"isolation failed: {CONFIG_DIR}" from cowork_local.i18n import set_language, tr from cowork_local.state import AppContext from cowork_local.ui.settings_dialog import SettingsDialog from cowork_local.ui.task_editor_dialog import TaskEditorDialog set_language("vi") ctx = AppContext(AppConfig.load()) fails = [] s = SettingsDialog(ctx) s.resize(900, 600) s.show() app.processEvents() n_s, f = check("Cai dat", s, app, 5) fails += f t = TaskEditorDialog(ctx=ctx) # task=None → a new task, all fields present t.resize(900, 600) t.show() app.processEvents() n_t, f = check("Task editor", t, app, 5) fails += f # Translations for the two names that had to be invented for the index. print() for lang in ("vi", "en", "ja"): set_language(lang) print(f" {lang}: general={tr('settings.group.general')!r} " f"basic={tr('schedtask.g_basic')!r}") for key in ("settings.group.general", "schedtask.g_basic"): if tr(key) == key: fails.append(f"thieu ban dich {key} cho {lang}") set_language("vi") print() if fails: print("*** LOI ***") for x in fails: print(" " + x) return 1 print("KET QUA: hai hop thoai co muc luc, khong mat control nao") return 0 if __name__ == "__main__": raise SystemExit(main())