fix(tools): 5 checker UI hỏng sau đợt tách widget R08

`tools/` không đổi một byte nào giữa hai bản, nhưng 5 checker vẫn chết vì
chúng tìm control bằng `getattr(root, "ten")` trên đúng widget cũ — mà R08 đã
dời control xuống widget con.

Thêm ba helper dùng chung vào `capture_screens.py`:
  * `_own_member` — tên do app khai trên widget, không phải thừa kế từ Qt
  * `owner_of`   — widget thật sự đang giữ tên đó, duyệt theo bề rộng
  * `control`    — lấy control dù nó nằm ở cấp nào

`check_controls_alive` từ "MẤT 24 control" về 0, kèm liệt kê 22 control đã
đổi chỗ và 2 cái đổi tên. `check_probes_bite` từ 1/4 lên 6/6 phép cấy lỗi đều
bị bắt — phép cấy thứ hai trỏ vào `ui/schedule_task_tab.py` đã bị xoá, nay
trỏ vào `presentation/scheduling/kanban_board_widget.py`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-30 10:37:06 +09:00
co-authored by Claude Opus 5
parent e5c184ce07
commit 81b9482011
7 changed files with 378 additions and 262 deletions
+57
View File
@@ -37,6 +37,63 @@ OUT_DIR = REPO / "docs" / "screens"
THEMES = ("dark", "light")
def _own_member(widget, name: str) -> bool:
"""True when `name` is declared by the app on `widget`, not inherited from Qt.
Instance attributes live in ``vars(widget)``; methods live on the class, so
both are checked. Only classes defined inside ``cowork_local`` count, so a
Qt base class that happens to use the same name can never be mistaken for
the app's own control.
"""
if name in vars(widget):
return True
for base in type(widget).__mro__:
if getattr(base, "__module__", "").startswith("cowork_local") and name in vars(base):
return True
return False
def owner_of(root, name: str):
"""The widget in `root`'s subtree that actually holds `name` today.
EPIC R08 split every screen's god-widget into child widgets, so a control
that used to be ``tab.gran_combo`` now lives at ``tab.chart.gran_combo``,
and ``ScheduleTaskTab.columns`` moved to ``ScheduleTaskTab.kanban.columns``.
Checkers ask for a control by name and get back whichever widget owns it
today, so a further split does not break them again — while a control that
is genuinely gone still returns ``None`` and is still reported as a loss.
Breadth-first, so the shallowest owner wins if a name appears twice.
"""
from PySide6.QtWidgets import QWidget
seen: set[int] = set()
queue = [root]
while queue:
w = queue.pop(0)
if id(w) in seen:
continue
seen.add(id(w))
if _own_member(w, name):
return w
queue.extend(c for c in w.children() if isinstance(c, QWidget))
return None
def control(root, name: str, default=None):
"""The control named `name` anywhere in `root`'s subtree — see `owner_of`.
Falls back to a plain ``getattr`` on `root` so a screen that already bridges
its old attribute names itself keeps working: ``MonitoringTab.__getattr__``
maps ``ov_*`` onto the extracted tabs, and a name served that way is on no
widget's ``__dict__`` for `owner_of` to find.
"""
holder = owner_of(root, name)
if holder is not None:
return getattr(holder, name, default)
return getattr(root, name, default)
def _isolate_home() -> Path:
"""Copy the real config dir into a temp HOME and repoint the env at it."""
real = Path.home() / ".cowork_local"