Files
cowork-local/tools/check_responsive.py
T
Nam Pham Dinh ThanhandClaude Opus 5 d060d5679a Align rail Settings, translate the help transcript, style the checkers
Settings sat 7px further in than the Dashboard/Giám sát rows above it — its
QSS gave it a 6px side margin where those rows start at the rail edge. At the
collapsed 54px width that put its icon near the middle of the rail, which is
what "thu gọn menu lại ra giữa" was describing. Icon and label now start on
the same x as the rows, open and collapsed, in both themes.

The help panel's transcript is rendered HTML, so switching language re-labelled
the chrome but left the greeting — and the "AI Assistant" speaker label — in
whatever language the panel was built in. retranslate() now rewrites the
greeting (matched by identity, so a real reply is never touched) and re-renders.

The sparkle is #FDBE59, sampled from the audit page's own render. Its CSS says
.spark{color:#0F9B8A}, but the glyph is the ✨ emoji and a colour emoji ignores
CSS colour, so the page has always drawn a gold star.

Behind all three: MainWindow does not style itself — run() calls
app.setStyleSheet — so 12 of 13 checkers were measuring a window with no
padding, margins or borders. Every QSS-driven layout bug was invisible to them,
and an unstyled window reported an icon drift that does not exist. Added
_apply_theme() and wired it through.

Two checker repairs that followed:
  · check_no_hscroll flagged the 9pt dialogs on sizeHintForColumn(0), which
    returns 182px at 9pt, 11pt and 14pt alike. Nothing was clipped. It now
    compares the painted text against the width actually on screen, and fails
    on a squeezed list (24 combos) where the old test passed.
  · the checkers print Vietnamese and died mid-report on a cp932 console.

New: check_rail_align (icons hold one line, both themes, both states) and
check_help_i18n (transcript follows the language). Both verified to fail
without their fix.

15/15 checkers pass. check_nav and check_design_parity segfault in Qt teardown
roughly one run in three — pre-existing, after the verdict prints, and it
happens with or without the theme change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 10:48:11 +09:00

120 lines
4.2 KiB
Python

"""Measure what actually breaks on a small screen, screen by screen.
A pane is "clipped" when the width it is given is smaller than the width it says
it needs (minimumSizeHint): Qt then cuts content off instead of shrinking it,
which is what shows up as half-drawn buttons and cut-off labels.
Reports per destination, at a few window sizes, and lists the widest offenders
so a fix can be aimed at the right widget instead of guessed at.
Run: python tools/check_responsive.py [width height ...]
"""
from __future__ import annotations
import os
import sys
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
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 _freeze_schedulers, _isolate_home, _load_fonts # noqa: E402
SIZES = [(1920, 1080), (1366, 768), (1280, 720)]
def panes(widget):
"""Direct children worth measuring: splitter panes and page-level boxes."""
from PySide6.QtWidgets import QSplitter
out = []
for sp in widget.findChildren(QSplitter):
for i in range(sp.count()):
w = sp.widget(i)
if w is not None and not w.isHidden():
out.append((f"{sp.objectName() or 'splitter'}[{i}] {type(w).__name__}", w))
return out
def main(argv) -> int:
sizes = SIZES
if len(argv) >= 2:
sizes = [(int(argv[i]), int(argv[i + 1])) for i in range(0, len(argv) - 1, 2)]
sandbox = _isolate_home()
from PySide6.QtWidgets import QApplication
app = QApplication([])
_load_fonts()
_freeze_schedulers()
from cowork_local.config import AppConfig, CONFIG_DIR
assert str(sandbox) in str(CONFIG_DIR), f"isolation failed: {CONFIG_DIR}"
from seed_demo_data import seed
seed()
from cowork_local.app import MainWindow
from cowork_local.i18n import set_language
from cowork_local.state import AppContext
from cowork_local.theme import set_active_theme, stylesheet
set_language("vi")
cfg = AppConfig.load()
set_active_theme(cfg.theme)
app.setStyleSheet(stylesheet(cfg.theme))
win = MainWindow(AppContext(cfg), user_name="local")
win.show()
for _ in range(6):
app.processEvents()
dests = [("Project", win._ROW_WORKSPACE, win.workspace._project_tab_idx),
("Cowork", win._ROW_WORKSPACE, win.workspace._cowork_tab_idx),
("Co4E", win._ROW_WORKSPACE, win.workspace._co4e_tab_idx),
("Folder", win._ROW_WORKSPACE, win.workspace._folder_tab_idx),
("GraphRAG", win._ROW_WORKSPACE, win.workspace._graphrag_tab_idx),
("Schedule", win._ROW_SCHEDULE, None),
("Dashboard", win._ROW_DASHBOARD, None),
("Monitoring", win._ROW_MONITORING, None)]
print(f"cua so: minimumSizeHint = {win.minimumSizeHint().width()}"
f"x{win.minimumSizeHint().height()}px")
print()
worst: dict[str, int] = {}
for w, h in sizes:
win.resize(w, h)
for _ in range(4):
app.processEvents()
print(f"=== {w}x{h} ===")
for name, page, sub in dests:
win._goto(page, sub)
for _ in range(4):
app.processEvents()
widget = win._page_widgets[page]
need = widget.minimumSizeHint().width()
have = widget.width()
tight = [(n, p.minimumSizeHint().width(), p.width())
for n, p in panes(widget)
if p.minimumSizeHint().width() > p.width() + 1]
flag = "" if need <= have else f" <-- THIEU {need - have}px"
print(f" {name:11} can {need:5}px · duoc {have:5}px{flag}")
for n, nd, hv in tight:
print(f" · {n:34} can {nd:4} duoc {hv:4}")
worst[f"{name}/{n}"] = max(worst.get(f"{name}/{n}", 0), nd - hv)
print()
if worst:
print("BO BO NHIEU NHAT:")
for k, v in sorted(worst.items(), key=lambda kv: -kv[1])[:12]:
print(f" {v:5}px {k}")
else:
print("KET QUA: khong pane nao bi bo o cac co da thu")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))