summaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: ebf412e7a6528e646adfa02b992a25b5392c77d0 (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,
  25. playaudio=Config.getboolean('mainvideo', 'playaudio'))
  26. def configure_video_previews(self):
  27. sources = ['cam1', 'cam2', 'grabber']
  28. box = self.find_widget_recursive(self.win, 'box_left')
  29. for idx, source in enumerate(sources):
  30. preview = self.get_check_widget('widget_preview', clone=True)
  31. video = self.find_widget_recursive(preview, 'video')
  32. try:
  33. width = Config.getint('previews', 'width')
  34. except:
  35. width = 320
  36. try:
  37. height = Config.getint('previews', 'height')
  38. except:
  39. height = width*9/16
  40. video.set_size_request(width, height)
  41. box.pack_start(preview, fill=False, expand=False, padding=0)
  42. # http://stackoverflow.com/questions/3489520/python-gtk-widget-name
  43. self.find_widget_recursive(preview, 'label').set_label(source)
  44. player = VideoDisplay(13000 + idx, video)
  45. self.preview_players[source] = player
  46. self.previews[source] = preview
  47. def configure_audio_selector(self):
  48. combo = self.find_widget_recursive(self.win, 'combo_audio')
  49. combo.set_sensitive(True)
  50. # FIXME access via combo_audio?
  51. liststore = self.get_check_widget('liststore_audio')
  52. liststore.clear()
  53. row = liststore.append()
  54. liststore.set(row, [0], ['foobar'])
  55. row = liststore.append('')
  56. liststore.set(row, [0], ['moofar'])
  57. combo.set_active_id('moofar')
  58. def show(self):
  59. self.video_main_player.run()
  60. for name, player in self.preview_players.items():
  61. player.run()
  62. self.win.show_all()