summaryrefslogtreecommitdiff
path: root/voctogui/lib/warningoverlay.py
blob: ad86b693d42e55e520fcd5a4f5d6232370615d7c (plain)
  1. import logging
  2. from gi.repository import GLib
  3. class VideoWarningOverlay(object):
  4. """ Displays a Warning-Overlay above the Video-Feed of another VideoDisplay """
  5. def __init__(self):
  6. self.log = logging.getLogger('VideoWarningOverlay')
  7. self.text = None
  8. self.enabled = False
  9. self.blink_state = False
  10. GLib.timeout_add_seconds(1, self.on_blink_callback)
  11. def on_blink_callback(self):
  12. self.blink_state = not self.blink_state
  13. return True
  14. def enable(self, text=None):
  15. self.text = text
  16. self.enabled = True
  17. def set_text(self, text=None):
  18. self.text = text
  19. def disable(self):
  20. self.enabled = False
  21. def draw_callback(self, cr, timestamp, duration):
  22. if not self.enabled:
  23. return
  24. w = 1920
  25. h = 1080/20
  26. if self.blink_state:
  27. cr.set_source_rgba(1.0, 0.0, 0.0, 0.8)
  28. else:
  29. cr.set_source_rgba(1.0, 0.5, 0.0, 0.8)
  30. cr.rectangle(0, 0, w, h)
  31. cr.fill()
  32. text = "Stream is Blanked"
  33. if self.text:
  34. text += ": "+self.text
  35. cr.set_font_size(h*0.75)
  36. xbearing, ybearing, txtwidth, txtheight, xadvance, yadvance = cr.text_extents(text)
  37. cr.move_to(w/2 - txtwidth/2, h*0.75)
  38. cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
  39. cr.show_text(text)