diff options
author | MaZderMind <git@mazdermind.de> | 2016-09-26 20:42:07 +0200 |
---|---|---|
committer | MaZderMind <git@mazdermind.de> | 2016-09-26 20:42:07 +0200 |
commit | 6e846c7081e242213cd70ceacfcff319e221942c (patch) | |
tree | 9d037e9272e65aea06c74775b2af1eae2f50a46e /voctogui/lib/uibuilder.py | |
parent | fbcbc3743e9179738244a96be54aa588e44314cb (diff) | |
parent | 1972da7f6aa60d3cb3b68808d0381e37898665f3 (diff) |
Merge branch 'pep8'
Diffstat (limited to 'voctogui/lib/uibuilder.py')
-rw-r--r-- | voctogui/lib/uibuilder.py | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/voctogui/lib/uibuilder.py b/voctogui/lib/uibuilder.py index 2a6b00e..8776480 100644 --- a/voctogui/lib/uibuilder.py +++ b/voctogui/lib/uibuilder.py @@ -1,47 +1,57 @@ -import gi, logging +import gi +import logging from gi.repository import Gtk, Gst -class UiBuilder(object): - def __init__(self, uifile): - if not self.log: - self.log = logging.getLogger('UiBuilder') - - self.uifile = uifile - - self.builder = Gtk.Builder() - self.builder.add_from_file(self.uifile) - - 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 ID inside the parent %s', name, str(widget)) - raise Exception('Widget not found in parent') - - return widget - def _find_widget_recursive(self, widget, name): - if Gtk.Buildable.get_name(widget) == name: - return widget - - if hasattr(widget, 'get_children'): - for child in widget.get_children(): - widget = self._find_widget_recursive(child, name) - if widget: - return widget - - return None - - 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') +class UiBuilder(object): - return widget + def __init__(self, uifile): + if not self.log: + self.log = logging.getLogger('UiBuilder') + + self.uifile = uifile + + self.builder = Gtk.Builder() + self.builder.add_from_file(self.uifile) + + 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 ID inside the parent %s', + name, + str(widget) + ) + raise Exception('Widget not found in parent') + + return widget + + def _find_widget_recursive(self, widget, name): + if Gtk.Buildable.get_name(widget) == name: + return widget + + if hasattr(widget, 'get_children'): + for child in widget.get_children(): + widget = self._find_widget_recursive(child, name) + if widget: + return widget + + return None + + 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') + + return widget |