def find_child(widget: Gtk.Widget, criterion: Callable) -> Optional[Gtk.Widget]: """Returns first matching widget amongst the widget itself and its descandants""" if criterion(widget): return widget for child in widget.get_children(): result = find_child(child, criterion) if isinstance(result, Gtk.Widget): return result return None
def snapshot_widget(root: Gtk.Widget) -> dict: style = root.get_style_context() snap = { 'type': type(root).__name__, 'label': get_label_for_widget(root), 'classes': style.list_classes()} if isinstance(root, Gtk.Container): snap['children'] = list(map(snapshot_widget, root.get_children())) return snap
def snapshot_widget(root: Gtk.Widget) -> dict: style = root.get_style_context() snap = { 'type': type(root).__name__, 'label': get_label_for_widget(root), 'classes': style.list_classes() } if isinstance(root, Gtk.Container): snap['children'] = list(map(snapshot_widget, root.get_children())) return snap
def find_child(widget: Gtk.Widget, child_name): """Find child widget by its name. Goes recursive if needed. :param widget: parent widget :param child_name: name of the widget :return: """ if widget.get_name() == child_name: return widget if hasattr(widget, 'get_children'): for child in widget.get_children(): _widget = find_child(child, child_name) if _widget: return _widget
def on_buttonnav_left(self, widget: Gtk.Widget, event: Gdk.EventCrossing) -> None: widget.get_children()[0].set_reveal_child(False)
def on_buttonnav_entered(self, widget: Gtk.Widget, event: Gdk.EventCrossing) -> None: widget.get_children()[0].set_reveal_child(True)
def _iter_all_widgets(root: Gtk.Widget): yield root if isinstance(root, Gtk.Container): for child in root.get_children(): yield from _iter_all_widgets(child)