aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: a75c1ba7edd662b182bd65c925de37c5a2e12eef (plain)
  1. #!/usr/bin/python3
  2. import gi, logging
  3. from gi.repository import Gtk, Gst, Gdk, GLib
  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. self.blink_btn = None
  86. self.blink_btn_state = False
  87. livebtn.connect('toggled', self.streamblank_button_toggled)
  88. livebtn.set_name('live')
  89. GLib.timeout_add_seconds(1, self.blink_streamblank_button)
  90. for idx, name in enumerate(['pause', 'nostream']):
  91. if idx == 0:
  92. new_btn = blankbtn
  93. else:
  94. new_icon = Gtk.Image.new_from_pixbuf(blankbtn.get_icon_widget().get_pixbuf())
  95. new_btn = Gtk.RadioToolButton(group=livebtn)
  96. new_btn.set_icon_widget(new_icon)
  97. toolbar.insert(new_btn, pos+1)
  98. new_btn.set_label("Stream %s" % name)
  99. new_btn.connect('toggled', self.streamblank_button_toggled)
  100. new_btn.set_name(name)
  101. def blink_streamblank_button(self):
  102. self.blink_btn_state = not self.blink_btn_state
  103. if self.blink_btn:
  104. self.blink_btn.get_icon_widget().override_background_color(
  105. Gtk.StateType.NORMAL,
  106. Gdk.RGBA(1.0, 0.0, 0.0, 1.0 if self.blink_btn_state else 0.0))
  107. return True
  108. def streamblank_button_toggled(self, btn):
  109. btn.get_icon_widget().override_background_color(
  110. Gtk.StateType.NORMAL,
  111. Gdk.RGBA(1.0, 0.0, 0.0, 0.0))
  112. if not btn.get_active():
  113. return
  114. if btn.get_name() != 'live':
  115. self.blink_btn = btn
  116. self.blink_btn_state = False
  117. else:
  118. self.blink_btn = None
  119. def show(self):
  120. self.log.info('Running Video-Playback Pipelines')
  121. self.video_main_player.run()
  122. for name, player in self.preview_players.items():
  123. player.run()
  124. self.log.info('Showing Main-Window')
  125. self.win.show_all()