From e78e24465bbe90150509946211148a364a75a115 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 17 Jun 2015 12:18:32 +0200 Subject: start filling the gui from code --- voctogui/lib/uibuilder.py | 58 ++++++++++++++++++++++++++++++++++++++++------- voctogui/ui/voctogui.ui | 15 ++++++------ voctogui/voctogui.py | 10 ++++---- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/voctogui/lib/uibuilder.py b/voctogui/lib/uibuilder.py index 8d8b245..4084bcf 100644 --- a/voctogui/lib/uibuilder.py +++ b/voctogui/lib/uibuilder.py @@ -2,24 +2,66 @@ import gi, logging from gi.repository import Gtk, Gst -class UiBuilder(Gtk.Builder): - def __init__(self): +class UiBuilder(object): + def __init__(self, uifile): self.log = logging.getLogger('UiBuilder') - super().__init__() + self.uifile = uifile def setup(self): + self.builder = Gtk.Builder() + self.builder.add_from_file(self.uifile) + # Aquire the Main-Window from the UI-File - self.log.debug('Loading Main-Window "window" from .ui-File') - self.win = self.get_check_widget("window") + self.win = self.get_check_widget('window') # Connect Close-Handler - self.win.connect("delete-event", Gtk.main_quit) + self.win.connect('delete-event', Gtk.main_quit) + + self.configure_video_previews() + self.configure_audio_selector() + + def configure_video_previews(self): + sources = ['cam1', 'cam2', 'grabber'] + box = self.get_check_widget('box_left') + + for source in sources: + preview = self.get_check_widget('widget_preview', clone=True) + #box.add(preview) + box.pack_start(preview, fill=False, expand=False, padding=0) + + # http://stackoverflow.com/questions/3489520/python-gtk-widget-name + preview.get_children()[0].get_children()[0].get_children()[1].get_children()[0].set_label(source) + + def configure_audio_selector(self): + combo = self.get_check_widget('combo_audio') + combo.set_sensitive(True) + + liststore = self.get_check_widget('liststore_audio') + liststore.clear() + + row = liststore.append() + liststore.set(row, [0], ['foobar']) + + row = liststore.append('') + liststore.set(row, [0], ['moofar']) + + combo.set_active_id('moofar') def show(self): self.win.show_all() - def get_check_widget(self, widget_id): - widget = self.get_object(widget_id) + def find_widget_recursive(self, widget_id, clone=False): + pass + + def get_check_widget(self, widget_id, clone=False): + if clone: + builder = Gtk.Builder() + builder.add_from_file(self.uifile) + else: + builder = self.builder + + self.log.debug('loading widget "%s" from the .ui-File', widget_id) + widget = builder.get_object(widget_id) if not widget: self.log.error('could not load required widget "%s" from the .ui-File', widget_id) raise Exception('Widget not found in .ui-File') diff --git a/voctogui/ui/voctogui.ui b/voctogui/ui/voctogui.ui index fba2892..75e9bb1 100644 --- a/voctogui/ui/voctogui.ui +++ b/voctogui/ui/voctogui.ui @@ -160,12 +160,10 @@ False + 320 True False vertical - - - True @@ -177,8 +175,9 @@ Audio - True + False True + 5 0 @@ -188,17 +187,18 @@ False False liststore_audio + 0 - 0 0 - False + True True + 5 1 @@ -207,7 +207,8 @@ False True 5 - 3 + end + 0 diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py index 39c2957..233bd16 100755 --- a/voctogui/voctogui.py +++ b/voctogui/voctogui.py @@ -30,14 +30,11 @@ from lib.uibuilder import UiBuilder class Voctogui(object): def __init__(self): self.log = logging.getLogger('Voctogui') - - # Instanciate GTK-Builder - self.builder = UiBuilder() # Uf a UI-File was specified on the Command-Line, load it if Args.ui_file: self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file) - self.builder.add_from_file(Args.ui_file) + self.builder = UiBuilder(Args.ui_file) else: # Paths to look for the gst-switch UI-File @@ -52,9 +49,12 @@ class Voctogui(object): if os.path.isfile(path): self.log.info('loading ui-file from file %s', path) - self.builder.add_from_file(path) + self.builder = UiBuilder(path) break + if self.builder is None: + raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths))) + self.builder.setup() -- cgit v1.2.3