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