Skip to content

widget_utils

get_widget(root_widget, address)

Returns a sub widget of root_widget. Address is a sequence of childhood ranks as a string Return sub_widget may be modified, it's still the same sub_widget of the root_widget get_widget(root_widget, '0') returns root_widgetn first child TODO : allow childhood rank > 9

Source code in src/antakia/gui/widget_utils.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def get_widget(root_widget: Widget, address: str) -> Widget:
    """
    Returns a sub widget of root_widget. Address is a sequence of childhood ranks as a string
    Return sub_widget may be modified, it's still the same sub_widget of the root_widget
    get_widget(root_widget, '0') returns root_widgetn first child
    TODO : allow childhood rank > 9
    """
    if not address:
        return root_widget

    try:
        address = [int(i) for i in address]
    except ValueError:
        raise ValueError(address, "must be a string composed of digits")
    try:
        return recursive_get_widget(root_widget, address)
    except:
        raise IndexError(f"Nothing found @{address} in this {root_widget.__class__.__name__}")