Files
gti_radiostudio/top_bar_widget.py
T

166 lines
5.0 KiB
Python
Raw Normal View History

2026-04-29 16:21:44 +10:00
# top_bar_widget.py
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QPushButton
from PySide6.QtCore import Qt, QTimer, Signal
from PySide6.QtGui import QFont
from datetime import datetime
# ─────────────────────────────────────────
# THEMES
# ─────────────────────────────────────────
THEMES = [
{
'name': 'GREEN',
'accent': '#00ff41',
'accent_dim': '#00aa2a',
'bg': '#0d0d0d',
'bg2': '#111111',
'border': '#1a3a1a',
'text': '#cccccc',
},
{
'name': 'AMBER',
'accent': '#ffaa00',
'accent_dim': '#cc8800',
'bg': '#0d0d00',
'bg2': '#111100',
'border': '#3a3000',
'text': '#ddddcc',
},
{
'name': 'BLUE',
'accent': '#00aaff',
'accent_dim': '#0077cc',
'bg': '#00080d',
'bg2': '#001122',
'border': '#001a3a',
'text': '#ccd8dd',
},
{
'name': 'RED',
'accent': '#ff4444',
'accent_dim': '#cc2222',
'bg': '#0d0000',
'bg2': '#110000',
'border': '#3a0000',
'text': '#ddcccc',
},
]
class TopBarWidget(QFrame):
theme_changed = Signal(dict)
def __init__(self, parent=None):
super().__init__(parent)
self._theme_index = 0
self.setFrameStyle(QFrame.Box | QFrame.Raised)
self.setFixedHeight(80)
self._apply_bar_style()
self._build_ui()
self.timer = QTimer(self)
self.timer.setInterval(1000)
self.timer.timeout.connect(self._update)
self.timer.start()
self._update()
def _apply_bar_style(self):
theme = THEMES[self._theme_index]
self.setStyleSheet(f"""
QFrame {{
background-color: {theme['bg2']};
border: 2px solid {theme['border']};
border-radius: 6px;
}}
""")
def _build_ui(self):
layout = QHBoxLayout(self)
layout.setContentsMargins(20, 8, 20, 8)
layout.setSpacing(12)
# Theme cycle button
self.theme_btn = QPushButton("◈")
self.theme_btn.setFixedSize(40, 40)
self.theme_btn.setFont(QFont("Arial", 16, QFont.Bold))
self.theme_btn.setToolTip("Cycle colour theme")
self.theme_btn.clicked.connect(self._cycle_theme)
self._style_theme_btn()
layout.addWidget(self.theme_btn)
# Station name
self.station_label = QLabel("RADIO PANEL")
self.station_label.setFont(QFont("Arial", 16, QFont.Bold))
self.station_label.setStyleSheet(
"color: #444444; background: transparent; border: none;"
)
self.station_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
layout.addWidget(self.station_label)
layout.addStretch()
# Date
self.date_label = QLabel("")
self.date_label.setFont(QFont("Arial", 20, QFont.Bold))
self.date_label.setStyleSheet(
"color: #aaaaaa; background: transparent; border: none;"
)
self.date_label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
layout.addWidget(self.date_label)
layout.addStretch()
# Clock
self.clock_label = QLabel("")
self.clock_label.setFont(QFont("Courier New", 42, QFont.Bold))
self.clock_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.clock_label.setMinimumWidth(220)
self._style_clock()
layout.addWidget(self.clock_label)
def _style_theme_btn(self):
theme = THEMES[self._theme_index]
self.theme_btn.setStyleSheet(f"""
QPushButton {{
background-color: transparent;
color: {theme['accent']};
border: 2px solid {theme['accent']};
border-radius: 20px;
}}
QPushButton:hover {{
background-color: {theme['accent']};
color: #000000;
}}
QPushButton:pressed {{
background-color: {theme['accent_dim']};
}}
""")
def _style_clock(self):
theme = THEMES[self._theme_index]
self.clock_label.setStyleSheet(
f"color: {theme['accent']}; background: transparent; border: none;"
)
def _cycle_theme(self):
self._theme_index = (self._theme_index + 1) % len(THEMES)
self._apply_bar_style()
self._style_theme_btn()
self._style_clock()
self.theme_changed.emit(THEMES[self._theme_index])
def _update(self):
now = datetime.now()
self.clock_label.setText(now.strftime("%H:%M:%S"))
self.date_label.setText(now.strftime("%A %d %B %Y"))
@property
def current_theme(self) -> dict:
return THEMES[self._theme_index]