panel_header.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """
  2. Panel Header Widget
  3. Reusable header component for panels with title and optional status indicator.
  4. """
  5. from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel
  6. from PyQt5.QtCore import Qt
  7. from PyQt5.QtGui import QFont
  8. class PanelHeader(QWidget):
  9. """
  10. Header widget for panels with colored background and status indicator.
  11. Args:
  12. title: Header title text
  13. color: Background color hex code
  14. show_status: Whether to show status indicator
  15. status: Status type ('online', 'offline', 'processing')
  16. """
  17. def __init__(self, title: str, color: str = "#34495e",
  18. show_status: bool = False, status: str = "offline", parent=None):
  19. super().__init__(parent)
  20. self.status_indicator = None
  21. self.init_ui(title, color, show_status, status)
  22. def init_ui(self, title: str, color: str, show_status: bool, status: str):
  23. """Initialize the header UI."""
  24. self.setFixedHeight(25)
  25. self.setStyleSheet(f"""
  26. QWidget {{
  27. background-color: {color};
  28. border-top-left-radius: 5px;
  29. border-top-right-radius: 5px;
  30. }}
  31. """)
  32. layout = QHBoxLayout(self)
  33. layout.setContentsMargins(10, 0, 10, 0)
  34. layout.setSpacing(5)
  35. # Title label
  36. title_label = QLabel(title)
  37. title_label.setFont(QFont("Arial", 10, QFont.Bold))
  38. title_label.setStyleSheet("color: white;")
  39. layout.addWidget(title_label)
  40. layout.addStretch()
  41. # Status indicator
  42. if show_status:
  43. self.status_indicator = QLabel("●")
  44. self.status_indicator.setFont(QFont("Arial", 12))
  45. self.set_status(status)
  46. layout.addWidget(self.status_indicator)
  47. def set_status(self, status: str):
  48. """
  49. Update the status indicator.
  50. Args:
  51. status: Status type ('online', 'offline', 'processing')
  52. """
  53. if self.status_indicator:
  54. status_colors = {
  55. "online": "#27ae60",
  56. "offline": "#e74c3c",
  57. "processing": "#f39c12"
  58. }
  59. color = status_colors.get(status, "#95a5a6")
  60. self.status_indicator.setStyleSheet(f"color: {color};")