"""Builder for snapshot and storage actions section.""" from PyQt6.QtWidgets import ( QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit, QPushButton, QSizePolicy, QSpinBox, QVBoxLayout, ) from python_app.gui.controllers.sections.views import DataView, SectionView from python_app.models.gui_profile_schema import GuiStateModel def build_data_actions_group(gui: GuiStateModel) -> DataView: """Create snapshot save controls section.""" view = SectionView(QGroupBox("Data Actions")) group = view.group layout = QVBoxLayout(group) layout.setSpacing(8) data_defaults = gui.data_actions save_button = QPushButton("Save Last 1000") save_button.setToolTip("Save up to 1000 most recent measurements with all available data stages.") save_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) save_vna_json_button = QPushButton("Save S21 JSON") save_vna_json_button.setToolTip( "Export one S21 VNA-history JSON per combo from the preprocessed stage." ) save_vna_json_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) remove_last_button = QPushButton("Remove Last Measurement") remove_last_button.setProperty("role", "destructive") remove_last_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) capture_tmp_reference_button = QPushButton("Capture Temporary Reference") capture_tmp_reference_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) record_button = QPushButton("Start + Record to Disk") record_button.setToolTip( "Start the run (if stopped) and save the next N measurements to the path/name below." ) record_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) record_count = view.add("_record_count", QSpinBox()) record_count.setMinimum(1) record_count.setMaximum(1_000_000) record_count.setValue(int(data_defaults.record_count)) button_grid = QGridLayout() button_grid.setHorizontalSpacing(8) button_grid.setVerticalSpacing(8) button_grid.addWidget(save_button, 0, 0) button_grid.addWidget(save_vna_json_button, 0, 1) button_grid.addWidget(remove_last_button, 1, 0) button_grid.addWidget(capture_tmp_reference_button, 1, 1) button_grid.addWidget(record_button, 2, 0, 1, 2) button_grid.setColumnStretch(0, 1) button_grid.setColumnStretch(1, 1) layout.addLayout(button_grid) record_count_row = QHBoxLayout() record_count_row.setSpacing(8) record_count_row.addWidget(QLabel("Sweeps to record")) record_count_row.addWidget(record_count) record_count_row.addStretch(1) layout.addLayout(record_count_row) path_row = QHBoxLayout() path_row.setSpacing(8) save_path_input = view.add("_save_path_input", QLineEdit(str(data_defaults.save_path))) browse_button = QPushButton("Browse…") path_row.addWidget(QLabel("Path")) path_row.addWidget(save_path_input, stretch=1) path_row.addWidget(browse_button) layout.addLayout(path_row) name_row = QHBoxLayout() name_row.setSpacing(8) save_name_input = view.add("_save_name_input", QLineEdit(str(data_defaults.save_name))) name_row.addWidget(QLabel("Name")) name_row.addWidget(save_name_input, stretch=1) layout.addLayout(name_row) return DataView(group=group, fields=view.fields, save=save_button, save_json=save_vna_json_button, remove_last=remove_last_button, capture_tmp=capture_tmp_reference_button, record=record_button, browse=browse_button, save_path=save_path_input, save_name=save_name_input, record_count=record_count)