summaryrefslogtreecommitdiff
path: root/voctogui/lib/warningoverlay.py
blob: f4f7f24f768312b9f7c888a235a2a79d562150af (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
  6. of another VideoDisplay"""
  7. def __init__(self, drawing_area):
  8. self.log = logging.getLogger('VideoWarningOverlay')
  9. self.drawing_area = drawing_area
  10. self.drawing_area.connect("draw", self.draw_callback)
  11. self.text = None
  12. self.blink_state = False
  13. GLib.timeout_add_seconds(1, self.on_blink_callback)
  14. def on_blink_callback(self):
  15. self.blink_state = not self.blink_state
  16. self.drawing_area.queue_draw()
  17. return True
  18. def enable(self, text=None):
  19. self.text = text
  20. self.drawing_area.show()
  21. self.drawing_area.queue_draw()
  22. def set_text(self, text=None):
  23. self.text = text
  24. self.drawing_area.queue_draw()
  25. def disable(self):
  26. self.drawing_area.hide()
  27. self.drawing_area.queue_draw()
  28. def draw_callback(self, area, cr):
  29. w = self.drawing_area.get_allocated_width()
  30. h = self.drawing_area.get_allocated_height()
  31. self.log.debug('draw_callback: w/h=%u/%u, blink_state=%u',
  32. w, h, self.blink_state)
  33. if self.blink_state:
  34. cr.set_source_rgba(1.0, 0.0, 0.0, 0.8)
  35. else:
  36. cr.set_source_rgba(1.0, 0.5, 0.0, 0.8)
  37. cr.rectangle(0, 0, w, h)
  38. cr.fill()
  39. text = "Stream is Blanked"
  40. if self.text:
  41. text += ": " + self.text
  42. cr.set_font_size(h * 0.75)
  43. (xbearing, ybearing,
  44. txtwidth, txtheight,
  45. xadvance, yadvance) = cr.text_extents(text)
  46. cr.move_to(w / 2 - txtwidth / 2, h * 0.75)
  47. cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
  48. cr.show_text(text)