fullscreen_timer_widget.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """Fullscreen timer widget optimized for large display."""
  2. from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QFrame
  3. from PyQt6.QtCore import Qt
  4. from PyQt6.QtGui import QFont
  5. class FullscreenTimerWidget(QFrame):
  6. def __init__(self, timer_model):
  7. super().__init__()
  8. self.timer_model = timer_model
  9. self.remaining_seconds = timer_model.duration
  10. self.is_paused = False
  11. self.time_font_size = 120
  12. self.title_font_size = 40
  13. self.init_ui()
  14. def init_ui(self):
  15. # Frame styling with border between timers
  16. self.setStyleSheet(f"""
  17. QFrame {{
  18. background-color: {self.timer_model.bg_color};
  19. border-bottom: 3px solid #333333;
  20. }}
  21. """)
  22. # Main layout
  23. layout = QVBoxLayout(self)
  24. layout.setContentsMargins(40, 40, 40, 40)
  25. # Timer title
  26. self.title_label = QLabel(self.timer_model.name)
  27. self.title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
  28. self.title_label.setStyleSheet(f"color: {self.timer_model.text_color}; border: none;")
  29. self.title_label.setWordWrap(True)
  30. self.title_font = QFont("Arial", self.title_font_size, QFont.Weight.Bold)
  31. self.title_label.setFont(self.title_font)
  32. layout.addWidget(self.title_label, stretch=1)
  33. # Timer display
  34. self.time_label = QLabel(self.format_time(self.remaining_seconds))
  35. self.time_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
  36. self.time_label.setStyleSheet(f"color: {self.timer_model.text_color}; border: none;")
  37. self.time_font = QFont("Arial", self.time_font_size, QFont.Weight.Bold)
  38. self.time_label.setFont(self.time_font)
  39. layout.addWidget(self.time_label, stretch=3)
  40. # Pause indicator (optional, shown when paused)
  41. self.pause_indicator = QLabel("⏸ PAUSED")
  42. self.pause_indicator.setAlignment(Qt.AlignmentFlag.AlignCenter)
  43. self.pause_indicator.setStyleSheet(f"color: {self.timer_model.text_color}; border: none;")
  44. pause_font = QFont("Arial", 24, QFont.Weight.Bold)
  45. self.pause_indicator.setFont(pause_font)
  46. self.pause_indicator.hide()
  47. layout.addWidget(self.pause_indicator)
  48. def format_time(self, seconds):
  49. hours = seconds // 3600
  50. minutes = (seconds % 3600) // 60
  51. secs = seconds % 60
  52. if hours > 0:
  53. return f"{hours:02d}:{minutes:02d}:{secs:02d}"
  54. else:
  55. return f"{minutes:02d}:{secs:02d}"
  56. def sync_with(self, source_widget):
  57. """Sync this mirror widget with the source widget."""
  58. self.remaining_seconds = source_widget.remaining_seconds
  59. self.is_paused = source_widget.is_paused
  60. self.time_label.setText(self.format_time(self.remaining_seconds))
  61. if self.is_paused:
  62. self.pause_indicator.show()
  63. else:
  64. self.pause_indicator.hide()
  65. def update_display(self, remaining_seconds):
  66. """Update the display with new time (for mirror widgets)."""
  67. self.remaining_seconds = remaining_seconds
  68. if remaining_seconds <= 0:
  69. self.time_label.setText("TIME'S UP!")
  70. else:
  71. self.time_label.setText(self.format_time(remaining_seconds))
  72. def update_state(self, is_paused):
  73. """Update the paused state (for mirror widgets)."""
  74. self.is_paused = is_paused
  75. if is_paused:
  76. self.pause_indicator.show()
  77. else:
  78. self.pause_indicator.hide()
  79. def update_font_sizes(self, time_size, title_size):
  80. """Update font sizes based on number of timers."""
  81. self.time_font_size = time_size
  82. self.title_font_size = title_size
  83. self.time_font.setPointSize(time_size)
  84. self.time_label.setFont(self.time_font)
  85. self.title_font.setPointSize(title_size)
  86. self.title_label.setFont(self.title_font)