def connect_current_combo(client, prop, widget):
    """
    Connect widget.currentIndexChanged and client.prop

    client.prop should be a callback property
    """

    def update_widget(value):
        try:
            idx = _find_combo_data(widget, value)
        except ValueError:
            if value is None:
                idx = -1
            else:
                raise
        widget.setCurrentIndex(idx)

    def update_prop(idx):
        if idx == -1:
            setattr(client, prop, None)
        else:
            setattr(client, prop, widget.itemData(idx))

    add_callback(client, prop, update_widget)
    widget.currentIndexChanged.connect(update_prop)
    update_widget(getattr(client, prop))
dataset/ETHPy150Open glue-viz/glue/glue/utils/qt/widget_properties.py/connect_current_combo/original