diff options
author | MaZderMind <github@mazdermind.de> | 2015-06-17 12:18:32 +0200 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2015-06-17 12:18:32 +0200 |
commit | e78e24465bbe90150509946211148a364a75a115 (patch) | |
tree | 3c205708dfaa6edcd44a72af7212a5b99ed180a2 /voctogui | |
parent | ce5c7ebd8b631386c0a9c911cb3ecb20c3f824dc (diff) |
start filling the gui from code
Diffstat (limited to 'voctogui')
-rw-r--r-- | voctogui/lib/uibuilder.py | 58 | ||||
-rw-r--r-- | voctogui/ui/voctogui.ui | 15 | ||||
-rwxr-xr-x | 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,13 +160,11 @@ <property name="can_focus">False</property> <child> <object class="GtkBox" id="box_left"> + <property name="width_request">320</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <placeholder/> - </child> - <child> <object class="GtkBox" id="box_audio"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -177,8 +175,9 @@ <property name="label" translatable="yes">Audio</property> </object> <packing> - <property name="expand">True</property> + <property name="expand">False</property> <property name="fill">True</property> + <property name="padding">5</property> <property name="position">0</property> </packing> </child> @@ -188,17 +187,18 @@ <property name="sensitive">False</property> <property name="can_focus">False</property> <property name="model">liststore_audio</property> + <property name="id_column">0</property> <child> <object class="GtkCellRendererText" id="cellrenderertext"/> <attributes> - <attribute name="height">0</attribute> <attribute name="text">0</attribute> </attributes> </child> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> + <property name="padding">5</property> <property name="position">1</property> </packing> </child> @@ -207,7 +207,8 @@ <property name="expand">False</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">3</property> + <property name="pack_type">end</property> + <property name="position">0</property> </packing> </child> </object> 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() |