summaryrefslogtreecommitdiff
path: root/voctogui/lib/videopreviews.py
blob: d6a18ecd2c37be6be3dd9401180f3a5afbc699cc (plain)
  1. import logging
  2. from gi.repository import Gst, Gtk
  3. from lib.videodisplay import VideoDisplay
  4. class VideoPreviewsController(object):
  5. """ Displays Video-Previews and selection Buttons for them """
  6. def __init__(self, drawing_area, win, uibuilder):
  7. self.log = logging.getLogger('VideoPreviewsController')
  8. self.drawing_area = drawing_area
  9. self.win = win
  10. self.sources = ['cam1', 'cam2', 'grabber']
  11. self.preview_players = {}
  12. self.previews = {}
  13. try:
  14. width = Config.getint('previews', 'width')
  15. self.log.debug('Preview-Width configured to %u', width)
  16. except:
  17. width = 320
  18. self.log.debug('Preview-Width selected as %u', width)
  19. try:
  20. height = Config.getint('previews', 'height')
  21. self.log.debug('Preview-Height configured to %u', width)
  22. except:
  23. height = width*9/16
  24. self.log.debug('Preview-Height calculated to %u', width)
  25. # Accelerators
  26. accelerators = Gtk.AccelGroup()
  27. win.add_accel_group(accelerators)
  28. group_a = None
  29. group_b = None
  30. for idx, source in enumerate(self.sources):
  31. self.log.info('Initializing Video Preview %s', source)
  32. preview = uibuilder.get_check_widget('widget_preview', clone=True)
  33. video = uibuilder.find_widget_recursive(preview, 'video')
  34. video.set_size_request(width, height)
  35. drawing_area.pack_start(preview, fill=False, expand=False, padding=0)
  36. player = VideoDisplay(video, port=13000 + idx)
  37. uibuilder.find_widget_recursive(preview, 'label').set_label(source)
  38. btn_a = uibuilder.find_widget_recursive(preview, 'btn_a')
  39. btn_b = uibuilder.find_widget_recursive(preview, 'btn_b')
  40. btn_a.set_name("%c %u" % ('a', idx))
  41. btn_b.set_name("%c %u" % ('b', idx))
  42. if not group_a:
  43. group_a = btn_a
  44. else:
  45. btn_a.join_group(group_a)
  46. if not group_b:
  47. group_b = btn_b
  48. else:
  49. btn_b.join_group(group_b)
  50. btn_a.connect('toggled', self.btn_toggled)
  51. btn_b.connect('toggled', self.btn_toggled)
  52. key, mod = Gtk.accelerator_parse('%u' % (idx+1))
  53. btn_a.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  54. key, mod = Gtk.accelerator_parse('<Ctrl>%u' % (idx+1))
  55. btn_b.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  56. self.preview_players[source] = player
  57. self.previews[source] = preview
  58. def btn_toggled(self, btn):
  59. if not btn.get_active():
  60. return
  61. self.log.info('btn_toggled: %s', btn.get_name())