| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- """
- Mode Toggle Widget
- Toggle button widget for switching between modes (LIVE/FILE).
- """
- from PyQt5.QtWidgets import QWidget, QHBoxLayout, QPushButton
- from PyQt5.QtCore import Qt, pyqtSignal
- from PyQt5.QtGui import QFont
- class ModeToggle(QWidget):
- """
- Toggle widget for mode selection.
-
- Signals:
- mode_changed: Emitted when mode is changed (str: 'live' or 'file')
- """
-
- mode_changed = pyqtSignal(str)
-
- def __init__(self, parent=None):
- super().__init__(parent)
- self.current_mode = "file"
- self.init_ui()
-
- def init_ui(self):
- """Initialize the toggle UI."""
- layout = QHBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
-
- # Container style to resemble a switch/segment control
- self.setStyleSheet("""
- QWidget#ModeToggleRoot {
- background-color: #ecf0f1;
- border: 1px solid #bdc3c7;
- border-radius: 14px;
- }
- """)
- self.setObjectName("ModeToggleRoot")
-
- # LIVE button
- self.live_btn = QPushButton("LIVE")
- self.live_btn.setFont(QFont("Arial", 9))
- self.live_btn.setFixedSize(80, 28)
- self.live_btn.setCheckable(True)
- self.live_btn.clicked.connect(lambda: self.set_mode("live"))
- layout.addWidget(self.live_btn)
-
- # FILE button
- self.file_btn = QPushButton("FILE")
- self.file_btn.setFont(QFont("Arial", 9))
- self.file_btn.setFixedSize(80, 28)
- self.file_btn.setCheckable(True)
- self.file_btn.setChecked(True)
- self.file_btn.clicked.connect(lambda: self.set_mode("file"))
- layout.addWidget(self.file_btn)
-
- self._update_styles()
-
- # Disable LIVE mode initially (coming soon)
- self.live_btn.setEnabled(False)
- self.live_btn.setToolTip("Live audio streaming - Coming in future update")
-
- def set_mode(self, mode: str):
- """
- Set the current mode.
-
- Args:
- mode: 'live' or 'file'
- """
- self.current_mode = mode
- self.live_btn.setChecked(mode == "live")
- self.file_btn.setChecked(mode == "file")
- self._update_styles()
- self.mode_changed.emit(mode)
-
- def _update_styles(self):
- """Update button styles based on selection."""
- active_style = """
- QPushButton {{
- background-color: #3498db;
- border: none;
- border-radius: 14px;
- color: white;
- font-weight: bold;
- padding: 4px 10px;
- }}
- """
-
- inactive_style = """
- QPushButton {{
- background-color: transparent;
- border: none;
- border-radius: 14px;
- color: #2c3e50;
- padding: 4px 10px;
- }}
- QPushButton:hover {{
- background-color: #d5dbdb;
- }}
- """
-
- disabled_style = """
- QPushButton:disabled {{
- background-color: #95a5a6;
- border: 1px solid #7f8c8d;
- color: #ecf0f1;
- }}
- """
-
- self.live_btn.setStyleSheet(
- (active_style if self.current_mode == "live" else inactive_style) + disabled_style
- )
- self.file_btn.setStyleSheet(
- active_style if self.current_mode == "file" else inactive_style
- )
|