aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/uibuilder.py
diff options
context:
space:
mode:
Diffstat (limited to 'voctogui/lib/uibuilder.py')
-rw-r--r--voctogui/lib/uibuilder.py96
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