summaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: e066a90bf03ef3e7978009e9a784d29f6a195210 (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. # Aquire the Main-Window from the UI-File
  13. self.win = self.get_check_widget('window')
  14. # Connect Close-Handler
  15. self.win.connect('delete-event', Gtk.main_quit)
  16. self.previews = {}
  17. self.preview_players = {}
  18. self.configure_video_main()
  19. self.configure_video_previews()
  20. self.configure_audio_selector()
  21. def configure_video_main(self):
  22. video = self.find_widget_recursive(self.win, 'video_main')
  23. audiolevel = self.find_widget_recursive(self.win, 'audiolevel_main')
  24. self.video_main_player = VideoDisplay(11000, video, audiolevel, playaudio=True)
  25. def configure_video_previews(self):
  26. sources = ['cam1', 'cam2', 'grabber']
  27. box = self.find_widget_recursive(self.win, 'box_left')
  28. for idx, source in enumerate(sources):
  29. preview = self.get_check_widget('widget_preview', clone=True)
  30. video = self.find_widget_recursive(preview, 'video')
  31. try:
  32. width = Config.getint('previews', 'width')
  33. except:
  34. width = 320
  35. try:
  36. height = Config.getint('previews', 'height')
  37. except:
  38. height = width*9/16
  39. video.set_size_request(width, height)
  40. box.pack_start(preview, fill=False, expand=False, padding=0)
  41. # http://stackoverflow.com/questions/3489520/python-gtk-widget-name
  42. self.find_widget_recursive(preview, 'label').set_label(source)
  43. player = VideoDisplay(13000 + idx, video)
  44. self.preview_players[source] = player
  45. self.previews[source] = preview
  46. def configure_audio_selector(self):
  47. combo = self.find_widget_recursive(self.win, 'combo_audio')
  48. combo.set_sensitive(True)
  49. # FIXME access via combo_audio?
  50. liststore = self.get_check_widget('liststore_audio')
  51. liststore.clear()
  52. row = liststore.append()
  53. liststore.set(row, [0], ['foobar'])
  54. row = liststore.append('')
  55. liststore.set(row, [0], ['moofar'])
  56. combo.set_active_id('moofar')
  57. def show(self):
  58. self.video_main_player.run()
  59. for name, player in self.preview_players.items():
  60. player.run()
  61. self.win.show_all()