summaryrefslogtreecommitdiff
path: root/voctogui/lib/uibuilder.py
blob: 4084bcf503c876465f0add7cd679bd23b5568f07 (plain)
  1. #!/usr/bin/python3
  2. import gi, logging
  3. from gi.repository import Gtk, Gst
  4. class UiBuilder(object):
  5. def __init__(self, uifile):
  6. self.log = logging.getLogger('UiBuilder')
  7. self.uifile = uifile
  8. def setup(self):
  9. self.builder = Gtk.Builder()
  10. self.builder.add_from_file(self.uifile)
  11. # Aquire the Main-Window from the UI-File
  12. self.win = self.get_check_widget('window')
  13. # Connect Close-Handler
  14. self.win.connect('delete-event', Gtk.main_quit)
  15. self.configure_video_previews()
  16. self.configure_audio_selector()
  17. def configure_video_previews(self):
  18. sources = ['cam1', 'cam2', 'grabber']
  19. box = self.get_check_widget('box_left')
  20. for source in sources:
  21. preview = self.get_check_widget('widget_preview', clone=True)
  22. #box.add(preview)
  23. box.pack_start(preview, fill=False, expand=False, padding=0)
  24. # http://stackoverflow.com/questions/3489520/python-gtk-widget-name
  25. preview.get_children()[0].get_children()[0].get_children()[1].get_children()[0].set_label(source)
  26. def configure_audio_selector(self):
  27. combo = self.get_check_widget('combo_audio')
  28. combo.set_sensitive(True)
  29. liststore = self.get_check_widget('liststore_audio')
  30. liststore.clear()
  31. row = liststore.append()
  32. liststore.set(row, [0], ['foobar'])
  33. row = liststore.append('')
  34. liststore.set(row, [0], ['moofar'])
  35. combo.set_active_id('moofar')
  36. def show(self):
  37. self.win.show_all()
  38. def find_widget_recursive(self, widget_id, clone=False):
  39. pass
  40. def get_check_widget(self, widget_id, clone=False):
  41. if clone:
  42. builder = Gtk.Builder()
  43. builder.add_from_file(self.uifile)
  44. else:
  45. builder = self.builder
  46. self.log.debug('loading widget "%s" from the .ui-File', widget_id)
  47. widget = builder.get_object(widget_id)
  48. if not widget:
  49. self.log.error('could not load required widget "%s" from the .ui-File', widget_id)
  50. raise Exception('Widget not found in .ui-File')
  51. return widget