aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/videopreviews.py
blob: 7be34da8d2316bb9c48fb8bf99781dc25b080c6d (plain)
  1. import logging
  2. from gi.repository import Gst, Gtk
  3. from lib.config import Config
  4. from lib.videodisplay import VideoDisplay
  5. import lib.connection as Connection
  6. class VideoPreviewsController(object):
  7. """ Displays Video-Previews and selection Buttons for them """
  8. def __init__(self, drawing_area, win, uibuilder):
  9. self.log = logging.getLogger('VideoPreviewsController')
  10. self.drawing_area = drawing_area
  11. self.win = win
  12. self.sources = Config.getlist('mix', 'sources')
  13. self.preview_players = {}
  14. self.previews = {}
  15. self.a_btns = {}
  16. self.b_btns = {}
  17. try:
  18. width = Config.getint('previews', 'width')
  19. self.log.debug('Preview-Width configured to %u', width)
  20. except:
  21. width = 320
  22. self.log.debug('Preview-Width selected as %u', width)
  23. try:
  24. height = Config.getint('previews', 'height')
  25. self.log.debug('Preview-Height configured to %u', width)
  26. except:
  27. height = width*9/16
  28. self.log.debug('Preview-Height calculated to %u', width)
  29. # Accelerators
  30. accelerators = Gtk.AccelGroup()
  31. win.add_accel_group(accelerators)
  32. group_a = None
  33. group_b = None
  34. for idx, source in enumerate(self.sources):
  35. self.log.info('Initializing Video Preview %s', source)
  36. preview = uibuilder.get_check_widget('widget_preview', clone=True)
  37. video = uibuilder.find_widget_recursive(preview, 'video')
  38. video.set_size_request(width, height)
  39. drawing_area.pack_start(preview, fill=False, expand=False, padding=0)
  40. player = VideoDisplay(video, port=13000 + idx)
  41. uibuilder.find_widget_recursive(preview, 'label').set_label(source)
  42. btn_a = uibuilder.find_widget_recursive(preview, 'btn_a')
  43. btn_b = uibuilder.find_widget_recursive(preview, 'btn_b')
  44. btn_a.set_name("%c %u" % ('a', idx))
  45. btn_b.set_name("%c %u" % ('b', idx))
  46. if not group_a:
  47. group_a = btn_a
  48. else:
  49. btn_a.join_group(group_a)
  50. if not group_b:
  51. group_b = btn_b
  52. else:
  53. btn_b.join_group(group_b)
  54. btn_a.connect('toggled', self.btn_toggled)
  55. btn_b.connect('toggled', self.btn_toggled)
  56. key, mod = Gtk.accelerator_parse('%u' % (idx+1))
  57. btn_a.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  58. key, mod = Gtk.accelerator_parse('<Ctrl>%u' % (idx+1))
  59. btn_b.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  60. self.preview_players[source] = player
  61. self.previews[source] = preview
  62. self.a_btns[source] = btn_a
  63. self.b_btns[source] = btn_b
  64. # connect event-handler and request initial state
  65. Connection.on('video_status', self.on_video_status)
  66. Connection.send('get_video')
  67. def btn_toggled(self, btn):
  68. if not btn.get_active():
  69. return
  70. btn_name = btn.get_name()
  71. self.log.debug('btn_toggled: %s', btn_name)
  72. channel, idx = btn_name.split(' ')[:2]
  73. source_name = self.sources[int(idx)]
  74. self.log.debug(self.sources)
  75. self.log.info('video-channel %s changed to %s', channel, source_name)
  76. Connection.send('set_video_'+channel, source_name)
  77. def on_video_status(self, source_a, source_b):
  78. self.log.info('on_video_status callback w/ sources: %s and %s', source_a, source_b)
  79. self.a_btns[source_a].set_active(True)
  80. self.b_btns[source_b].set_active(True)