mode_toggle.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. """
  2. Mode Toggle Widget
  3. Toggle button widget for switching between modes (LIVE/FILE).
  4. """
  5. from PyQt5.QtWidgets import QWidget, QHBoxLayout, QPushButton
  6. from PyQt5.QtCore import Qt, pyqtSignal
  7. from PyQt5.QtGui import QFont
  8. class ModeToggle(QWidget):
  9. """
  10. Toggle widget for mode selection.
  11. Signals:
  12. mode_changed: Emitted when mode is changed (str: 'live' or 'file')
  13. """
  14. mode_changed = pyqtSignal(str)
  15. def __init__(self, parent=None):
  16. super().__init__(parent)
  17. self.current_mode = "file"
  18. self.init_ui()
  19. def init_ui(self):
  20. """Initialize the toggle UI."""
  21. layout = QHBoxLayout(self)
  22. layout.setContentsMargins(0, 0, 0, 0)
  23. layout.setSpacing(0)
  24. # Container style to resemble a switch/segment control
  25. self.setStyleSheet("""
  26. QWidget#ModeToggleRoot {
  27. background-color: #ecf0f1;
  28. border: 1px solid #bdc3c7;
  29. border-radius: 14px;
  30. }
  31. """)
  32. self.setObjectName("ModeToggleRoot")
  33. # LIVE button
  34. self.live_btn = QPushButton("LIVE")
  35. self.live_btn.setFont(QFont("Arial", 9))
  36. self.live_btn.setFixedSize(80, 28)
  37. self.live_btn.setCheckable(True)
  38. self.live_btn.clicked.connect(lambda: self.set_mode("live"))
  39. layout.addWidget(self.live_btn)
  40. # FILE button
  41. self.file_btn = QPushButton("FILE")
  42. self.file_btn.setFont(QFont("Arial", 9))
  43. self.file_btn.setFixedSize(80, 28)
  44. self.file_btn.setCheckable(True)
  45. self.file_btn.setChecked(True)
  46. self.file_btn.clicked.connect(lambda: self.set_mode("file"))
  47. layout.addWidget(self.file_btn)
  48. self._update_styles()
  49. # Disable LIVE mode initially (coming soon)
  50. self.live_btn.setEnabled(False)
  51. self.live_btn.setToolTip("Live audio streaming - Coming in future update")
  52. def set_mode(self, mode: str):
  53. """
  54. Set the current mode.
  55. Args:
  56. mode: 'live' or 'file'
  57. """
  58. self.current_mode = mode
  59. self.live_btn.setChecked(mode == "live")
  60. self.file_btn.setChecked(mode == "file")
  61. self._update_styles()
  62. self.mode_changed.emit(mode)
  63. def _update_styles(self):
  64. """Update button styles based on selection."""
  65. active_style = """
  66. QPushButton {{
  67. background-color: #3498db;
  68. border: none;
  69. border-radius: 14px;
  70. color: white;
  71. font-weight: bold;
  72. padding: 4px 10px;
  73. }}
  74. """
  75. inactive_style = """
  76. QPushButton {{
  77. background-color: transparent;
  78. border: none;
  79. border-radius: 14px;
  80. color: #2c3e50;
  81. padding: 4px 10px;
  82. }}
  83. QPushButton:hover {{
  84. background-color: #d5dbdb;
  85. }}
  86. """
  87. disabled_style = """
  88. QPushButton:disabled {{
  89. background-color: #95a5a6;
  90. border: 1px solid #7f8c8d;
  91. color: #ecf0f1;
  92. }}
  93. """
  94. self.live_btn.setStyleSheet(
  95. (active_style if self.current_mode == "live" else inactive_style) + disabled_style
  96. )
  97. self.file_btn.setStyleSheet(
  98. active_style if self.current_mode == "file" else inactive_style
  99. )