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