quality_thermal_panel.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. """
  2. Thermal Analysis Panel
  3. Panel for displaying thermal camera data and temperature analysis.
  4. Currently shows offline status with thermal gradient mockup.
  5. """
  6. from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy
  7. from PyQt5.QtCore import Qt, QTimer
  8. from PyQt5.QtGui import QFont, QPixmap, QImage, QPainter, QColor, QPen, QBrush, QLinearGradient, QRadialGradient
  9. from ui.widgets.panel_header import PanelHeader
  10. from ui.widgets.coming_soon_overlay import ComingSoonOverlay
  11. class QualityThermalPanel(QWidget):
  12. """
  13. Panel for thermal analysis display.
  14. Shows thermal gradient visualization with offline status.
  15. """
  16. def __init__(self, parent=None):
  17. super().__init__(parent)
  18. self.current_temperature = 28.5
  19. self.temperature_range = (22.0, 32.0)
  20. self.init_ui()
  21. def init_ui(self):
  22. """Initialize the panel UI."""
  23. # Set size policy to expand equally
  24. self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
  25. layout = QVBoxLayout(self)
  26. layout.setContentsMargins(0, 0, 0, 0)
  27. layout.setSpacing(0)
  28. # Main panel container with card styling
  29. self.setStyleSheet("""
  30. QWidget {
  31. background-color: white;
  32. border: 1px solid #ddd;
  33. }
  34. """)
  35. # Header using the PanelHeader widget
  36. header = PanelHeader(
  37. title="Thermal Analysis",
  38. color="#e67e22" # Orange for thermal
  39. )
  40. layout.addWidget(header)
  41. # Content area
  42. content = QWidget()
  43. content.setStyleSheet("""
  44. background-color: #2c3e50;
  45. border: 1px solid #34495e;
  46. border-top: none;
  47. """)
  48. content_layout = QVBoxLayout(content)
  49. content_layout.setContentsMargins(10, 10, 10, 10)
  50. content_layout.setAlignment(Qt.AlignCenter)
  51. content_layout.setSpacing(5)
  52. # Thermal visualization area
  53. self.thermal_display = ThermalVisualizationWidget()
  54. self.thermal_display.setMinimumSize(200, 150)
  55. content_layout.addWidget(self.thermal_display)
  56. # Temperature info
  57. temp_widget = QWidget()
  58. temp_layout = QVBoxLayout(temp_widget)
  59. temp_layout.setContentsMargins(0, 5, 0, 0)
  60. temp_layout.setSpacing(2)
  61. # Current temperature reading
  62. self.temp_label = QLabel(f"{self.current_temperature}°C")
  63. self.temp_label.setFont(QFont("Arial", 16, QFont.Bold))
  64. self.temp_label.setStyleSheet("color: #f39c12;")
  65. self.temp_label.setAlignment(Qt.AlignCenter)
  66. temp_layout.addWidget(self.temp_label)
  67. # Temperature scale label
  68. scale_label = QLabel("Temperature Range:")
  69. scale_label.setFont(QFont("Arial", 10))
  70. scale_label.setStyleSheet("color: #bdc3c7;")
  71. scale_label.setAlignment(Qt.AlignCenter)
  72. temp_layout.addWidget(scale_label)
  73. # Temperature scale widget
  74. self.scale_widget = TemperatureScaleWidget(self.temperature_range)
  75. self.scale_widget.setFixedHeight(20)
  76. temp_layout.addWidget(self.scale_widget)
  77. # Min/Max labels
  78. minmax_widget = QWidget()
  79. minmax_layout = QHBoxLayout(minmax_widget)
  80. minmax_layout.setContentsMargins(0, 0, 0, 0)
  81. min_label = QLabel(f"{self.temperature_range[0]}°C")
  82. min_label.setFont(QFont("Arial", 9))
  83. min_label.setStyleSheet("color: #7f8c8d;")
  84. max_label = QLabel(f"{self.temperature_range[1]}°C")
  85. max_label.setFont(QFont("Arial", 9))
  86. max_label.setStyleSheet("color: #7f8c8d;")
  87. minmax_layout.addWidget(min_label)
  88. minmax_layout.addStretch()
  89. minmax_layout.addWidget(max_label)
  90. temp_layout.addWidget(minmax_widget)
  91. # Offline status
  92. offline_label = QLabel("🔴 OFFLINE")
  93. offline_label.setFont(QFont("Arial", 9))
  94. offline_label.setStyleSheet("color: #e74c3c; font-weight: bold;")
  95. offline_label.setAlignment(Qt.AlignCenter)
  96. temp_layout.addWidget(offline_label)
  97. content_layout.addWidget(temp_widget)
  98. layout.addWidget(content, 1)
  99. def update_temperature(self, temperature):
  100. """Update current temperature reading."""
  101. self.current_temperature = temperature
  102. self.temp_label.setText(f"{temperature}°C")
  103. self.thermal_display.update_temperature(temperature)
  104. self.update()
  105. def set_temperature_range(self, min_temp, max_temp):
  106. """Set temperature range for the scale."""
  107. self.temperature_range = (min_temp, max_temp)
  108. self.scale_widget.update_range(min_temp, max_temp)
  109. class ThermalVisualizationWidget(QWidget):
  110. """Widget showing thermal gradient visualization."""
  111. def __init__(self, parent=None):
  112. super().__init__(parent)
  113. self.temperature = 28.5
  114. self.setAttribute(Qt.WA_StyledBackground, True)
  115. def update_temperature(self, temperature):
  116. """Update temperature for visualization."""
  117. self.temperature = temperature
  118. self.update()
  119. def paintEvent(self, event):
  120. """Custom paint event to draw thermal gradient."""
  121. painter = QPainter(self)
  122. painter.setRenderHint(QPainter.Antialiasing)
  123. # Get widget dimensions
  124. width = self.width()
  125. height = self.height()
  126. # Draw background
  127. painter.fillRect(0, 0, width, height, QColor("#000000"))
  128. # Create thermal gradient (blue to red through yellow)
  129. gradient = QLinearGradient(0, 0, width, height)
  130. # Define color stops for thermal gradient
  131. gradient.setColorAt(0.0, QColor("#3498db")) # Blue (cool)
  132. gradient.setColorAt(0.25, QColor("#27ae60")) # Green
  133. gradient.setColorAt(0.5, QColor("#f1c40f")) # Yellow
  134. gradient.setColorAt(0.75, QColor("#e67e22")) # Orange
  135. gradient.setColorAt(1.0, QColor("#e74c3c")) # Red (hot)
  136. # Draw gradient background
  137. painter.fillRect(0, 0, width, height, gradient)
  138. # Draw thermal "hot spots" or patterns
  139. self._draw_thermal_patterns(painter, width, height)
  140. # Draw temperature overlay
  141. self._draw_temperature_overlay(painter, width, height)
  142. def _draw_thermal_patterns(self, painter, width, height):
  143. """Draw thermal pattern visualization."""
  144. # Draw some elliptical "hot spots"
  145. center_x = width // 2
  146. center_y = height // 2
  147. # Main thermal area (elliptical)
  148. thermal_width = width * 3 // 4
  149. thermal_height = height * 2 // 3
  150. # Create radial gradient for thermal effect
  151. radial_gradient = QRadialGradient(center_x, center_y, max(thermal_width, thermal_height) // 2)
  152. # Center is hottest (red), edges cooler (yellow)
  153. radial_gradient.setColorAt(0.0, QColor("#e74c3c"))
  154. radial_gradient.setColorAt(0.7, QColor("#f39c12"))
  155. radial_gradient.setColorAt(1.0, QColor("#f1c40f"))
  156. painter.setBrush(radial_gradient)
  157. painter.setPen(Qt.NoPen)
  158. painter.drawEllipse(center_x - thermal_width // 2, center_y - thermal_height // 2,
  159. thermal_width, thermal_height)
  160. def _draw_temperature_overlay(self, painter, width, height):
  161. """Draw temperature overlay information."""
  162. # Draw current temperature in center
  163. painter.setPen(QPen(QColor("white"), 2))
  164. temp_text = f"{self.temperature}°C"
  165. painter.drawText(width // 2 - 30, height // 2 - 10, temp_text)
  166. def update(self):
  167. """Override update to ensure repaint."""
  168. super().update()
  169. self.repaint()
  170. class TemperatureScaleWidget(QWidget):
  171. """Widget showing temperature scale with color gradient."""
  172. def __init__(self, temp_range, parent=None):
  173. super().__init__(parent)
  174. self.temp_range = temp_range
  175. def update_range(self, min_temp, max_temp):
  176. """Update temperature range."""
  177. self.temp_range = (min_temp, max_temp)
  178. self.update()
  179. def paintEvent(self, event):
  180. """Custom paint event to draw temperature scale."""
  181. painter = QPainter(self)
  182. painter.setRenderHint(QPainter.Antialiasing)
  183. width = self.width()
  184. height = self.height()
  185. # Draw temperature scale gradient
  186. gradient = QLinearGradient(0, 0, width, 0)
  187. # Blue to red gradient for temperature scale
  188. gradient.setColorAt(0.0, QColor("#3498db")) # Cool
  189. gradient.setColorAt(0.25, QColor("#27ae60"))
  190. gradient.setColorAt(0.5, QColor("#f1c40f"))
  191. gradient.setColorAt(0.75, QColor("#e67e22"))
  192. gradient.setColorAt(1.0, QColor("#e74c3c")) # Hot
  193. painter.fillRect(0, 0, width, height, gradient)
  194. # Draw scale border
  195. painter.setPen(QPen(QColor("#34495e"), 1))
  196. painter.drawRect(0, 0, width - 1, height - 1)
  197. def update(self):
  198. """Override update to ensure repaint."""
  199. super().update()
  200. self.repaint()