Skip to content

Model Handler

app.ui.handlers.model_handler

View source code

Detection model management handler for asynchronous model loading.

See Also

Layer: Presentation. Context: Converts user actions and worker signals into application calls and UI feedback.

ModelHandler

Bases: QObject

Manages asynchronous detection model loading and switching.

Responsibilities
  • Handle model selection changes via UI dropdown.
  • Manage model load worker thread lifecycle.
  • Show model loading view_state in UI.
  • Handle model load success and failure cases.
  • Orchestrate proper thread cleanup to prevent memory leaks.
Note

Uses ModelLoadWorker in separate QThread to prevent UI blocking. Must follow strict thread teardown sequence (quit → wait → deleteLater). Worker is parentless (required by moveToThread() in Qt). Cannot modify objects across thread boundaries.

Signal flow: Receives model_changed signal from right panel dropdown. Emits worker finished/failed signals to update UI. Triggers frame re-render after successful model load.

Layer: Presentation. Context: Supports user interaction and delegates application work through presentation contracts.

__init__(controller: UIController) -> None

controller: UIController supplying model-selection actions, the active window, and worker completion callbacks.

close() -> None

Close close.

on_model_changed(model_name: str) -> None

Handle detection model change from UI dropdown.

Note

Triggered by right panel model_changed signal with model name.

Flow: on_model_changed(model_name) [this slot] ├── Validate session is selected ├── Show confirmation dialog (unless dismissed via checkbox) ├── Update session settings with new model name └──> Start asynchronous model load worker

Key Behaviors: Validates that a session is active (model can only load with active session). Shows warning dialog unless user checks "Don't ask again". Reverts dropdown if user cancels dialog. Starts ModelLoadWorker in separate thread (non-blocking).

on_model_load_failed(s_id: SessionId, model_name: str, err: str) -> None

Handle model load failure from worker thread.

Note

Triggered by ModelLoadWorker.failed signal.

Action: Display error dialog to user and update status bar.

Downstream: None (leaf node — error display only).

on_model_load_finished(s_id: SessionId, model_name: str) -> None

Handle successful completion of model load in worker thread.

Note

Triggered by ModelLoadWorker.finished signal.

Flow: on_model_load_finished(s_id, model_name) [this slot] ├── Clear detection boxes from UI tab ├── Update status bar with model info └──> Render frame (ready for new detections)

Downstream: None (leaf node — updates UI only).