summaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: 73faca77d839dcb923c3c257074e2d129de12565 (plain)
  1. #!/usr/bin/python3
  2. import gi, logging
  3. from gi.repository import Gtk, Gst
  4. from lib.config import Config
  5. from lib.uibuilder import UiBuilder
  6. from lib.videodisplay import VideoDisplay
  7. class Ui(UiBuilder):
  8. def __init__(self, uifile):
  9. self.log = logging.getLogger('Ui')
  10. super().__init__(uifile)
  11. def setup(self):
  12. self.log.info('Initializing Ui')
  13. # Aquire the Main-Window from the UI-File
  14. self.win = self.get_check_widget('window')
  15. # Connect Close-Handler
  16. self.win.connect('delete-event', Gtk.main_quit)
  17. self.previews = {}
  18. self.preview_players = {}
  19. self.configure_video_main()
  20. self.configure_video_previews()
  21. self.configure_audio_selector()
  22. self.configure_streamblank_selector()
  23. def configure_video_main(self):
  24. self.log.info('Initializing Main Video and Main Audio-Level View')
  25. video = self.find_widget_recursive(self.win, 'video_main')
  26. audiolevel = self.find_widget_recursive(self.win, 'audiolevel_main')
  27. self.video_main_player = VideoDisplay(11000, video, audiolevel,
  28. playaudio=Config.getboolean('mainvideo', 'playaudio'))
  29. def configure_video_previews(self):
  30. self.log.info('Initializing Video Previews')
  31. sources = ['cam1', 'cam2', 'grabber']
  32. box = self.find_widget_recursive(self.win, 'box_left')
  33. try:
  34. width = Config.getint('previews', 'width')
  35. self.log.debug('Preview-Width configured to %u', width)
  36. except:
  37. width = 320
  38. self.log.debug('Preview-Width selected as %u', width)
  39. try:
  40. height = Config.getint('previews', 'height')
  41. self.log.debug('Preview-Height configured to %u', width)
  42. except:
  43. height = width*9/16
  44. self.log.debug('Preview-Height calculated to %u', width)
  45. # Accelerators
  46. accelerators = Gtk.AccelGroup()
  47. self.win.add_accel_group(accelerators)
  48. for idx, source in enumerate(sources):
  49. self.log.info('Initializing Video Preview %s', source)
  50. preview = self.get_check_widget('widget_preview', clone=True)
  51. video = self.find_widget_recursive(preview, 'video')
  52. video.set_size_request(width, height)
  53. box.pack_start(preview, fill=False, expand=False, padding=0)
  54. player = VideoDisplay(13000 + idx, video)
  55. self.find_widget_recursive(preview, 'label').set_label(source)
  56. btn_a = self.find_widget_recursive(preview, 'btn_a')
  57. btn_b = self.find_widget_recursive(preview, 'btn_b')
  58. btn_a.connect('toggled', self.preview_btn_toggled)
  59. btn_b.connect('toggled', self.preview_btn_toggled)
  60. key, mod = Gtk.accelerator_parse('%u' % (idx+1))
  61. btn_a.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  62. key, mod = Gtk.accelerator_parse('<Ctrl>%u' % (idx+1))
  63. btn_b.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  64. self.preview_players[source] = player
  65. self.previews[source] = preview
  66. def preview_btn_toggled(self, btn):
  67. self.log.info('preview_btn_toggled')
  68. def configure_audio_selector(self):
  69. self.log.info('Initializing Audio Selector')
  70. combo = self.find_widget_recursive(self.win, 'combo_audio')
  71. combo.set_sensitive(True)
  72. # FIXME access via combo_audio?
  73. liststore = self.get_check_widget('liststore_audio')
  74. liststore.clear()
  75. row = liststore.append()
  76. liststore.set(row, [0], ['foobar'])
  77. row = liststore.append('')
  78. liststore.set(row, [0], ['moofar'])
  79. combo.set_active_id('moofar')
  80. def configure_streamblank_selector(self):
  81. livebtn = self.get_check_widget('stream_live')
  82. blankbtn = self.get_check_widget('stream_blank')
  83. toolbar = blankbtn.get_parent()
  84. pos = toolbar.get_item_index(blankbtn)
  85. for idx, name in enumerate(['pause', 'nostream']):
  86. if idx == 0:
  87. new_btn = blankbtn
  88. else:
  89. new_icon = Gtk.Image.new_from_pixbuf(blankbtn.get_icon_widget().get_pixbuf())
  90. new_btn = Gtk.RadioToolButton(group=livebtn)
  91. new_btn.set_icon_widget(new_icon)
  92. toolbar.insert(new_btn, pos+1)
  93. new_btn.set_label("Stream %s" % name)
  94. def show(self):
  95. self.log.info('Running Video-Playback Pipelines')
  96. self.video_main_player.run()
  97. for name, player in self.preview_players.items():
  98. player.run()
  99. self.log.info('Showing Main-Window')
  100. self.win.show_all()