# 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 . """Left icon sidebar for navigation.""" from PySide6.QtCore import Qt, Signal from PySide6.QtWidgets import QWidget, QVBoxLayout, QToolButton, QSizePolicy from PySide6.QtGui import QFont from .theme import COLOR_BG_SIDEBAR, COLOR_BORDER class Sidebar(QWidget): """48px-wide vertical icon sidebar.""" page_changed = Signal(int) ICONS = [ ("\u2699", "Parameters"), ("\u25D0", "Color"), ("\u2328", "Console"), ("\u25B6", "Output"), ("\u2638", "Settings"), ] def __init__(self, parent=None): super().__init__(parent) self.setFixedWidth(48) self.setObjectName("sidebar") self.setStyleSheet(f""" #sidebar {{ background-color: {COLOR_BG_SIDEBAR}; border-right: 1px solid {COLOR_BORDER}; }} """) layout = QVBoxLayout(self) layout.setContentsMargins(0, 8, 0, 8) layout.setSpacing(4) layout.setAlignment(Qt.AlignmentFlag.AlignTop) self._buttons: list[QToolButton] = [] icon_font = QFont() icon_font.setPointSize(16) for i, (icon, tooltip) in enumerate(self.ICONS): btn = QToolButton() btn.setText(icon) btn.setFont(icon_font) btn.setToolTip(tooltip) btn.setCheckable(True) btn.setFixedSize(40, 40) btn.clicked.connect(lambda checked, idx=i: self._on_click(idx)) self._buttons.append(btn) layout.addWidget(btn, alignment=Qt.AlignmentFlag.AlignCenter) layout.addStretch() if self._buttons: self._buttons[0].setChecked(True) def set_active(self, index: int): """Set the active button without emitting page_changed.""" for i, btn in enumerate(self._buttons): btn.setChecked(i == index) def _on_click(self, index: int): self.set_active(index) self.page_changed.emit(index)