summaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: c8ae1c5a35d6f88f1d1e883841a6397c2d6e4e83 (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. def configure_video_main(self):
  23. self.log.info('Initializing Main Video and Main Audio-Level View')
  24. video = self.find_widget_recursive(self.win, 'video_main')
  25. audiolevel = self.find_widget_recursive(self.win, 'audiolevel_main')
  26. self.video_main_player = VideoDisplay(11000, video, audiolevel,
  27. playaudio=Config.getboolean('mainvideo', 'playaudio'))
  28. def configure_video_previews(self):
  29. self.log.info('Initializing Video Previews')
  30. sources = ['cam1', 'cam2', 'grabber']
  31. box = self.find_widget_recursive(self.win, 'box_left')
  32. try:
  33. width = Config.getint('previews', 'width')
  34. self.log.debug('Preview-Width configured to %u', width)
  35. except:
  36. width = 320
  37. self.log.debug('Preview-Width selected as %u', width)
  38. try:
  39. height = Config.getint('previews', 'height')
  40. self.log.debug('Preview-Height configured to %u', width)
  41. except:
  42. height = width*9/16
  43. self.log.debug('Preview-Height calculated to %u', width)
  44. # Accelerators
  45. accelerators = Gtk.AccelGroup()
  46. self.win.add_accel_group(accelerators)
  47. for idx, source in enumerate(sources):
  48. self.log.info('Initializing Video Preview %s', source)
  49. preview = self.get_check_widget('widget_preview', clone=True)
  50. video = self.find_widget_recursive(preview, 'video')
  51. video.set_size_request(width, height)
  52. box.pack_start(preview, fill=False, expand=False, padding=0)
  53. player = VideoDisplay(13000 + idx, video)
  54. self.find_widget_recursive(preview, 'label').set_label(source)
  55. btn_a = self.find_widget_recursive(preview, 'btn_a')
  56. btn_b = self.find_widget_recursive(preview, 'btn_b')
  57. btn_a.connect('toggled', self.preview_btn_toggled)
  58. btn_b.connect('toggled', self.preview_btn_toggled)
  59. key, mod = Gtk.accelerator_parse('%u' % (idx+1))
  60. btn_a.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  61. key, mod = Gtk.accelerator_parse('<Ctrl>%u' % (idx+1))
  62. btn_b.add_accelerator('activate', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  63. self.preview_players[source] = player
  64. self.previews[source] = preview
  65. def preview_btn_toggled(self, btn):
  66. self.log.info('preview_btn_toggled')
  67. def configure_audio_selector(self):
  68. self.log.info('Initializing Audio Selector')
  69. combo = self.find_widget_recursive(self.win, 'combo_audio')
  70. combo.set_sensitive(True)
  71. # FIXME access via combo_audio?
  72. liststore = self.get_check_widget('liststore_audio')
  73. liststore.clear()
  74. row = liststore.append()
  75. liststore.set(row, [0], ['foobar'])
  76. row = liststore.append('')
  77. liststore.set(row, [0], ['moofar'])
  78. combo.set_active_id('moofar')
  79. def show(self):
  80. self.log.info('Running Video-Playback Pipelines')
  81. self.video_main_player.run()
  82. for name, player in self.preview_players.items():
  83. player.run()
  84. self.log.info('Showing Main-Window')
  85. self.win.show_all()