Files
radar_system/python_app/gui/window_view.py
T
2026-10-06 14:16:14 +03:00

98 lines
4.8 KiB
Python

"""Main-window layout and typed section views, without acquisition state."""
from pathlib import Path
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import (
QFileDialog, QFrame, QHBoxLayout, QLabel, QMainWindow,
QScrollArea, QToolButton, QVBoxLayout, QWidget,
)
from python_app.gui.controllers.history_controller import HistoryController
from python_app.gui.controllers.sections.data_actions_section import build_data_actions_group
from python_app.gui.controllers.sections.preprocess_summary_section import build_preprocess_summary_group
from python_app.gui.controllers.sections.primary_actions_section import build_primary_actions_group
from python_app.gui.controllers.sections.processing_section import build_processing_group
from python_app.gui.controllers.sections.radar_section import build_radar_group
from python_app.gui.controllers.sections.switch_section import build_switch_group
from python_app.models.gui_profile_schema import GuiStateModel
from python_app.models.run_config_schema import RunConfigModel
class WindowView:
def __init__(self, parent: QMainWindow, config: RunConfigModel, gui: GuiStateModel,
plot_stack: QWidget, log_panel: QWidget, *, project_root: Path) -> None:
self._parent = parent
self.root = QWidget(parent)
parent.setCentralWidget(self.root)
parent.setWindowTitle("Radar System Control")
layout = QHBoxLayout(self.root)
layout.setContentsMargins(12, 12, 12, 12)
layout.setSpacing(14)
layout.addWidget(plot_stack, stretch=11)
self._toggle = QToolButton()
self._toggle.setAutoRaise(True)
self._toggle.setArrowType(Qt.ArrowType.RightArrow)
self._toggle.setToolTip("Hide settings panel")
self._toggle.clicked.connect(self.toggle_settings)
layout.addWidget(self._toggle)
self.settings_panel = QWidget(self.root)
self.settings_panel.setMinimumWidth(610)
settings_layout = QVBoxLayout(self.settings_panel)
settings_layout.setContentsMargins(0, 0, 0, 0)
settings_layout.setSpacing(10)
self.processing = build_processing_group(config, gui)
self.primary = build_primary_actions_group(self.processing.mode)
settings_layout.addWidget(self.primary.group)
self.data = build_data_actions_group(gui)
self.switches = build_switch_group(config, gui)
self.preprocess = build_preprocess_summary_group()
self.radar = build_radar_group(config)
self.data.browse.clicked.connect(lambda: self.browse_save_path(project_root))
self.sections = (self.data, self.switches, self.preprocess, self.processing, self.radar)
controls = QWidget()
controls_layout = QVBoxLayout(controls)
controls_layout.setContentsMargins(0, 0, 12, 0)
controls_layout.setSpacing(10)
for section in self.sections:
controls_layout.addWidget(section.group)
controls_layout.addStretch(1)
scroll = QScrollArea(self.settings_panel)
scroll.setWidgetResizable(True)
scroll.setFrameShape(QFrame.Shape.NoFrame)
scroll.setWidget(controls)
settings_layout.addWidget(scroll, stretch=1)
self.status = QLabel("Status: idle")
self.status.setObjectName("statusLabel")
self.status.setWordWrap(True)
self._history = QLabel("History: raw=0, preprocessed=0, results=0")
self._history.setObjectName("hintLabel")
status_row = QHBoxLayout()
status_row.addWidget(self.status, stretch=1)
status_row.addWidget(self._history, alignment=Qt.AlignmentFlag.AlignRight)
settings_layout.addLayout(status_row)
settings_layout.addWidget(log_panel)
layout.addWidget(self.settings_panel, stretch=7)
parent.resize(1650, 940)
def toggle_settings(self) -> None:
visible = self.settings_panel.isHidden()
self.settings_panel.setVisible(visible)
self._toggle.setArrowType(Qt.ArrowType.RightArrow if visible else Qt.ArrowType.LeftArrow)
self._toggle.setToolTip("Hide settings panel" if visible else "Show settings panel")
def update_history(self, history: HistoryController) -> None:
self._history.setText(f"History: raw={len(history.raw)}, preprocessed={len(history.preprocessed)}, "
f"results={len(history.results)}")
def update_preprocess(self, selected: dict[str, str]) -> None:
for key, label in self.preprocess.labels.items():
label.setText(selected.get(key, "") or "<not selected>")
def browse_save_path(self, project_root: Path) -> None:
field = self.data.save_path
selected = QFileDialog.getExistingDirectory(self._parent, "Select Snapshot Directory",
field.text().strip() or str(project_root))
if selected:
field.setText(selected)