# Copyright (C) 2026 Seth Hillbrand # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """Settings panel with device info and SD card management.""" from PySide6.QtCore import Signal from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QMessageBox from PySide6.QtGui import QFont from ..theme import COLOR_BG_PANEL, COLOR_TEXT_SECONDARY from ..widgets import CollapsibleSection class _DeviceInfoSection(CollapsibleSection): """Read-only device information display.""" def __init__(self, parent=None): super().__init__("Device Info", parent) self.firmware_label = QLabel("--") self.add_widget(self._info_row("Firmware", self.firmware_label)) self.serial_label = QLabel("--") self.add_widget(self._info_row("Serial Number", self.serial_label)) self.lens_label = QLabel("--") self.add_widget(self._info_row("Lens Info", self.lens_label)) def set_firmware_info(self, text: str): self.firmware_label.setText(text) def set_serial(self, text: str): self.serial_label.setText(text) def set_lens_info(self, text: str): self.lens_label.setText(text) @staticmethod def _info_row(label_text: str, value_label: QLabel) -> QWidget: row = QWidget() layout = QHBoxLayout(row) layout.setContentsMargins(0, 2, 0, 2) layout.setSpacing(8) lbl = QLabel(label_text) lbl.setFixedWidth(110) lbl.setStyleSheet(f"color: {COLOR_TEXT_SECONDARY};") layout.addWidget(lbl) layout.addWidget(value_label) layout.addStretch() return row class _SDCardSection(CollapsibleSection): """SD card storage info and format action.""" format_sd_requested = Signal() def __init__(self, parent=None): super().__init__("SD Card", parent) self.storage_label = QLabel("-- / -- MB") self.add_widget(self._info_row("Storage", self.storage_label)) self.format_btn = QPushButton("Format SD Card") self.format_btn.setProperty("accent", True) self.format_btn.setFixedHeight(32) self.format_btn.clicked.connect(self._confirm_format) self.add_widget(self.format_btn) def _confirm_format(self): result = QMessageBox.warning( self, "Format SD Card", "All data on the SD card will be erased. Continue?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No, ) if result == QMessageBox.StandardButton.Yes: self.format_sd_requested.emit() def set_disk_info(self, available: int, total: int): self.storage_label.setText(f"{available} / {total} MB") @staticmethod def _info_row(label_text: str, value_label: QLabel) -> QWidget: row = QWidget() layout = QHBoxLayout(row) layout.setContentsMargins(0, 2, 0, 2) layout.setSpacing(8) lbl = QLabel(label_text) lbl.setFixedWidth(110) lbl.setStyleSheet(f"color: {COLOR_TEXT_SECONDARY};") layout.addWidget(lbl) layout.addWidget(value_label) layout.addStretch() return row class SettingsPanel(QWidget): """Panel with device information and SD card management.""" param_changed = Signal(str, object) format_sd_requested = Signal() def __init__(self, parent=None): super().__init__(parent) self.setObjectName("settingsPanel") self.setStyleSheet(f"#settingsPanel {{ background-color: {COLOR_BG_PANEL}; }}") outer = QVBoxLayout(self) outer.setContentsMargins(0, 0, 0, 0) outer.setSpacing(0) header = QWidget() header.setFixedHeight(36) header_layout = QHBoxLayout(header) header_layout.setContentsMargins(12, 4, 12, 4) header_layout.setSpacing(8) title = QLabel("Settings") title_font = QFont() title_font.setBold(True) title_font.setPointSize(11) title.setFont(title_font) header_layout.addWidget(title) header_layout.addStretch() outer.addWidget(header) self.device_info = _DeviceInfoSection() outer.addWidget(self.device_info) self.sd_card = _SDCardSection() self.sd_card.format_sd_requested.connect(self.format_sd_requested.emit) outer.addWidget(self.sd_card) outer.addStretch() def set_firmware_info(self, text: str): self.device_info.set_firmware_info(text) def set_serial(self, text: str): self.device_info.set_serial(text) def set_lens_info(self, text: str): self.device_info.set_lens_info(text) def set_disk_info(self, available: int, total: int): self.sd_card.set_disk_info(available, total)