new GPR parameters and some UI fixes

This commit is contained in:
Ayzen
2026-04-07 12:55:26 +03:00
parent 4b78c2808d
commit 202993325d
27 changed files with 1494 additions and 168 deletions
@@ -15,6 +15,67 @@ from python_app.workflows.sequential_capture_workflow import SequentialCaptureSe
class AppWindowPreprocessMixin:
"""Handles preprocess set management and sequential capture workflows."""
@staticmethod
def _capture_log_entries_for_session(session: SequentialCaptureSession) -> list[str]:
"""Build capture-log rows from current session traces."""
display_name = preprocess_asset_display_name(session.kind)
total_count = session.state().total_count
entries: list[str] = []
for index, trace in enumerate(session.captured_traces(), start=1):
entries.append(
f"{display_name}: {index}/{total_count} | "
f"input={trace.combo.input_pos} output={trace.combo.output_pos}"
)
return entries
def _available_preprocess_sets_for_radar_key(self, radar_key: str) -> dict[str, list[str]]:
"""Load available preprocess-set names for one radar key."""
return {
key: self._store.list_sets(PREPROCESS_ASSET_SPECS[key].set_kind, radar_key)
for key in VISIBLE_PREPROCESS_ASSET_KEYS
}
def _reset_preprocess_selection_after_radar_key_change(self) -> None:
"""Clear selected preprocess sets when radar-key-defining settings change."""
try:
radar_key = self._radar_key_from_ui()
except Exception:
return
previous_radar_key = getattr(self, "_selected_preprocess_radar_key", radar_key)
if radar_key == previous_radar_key:
return
self._selected_preprocess_radar_key = radar_key
cleared = {
key: value
for key, value in self._selected_preprocess_sets.items()
if value
}
if not cleared:
if self._preprocess_dialog is not None:
self._refresh_sets()
return
self._selected_preprocess_sets = {
key: ""
for key in VISIBLE_PREPROCESS_ASSET_KEYS
}
self._refresh_preprocess_summary_labels()
if self._preprocess_dialog is not None:
self._preprocess_dialog.set_selected_sets(self._selected_preprocess_sets, emit_signal=False)
self._refresh_sets()
cleared_summary = ", ".join(
f"{preprocess_asset_display_name(key)}={value}"
for key, value in cleared.items()
)
self._log(
"Preprocess selection reset after radar settings changed: "
f"{previous_radar_key} -> {radar_key}; cleared {cleared_summary}"
)
def _open_preprocess_panel(self) -> None:
"""Open preprocessing dialog and refresh available sets."""
dialog = self._ensure_preprocess_dialog()
@@ -42,6 +103,9 @@ class AppWindowPreprocessMixin:
dialog.selection_changed.connect(self._on_preprocess_selection_changed)
dialog.start_sequence_requested.connect(self._start_capture_sequence)
dialog.capture_next_requested.connect(self._capture_next_combo)
dialog.capture_all_requested.connect(self._capture_all_remaining)
dialog.undo_last_requested.connect(self._undo_last_capture)
dialog.finalize_sequence_requested.connect(self._finalize_capture_sequence)
dialog.abort_sequence_requested.connect(self._abort_capture_sequence)
self._update_capture_dialog_state()
return dialog
@@ -72,14 +136,11 @@ class AppWindowPreprocessMixin:
def _refresh_sets(self) -> None:
"""Refresh preprocess set lists for current radar key."""
config = self._build_config()
radar_key = self._radar_key(config)
radar_key = self._radar_key_from_ui()
self._selected_preprocess_radar_key = radar_key
dialog = self._ensure_preprocess_dialog()
available_sets = {
key: self._store.list_sets(PREPROCESS_ASSET_SPECS[key].set_kind, radar_key)
for key in VISIBLE_PREPROCESS_ASSET_KEYS
}
available_sets = self._available_preprocess_sets_for_radar_key(radar_key)
dialog.set_available_sets(available_sets)
unavailable_selections: list[str] = []
@@ -137,7 +198,9 @@ class AppWindowPreprocessMixin:
self._capture_session = session
dialog.clear_capture_log()
dialog.reset_preview()
dialog.set_status(f"{display_name} sequence started")
self._clear_trace_plots()
self._update_capture_dialog_state()
self._log(
f"{display_name} sequence started: set={set_name}, radar_key={radar_key}, "
@@ -155,47 +218,134 @@ class AppWindowPreprocessMixin:
self._show_error("No active capture sequence")
return
dialog = self._ensure_preprocess_dialog()
try:
trace = session.capture_current_combo()
self._record_preprocess_capture(session, trace)
except Exception as exc: # noqa: BLE001
self._show_exception("Failed to capture preprocess combo", exc)
self._abort_capture_sequence()
def _capture_all_remaining(self) -> None:
"""Capture all remaining combos for the active preprocess session."""
session = self._capture_session
if session is None:
self._show_error("No active capture sequence")
return
if session.is_complete():
self._show_error(
"Capture sequence is already complete",
details=self._capture_state_details(),
)
return
display_name = preprocess_asset_display_name(session.kind)
dialog = self._ensure_preprocess_dialog()
dialog.set_status(f"{display_name} batch capture started")
self._log(
f"{display_name} batch capture started: remaining="
f"{session.state().total_count - session.state().captured_count}"
)
try:
while not session.is_complete():
trace = session.capture_current_combo()
self._record_preprocess_capture(session, trace)
except Exception as exc: # noqa: BLE001
self._show_exception("Failed to capture preprocess combo", exc)
self._abort_capture_sequence()
def _record_preprocess_capture(self, session: SequentialCaptureSession, trace) -> None:
"""Update UI, preview, and logs after one successful preprocess capture."""
dialog = self._ensure_preprocess_dialog()
state = session.state()
display_name = preprocess_asset_display_name(session.kind)
channel = preprocess_asset_channel(session.kind)
dialog.append_capture_log_entry(
kind=display_name,
captured_count=state.captured_count,
total_count=state.total_count,
input_pos=trace.combo.input_pos,
output_pos=trace.combo.output_pos,
)
dialog.draw_last_trace(trace, title=f"{display_name} captured", channel=channel)
self._draw_single_trace(trace, title=f"{display_name} last trace", channel=channel)
self._log(
f"{display_name} capture: {state.captured_count}/{state.total_count} | "
f"input={trace.combo.input_pos} output={trace.combo.output_pos}"
)
self._update_capture_dialog_state()
if session.is_complete():
dialog.set_status(f"{display_name} sequence complete. Review captures or save the set.")
self._log(
f"{display_name} sequence capture complete: "
f"{state.captured_count}/{state.total_count}; waiting for save or undo"
)
def _undo_last_capture(self) -> None:
"""Remove the most recently captured combo and rewind capture cursor."""
session = self._capture_session
if session is None:
self._show_error("No active capture sequence")
return
dialog = self._ensure_preprocess_dialog()
try:
removed_trace = session.undo_last_capture()
state = session.state()
display_name = preprocess_asset_display_name(session.kind)
channel = preprocess_asset_channel(session.kind)
dialog.append_capture_log_entry(
kind=display_name,
captured_count=state.captured_count,
total_count=state.total_count,
input_pos=trace.combo.input_pos,
output_pos=trace.combo.output_pos,
)
dialog.draw_last_trace(trace, title=f"{display_name} captured", channel=channel)
self._draw_single_trace(trace, title=f"{display_name} last trace", channel=channel)
self._log(
f"{display_name} capture: {state.captured_count}/{state.total_count} | "
f"input={trace.combo.input_pos} output={trace.combo.output_pos}"
)
if session.is_complete():
radar_key, collection = session.finalize(self._store)
set_name = session.set_name
kind = session.kind
display_name = preprocess_asset_display_name(kind)
self._cleanup_capture_session()
self._selected_preprocess_sets[kind] = set_name
self._refresh_sets()
dialog.set_status(f"{display_name} set saved: {set_name} ({len(collection.traces)} traces)")
self._log(f"{display_name} sequence completed and saved: set={set_name}, key={radar_key}")
self._resume_pipeline_if_needed()
dialog.set_capture_log_entries(self._capture_log_entries_for_session(session))
last_trace = session.last_captured_trace()
if last_trace is None:
dialog.reset_preview()
dialog.set_status(f"{display_name} last capture removed. No captured combos remain.")
self._clear_trace_plots()
else:
self._update_capture_dialog_state()
dialog.draw_last_trace(last_trace, title=f"{display_name} last trace", channel=channel)
dialog.set_status(f"{display_name} last capture removed. Ready to recapture.")
self._draw_single_trace(last_trace, title=f"{display_name} last trace", channel=channel)
self._update_capture_dialog_state()
self._log(
f"{display_name} undo last capture: removed input={removed_trace.combo.input_pos} "
f"output={removed_trace.combo.output_pos}; remaining={state.captured_count}/{state.total_count}"
)
except Exception as exc: # noqa: BLE001
self._show_exception("Failed to capture preprocess combo", exc)
self._abort_capture_sequence()
self._show_exception("Failed to undo last preprocess capture", exc)
def _finalize_capture_sequence(self) -> None:
"""Persist completed capture session into preprocess-set storage."""
session = self._capture_session
if session is None:
self._show_error("No active capture sequence")
return
if not session.is_complete():
self._show_error(
"Capture sequence is not complete",
details=(
f"Captured {session.state().captured_count}/{session.state().total_count} combos. "
"Finish the remaining captures before saving."
),
)
return
dialog = self._ensure_preprocess_dialog()
try:
radar_key, collection = session.finalize(self._store)
set_name = session.set_name
kind = session.kind
display_name = preprocess_asset_display_name(kind)
self._cleanup_capture_session()
self._selected_preprocess_sets[kind] = set_name
self._refresh_sets()
dialog.set_status(f"{display_name} set saved: {set_name} ({len(collection.traces)} traces)")
self._log(f"{display_name} sequence completed and saved: set={set_name}, key={radar_key}")
self._resume_pipeline_if_needed()
except Exception as exc: # noqa: BLE001
self._show_exception("Failed to save preprocess set", exc)
def _abort_capture_sequence(self, *, resume_pipeline: bool = True) -> None:
"""Abort active capture session and optionally resume pipeline."""
@@ -222,6 +372,9 @@ class AppWindowPreprocessMixin:
total_count=0,
next_input=None,
next_output=None,
can_undo=False,
can_finalize=False,
can_capture_all=False,
)
return
@@ -238,6 +391,9 @@ class AppWindowPreprocessMixin:
total_count=state.total_count,
next_input=next_input,
next_output=next_output,
can_undo=state.can_undo,
can_finalize=state.is_complete,
can_capture_all=(not state.is_complete and state.current_combo is not None),
)
def _cleanup_capture_session(self) -> None: