Skip to content

fix(live): defer zone overlay redraw + fix ROI naming ask_string - #436

Merged
MarkSant merged 3 commits into
mainfrom
claude/live-zone-overlay-defer-and-roi-askstring
Jul 23, 2026
Merged

fix(live): defer zone overlay redraw + fix ROI naming ask_string#436
MarkSant merged 3 commits into
mainfrom
claude/live-zone-overlay-defer-and-roi-askstring

Conversation

@MarkSant

Copy link
Copy Markdown
Owner

Follow-up de #433/#435 — dois erros no fluxo de definição de zonas de projeto LIVE.

Erro 1 — polígono não aparece após aceitar a detecção

Após aprovar a auto-detecção pela câmera, o frame e os botões de edição apareciam, mas o polígono só surgia ao dar duplo-clique no item "arena principal".

Causa raiz: display_roi_video_frame (disparado por UI_DISPLAY_VIDEO_FRAME dentro de run_live_calibration) agenda um repaint próprio do fundo via root.after(10, _draw_bg_image_to_canvas). O UI_REDRAW_ZONES síncrono do #435 desenhava o overlay primeiro, e esse repaint diferido do fundo apagava o polígono 10 ms depois.

Correção: deferir _refresh_zone_tab_after_live_detection via root.after(60, ...) (60 ms > 10 ms), para o redraw do overlay rodar depois do repaint do fundo. Sem Tk root (testes), cai no caminho síncrono.

Erro 2 — 'ApplicationGUI' object has no attribute 'ask_string'

Ao terminar o polígono principal e desenhar a primeira ROI, ROICompletionStrategy.complete chamava gui.ask_string(...) (com # type: ignore[attr-defined]), mas ask_string existe no DialogManager, não no ApplicationGUI.

Correção: gui.dialog_manager.ask_string(...), igual ao zone_editor.py. Testes atualizados para mockar o alvo correto.

Testes

  • test_single_video_workflow_auto_detect.py e test_polygon_drawing_service.py: 21 passed.
  • ruff ✅ · ruff format ✅ · mypy ✅ (via venv MAIN).

🤖 Generated with Claude Code

MarkSant and others added 2 commits July 23, 2026 19:21
Follow-up to #435. After approving live auto-detection, the polygon still
did not appear until the user double-clicked the "arena principal" item.

`display_roi_video_frame` (run via UI_DISPLAY_VIDEO_FRAME inside
run_live_calibration) schedules its own `root.after(10, _draw_bg_image_to_canvas)`
background repaint. The synchronous UI_REDRAW_ZONES from #435 drew the
overlay first, then that deferred bg repaint wiped it 10 ms later.

Fix: defer `_refresh_zone_tab_after_live_detection` via `root.after(60, ...)`
so the overlay redraw runs after the bg repaint. Falls back to a synchronous
call when no Tk root is available (unit tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drawing the first ROI raised "'ApplicationGUI' object has no attribute
'ask_string'": ROICompletionStrategy.complete called `gui.ask_string(...)`
(guarded by a `# type: ignore[attr-defined]`), but ask_string lives on
DialogManager. Route through `gui.dialog_manager.ask_string(...)`, matching
zone_editor.py. Tests updated to mock the correct target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 23, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Correção de dois regressos no fluxo de auto-detecção/edição de zonas em projetos LIVE: (1) overlay do polígono sendo “apagado” por um repaint diferido do frame após aprovação da detecção, e (2) chamada incorreta de ask_string no alvo errado durante a conclusão de ROI.

Changes:

  • Defere o refresh do overlay/lista de zonas após live auto-detect para ocorrer depois do repaint do background (via root.after(60, ...), com fallback síncrono em ambiente sem Tk root).
  • Corrige a coleta do nome da ROI para usar gui.dialog_manager.ask_string(...) (em vez de gui.ask_string(...)).
  • Atualiza testes para mockar o alvo correto (dialog_manager.ask_string).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/zebtrack/ui/components/single_video_workflow.py Defere o refresh do overlay/lista após live auto-detect para evitar que um repaint posterior do background apague o polígono.
src/zebtrack/ui/components/polygon_drawing_service.py Ajusta a coleta do nome da ROI para chamar ask_string via DialogManager (alvo correto).
tests/ui/components/test_polygon_drawing_service.py Atualiza mocks para refletir a mudança do alvo de ask_string (via dialog_manager).

Comment on lines +317 to +321
root = getattr(gui, "root", None)
if root is not None and hasattr(root, "after"):
# 60 ms > the 10 ms bg repaint scheduled by display_roi_video_frame.
root.after(60, _do_refresh)
else:
…stant

Addresses Copilot review on #436: the `root.after(60, ...)` in
_refresh_zone_tab_after_live_detection was a magic number coupled to the
`root.after(10, ...)` bg repaint inside display_roi_video_frame. If that 10 ms
changed, the overlay bug could silently return.

Extract `VideoFrameManager.BG_REPAINT_DELAY_MS` (used by the repaint itself)
and derive the refresh delay as `BG_REPAINT_DELAY_MS + 50`, so the two values
can no longer drift apart.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MarkSant
MarkSant merged commit 500b52f into main Jul 23, 2026
4 of 5 checks passed
@MarkSant
MarkSant deleted the claude/live-zone-overlay-defer-and-roi-askstring branch July 23, 2026 22:27
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/zebtrack/ui/components/single_video_workflow.py 66.66% 3 Missing ⚠️
...btrack/ui/components/canvas/video_frame_manager.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants