Files
yolocam-linux/yolocam-gui/yolocam_gui/ui/main_window.py
T
Seth Hillbrand 3cbc946565 Clean up GUI panels and fix sidebar icons
Rename the Stream panel to Output throughout the app,
menu, sidebar, and docs since the S3 does not support
network streaming. Remove the UVC toggle section from
the output panel and the recording section from the
console panel, along with all controller wiring for
both. Replace emoji sidebar icons for Color and Output
with Unicode geometric shapes that render correctly in
Qt. Wire the Help > Documentation menu action to open
the GitLab repository URL. Update the GUI guide to
match all panel and menu changes.
2026-02-15 13:34:52 -08:00

168 lines
5.8 KiB
Python

# 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 <https://www.gnu.org/licenses/>.
"""Main application window."""
import logging
from PySide6.QtCore import Qt, QTimer, QUrl
from PySide6.QtGui import QDesktopServices, QKeySequence, QShortcut
from PySide6.QtWidgets import (
QMainWindow, QWidget, QHBoxLayout, QScrollArea, QStackedWidget, QSizePolicy,
)
from .theme import COLOR_BG_PANEL, COLOR_BORDER
from .sidebar import Sidebar
from .video_widget import VideoWidget
from .panels import ImageParamsPanel, ColorPanel, ConsolePanel, StreamPanel, SettingsPanel
log = logging.getLogger(__name__)
class MainWindow(QMainWindow):
"""YoloCam main window with sidebar, stacked panels, and video feed."""
def __init__(self):
super().__init__()
self.setWindowTitle("YoloCam")
self.resize(1100, 570)
self._build_menu_bar()
self.statusBar().showMessage("Disconnected")
central = QWidget()
self.setCentralWidget(central)
root_layout = QHBoxLayout(central)
root_layout.setContentsMargins(0, 0, 0, 0)
root_layout.setSpacing(0)
self.sidebar = Sidebar()
self.sidebar.page_changed.connect(self._on_page_changed)
root_layout.addWidget(self.sidebar)
self.params_panel = ImageParamsPanel()
self.color_panel = ColorPanel()
self.console_panel = ConsolePanel()
self.stream_panel = StreamPanel()
self.settings_panel = SettingsPanel()
self._stacked = QStackedWidget()
self._panels = [
self.params_panel,
self.color_panel,
self.console_panel,
self.stream_panel,
self.settings_panel,
]
for panel in self._panels:
scroll = QScrollArea()
scroll.setWidget(panel)
scroll.setWidgetResizable(True)
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
scroll.setStyleSheet(f"""
QScrollArea {{ border-right: 1px solid {COLOR_BORDER}; background-color: {COLOR_BG_PANEL}; }}
""")
self._stacked.addWidget(scroll)
self._stacked.setFixedWidth(400)
root_layout.addWidget(self._stacked)
self.video_widget = VideoWidget(device_index=-1)
self.video_widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
root_layout.addWidget(self.video_widget, 1)
self._controller = None
def set_controller(self, controller):
"""Attach the CameraController after construction."""
self._controller = controller
controller.status_message.connect(self.statusBar().showMessage)
controller.connection_changed.connect(self._on_connection_changed)
QTimer.singleShot(500, controller.connect_camera)
def _build_menu_bar(self):
menu_bar = self.menuBar()
app_menu = menu_bar.addMenu("YoloCam")
self._connect_action = app_menu.addAction("Connect to Camera")
self._connect_action.setShortcut(QKeySequence("Ctrl+Shift+C"))
self._connect_action.triggered.connect(self._toggle_connection)
app_menu.addSeparator()
quit_action = app_menu.addAction("Quit")
quit_action.setShortcut(QKeySequence.StandardKey.Quit)
quit_action.triggered.connect(self.close)
view_menu = menu_bar.addMenu("View")
for i, (label, key) in enumerate([
("Camera", "1"), ("Color", "2"), ("Console", "3"),
("Output", "4"), ("Settings", "5"),
]):
action = view_menu.addAction(label)
action.setShortcut(QKeySequence(f"Ctrl+{key}"))
action.triggered.connect(lambda checked, idx=i: self._switch_panel(idx))
view_menu.addSeparator()
fullscreen_action = view_menu.addAction("Toggle Fullscreen")
fullscreen_action.setShortcut(QKeySequence.StandardKey.FullScreen)
fullscreen_action.triggered.connect(self._toggle_fullscreen)
help_menu = menu_bar.addMenu("Help")
doc_action = help_menu.addAction("Documentation")
doc_action.triggered.connect(
lambda: QDesktopServices.openUrl(QUrl("https://gitlab.com/sethhillbrand/yolocam-linux"))
)
def _switch_panel(self, index: int):
if 0 <= index < self._stacked.count():
self._stacked.setCurrentIndex(index)
self.sidebar.set_active(index)
def _toggle_fullscreen(self):
if self.isFullScreen():
self.showNormal()
else:
self.showFullScreen()
def _on_page_changed(self, index: int):
if 0 <= index < self._stacked.count():
self._stacked.setCurrentIndex(index)
def _toggle_connection(self):
if self._controller is None:
return
if self._controller.client.connection_state == "connected":
self._controller.disconnect_camera()
else:
self._controller.connect_camera()
def _on_connection_changed(self, state: str):
if state == "connected":
self._connect_action.setText("Disconnect")
else:
self._connect_action.setText("Connect to Camera")
def closeEvent(self, event):
if self._controller:
self._controller.disconnect_camera()
self.video_widget.stop()
super().closeEvent(event)