diff options
author | MaZderMind <github@mazdermind.de> | 2015-06-17 15:49:03 +0200 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2015-06-17 15:49:03 +0200 |
commit | 7432403bd14eb8eb9f0d202f7fe4addb403be559 (patch) | |
tree | 9c0527652338d79c0768b38b6a24b352cb87bc85 /voctogui | |
parent | e78e24465bbe90150509946211148a364a75a115 (diff) |
enhance ui control code
Diffstat (limited to 'voctogui')
-rw-r--r-- | voctogui/lib/ui.py | 50 | ||||
-rw-r--r-- | voctogui/lib/uibuilder.py | 57 | ||||
-rw-r--r-- | voctogui/ui/voctogui.ui | 4 | ||||
-rwxr-xr-x | voctogui/voctogui.py | 12 |
4 files changed, 78 insertions, 45 deletions
diff --git a/voctogui/lib/ui.py b/voctogui/lib/ui.py new file mode 100644 index 0000000..fd40bb8 --- /dev/null +++ b/voctogui/lib/ui.py @@ -0,0 +1,50 @@ +#!/usr/bin/python3 +import gi, logging +from gi.repository import Gtk, Gst + +from lib.uibuilder import UiBuilder + +class Ui(UiBuilder): + def __init__(self, uifile): + self.log = logging.getLogger('Ui') + super().__init__(uifile) + + def setup(self): + # Aquire the Main-Window from the UI-File + self.win = self.get_check_widget('window') + + # Connect Close-Handler + 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 + self.find_widget_recursive(preview, "label").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() diff --git a/voctogui/lib/uibuilder.py b/voctogui/lib/uibuilder.py index 4084bcf..8ce01ab 100644 --- a/voctogui/lib/uibuilder.py +++ b/voctogui/lib/uibuilder.py @@ -4,54 +4,33 @@ from gi.repository import Gtk, Gst class UiBuilder(object): def __init__(self, uifile): - self.log = logging.getLogger('UiBuilder') + if not self.log: + self.log = logging.getLogger('UiBuilder') + 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.win = self.get_check_widget('window') - - # Connect Close-Handler - 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']) + def find_widget_recursive(self, widget, name): + widget = self._find_widget_recursive(widget, name) + if not widget: + self.log.error('could find required widget "%s" by name (not ID!) inside the parent %s', name, str(widget)) + raise Exception('Widget not found in parent') - row = liststore.append('') - liststore.set(row, [0], ['moofar']) + return widget - combo.set_active_id('moofar') + def _find_widget_recursive(self, widget, name): + if widget.get_name() == name: + return widget - def show(self): - self.win.show_all() + if hasattr(widget, 'get_children'): + for child in widget.get_children(): + widget = self._find_widget_recursive(child, name) + if widget: + return widget - def find_widget_recursive(self, widget_id, clone=False): - pass + return None def get_check_widget(self, widget_id, clone=False): if clone: diff --git a/voctogui/ui/voctogui.ui b/voctogui/ui/voctogui.ui index 75e9bb1..2443925 100644 --- a/voctogui/ui/voctogui.ui +++ b/voctogui/ui/voctogui.ui @@ -277,6 +277,7 @@ <property name="orientation">vertical</property> <child> <object class="GtkDrawingArea" id="video"> + <property name="name">video</property> <property name="width_request">320</property> <property name="height_request">180</property> <property name="visible">True</property> @@ -297,6 +298,7 @@ <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label"> + <property name="name">label</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">cam1</property> @@ -311,6 +313,7 @@ <child> <object class="GtkButton" id="btn_a"> <property name="label" translatable="yes">a</property> + <property name="name">btn_a</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -325,6 +328,7 @@ <child> <object class="GtkButton" id="btn_b"> <property name="label" translatable="yes">b</property> + <property name="name">btn_b</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py index 233bd16..52bc3c0 100755 --- a/voctogui/voctogui.py +++ b/voctogui/voctogui.py @@ -24,7 +24,7 @@ Gst.init([]) # import local classes from lib.args import Args -from lib.uibuilder import UiBuilder +from lib.ui import Ui # main class class Voctogui(object): @@ -34,7 +34,7 @@ class Voctogui(object): # 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 = UiBuilder(Args.ui_file) + self.ui = Ui(Args.ui_file) else: # Paths to look for the gst-switch UI-File @@ -49,18 +49,18 @@ class Voctogui(object): if os.path.isfile(path): self.log.info('loading ui-file from file %s', path) - self.builder = UiBuilder(path) + self.ui = Ui(path) break - if self.builder is None: + if self.ui is None: raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths))) - self.builder.setup() + self.ui.setup() def run(self): self.log.info('setting UI visible') - self.builder.show() + self.ui.show() try: self.log.info('running Gtk-MainLoop') |