status_indicator.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Status Indicator Widget
  3. A simple colored dot widget to show online/offline/updating status.
  4. """
  5. from PyQt5.QtWidgets import QLabel
  6. from resources.styles import get_status_indicator_style
  7. from utils.config import STATUS_INDICATOR_SIZE
  8. class StatusIndicator(QLabel):
  9. """
  10. A colored status indicator dot.
  11. Shows different colors based on status:
  12. - online: Green
  13. - offline: Red
  14. - updating: Orange
  15. Attributes:
  16. status: Current status ('online', 'offline', or 'updating')
  17. """
  18. def __init__(self, status: str = "online"):
  19. """
  20. Initialize the status indicator.
  21. Args:
  22. status: Initial status ('online', 'offline', or 'updating')
  23. """
  24. super().__init__()
  25. self.status = status
  26. self.setFixedSize(STATUS_INDICATOR_SIZE, STATUS_INDICATOR_SIZE)
  27. self.update_status()
  28. def update_status(self):
  29. """Update the visual appearance based on current status."""
  30. style = get_status_indicator_style(self.status)
  31. self.setStyleSheet(style)
  32. def set_status(self, status: str):
  33. """
  34. Set a new status and update appearance.
  35. Args:
  36. status: New status ('online', 'offline', or 'updating')
  37. """
  38. self.status = status
  39. self.update_status()
  40. def get_status(self) -> str:
  41. """
  42. Get the current status.
  43. Returns:
  44. str: Current status
  45. """
  46. return self.status