from __future__ import absolute_import

def get_widget_by_name(box, widget_name):

    if hasattr(box, '_ngl_children'):
        children = box._ngl_children
    elif hasattr(box, 'children'):
        children = box.children
    else:
        children = None

    if children is not None:
        for widget in children:
            if hasattr(widget, '_ngl_name') and widget._ngl_name == widget_name:
                return widget
    return None
