aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/ui.py
blob: 7da3ba4a1760ae0c6fa88959f16a0cac9671f714 (plain)
  1. import gi
  2. import 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. from lib.audioleveldisplay import AudioLevelDisplay
  8. from lib.warningoverlay import VideoWarningOverlay
  9. from lib.videopreviews import VideoPreviewsController
  10. from lib.audioselector import AudioSelectorController
  11. from lib.toolbar.composition import CompositionToolbarController
  12. from lib.toolbar.streamblank import StreamblankToolbarController
  13. from lib.toolbar.misc import MiscToolbarController
  14. from lib.shortcuts import show_shortcuts
  15. class Ui(UiBuilder):
  16. def __init__(self, uifile):
  17. self.log = logging.getLogger('Ui')
  18. super().__init__(uifile)
  19. def setup(self):
  20. self.log.info('Initializing Ui')
  21. # Aquire the Main-Window from the UI-File
  22. self.win = self.get_check_widget('window')
  23. # Connect Close-Handler
  24. self.win.connect('delete-event', Gtk.main_quit)
  25. # Create Audio-Level Display
  26. drawing_area = self.find_widget_recursive(self.win, 'audiolevel_main')
  27. self.audio_level_display = AudioLevelDisplay(drawing_area)
  28. # Create Main-Video Overlay Controller
  29. drawing_area = self.find_widget_recursive(self.win,
  30. 'video_overlay_drawingarea')
  31. self.video_warning_overlay = VideoWarningOverlay(drawing_area)
  32. # Create Main-Video Display
  33. drawing_area = self.find_widget_recursive(self.win, 'video_main')
  34. self.main_video_display = VideoDisplay(
  35. drawing_area,
  36. port=11000,
  37. play_audio=Config.getboolean('mainvideo', 'playaudio'),
  38. level_callback=self.audio_level_display.level_callback
  39. )
  40. # Setup Preview Controller
  41. drawing_area = self.find_widget_recursive(self.win, 'box_left')
  42. self.video_previews_controller = VideoPreviewsController(
  43. drawing_area,
  44. win=self.win,
  45. uibuilder=self
  46. )
  47. # check if there is a fixed audio source configured.
  48. # if so, remove the combo-box entirely instead of setting it up.
  49. if Config.has_option('mix', 'audiosource'):
  50. box_audio = self.find_widget_recursive(self.win, 'box_audio')
  51. drawing_area.remove(box_audio)
  52. else:
  53. combo_audio = self.find_widget_recursive(self.win, 'combo_audio')
  54. self.audio_selector_controller = AudioSelectorController(
  55. drawing_area=combo_audio,
  56. win=self.win,
  57. uibuilder=self
  58. )
  59. # Setup Toolbar Controllers
  60. toolbar = self.find_widget_recursive(self.win, 'toolbar')
  61. self.composition_toolbar_controller = CompositionToolbarController(
  62. toolbar,
  63. win=self.win,
  64. uibuilder=self
  65. )
  66. self.streamblank_toolbar_controller = StreamblankToolbarController(
  67. toolbar,
  68. win=self.win,
  69. uibuilder=self,
  70. warning_overlay=self.video_warning_overlay
  71. )
  72. self.misc_controller = MiscToolbarController(
  73. toolbar,
  74. win=self.win,
  75. uibuilder=self
  76. )
  77. # Setup Shortcuts window
  78. self.win.connect('key-press-event', self.handle_keypress)
  79. def handle_keypress(self, window, event):
  80. if event.keyval == Gdk.KEY_question:
  81. show_shortcuts(window)
  82. def show(self):
  83. self.log.info('Showing Main-Window')
  84. self.win.show_all()