menpo/visualize/widgets/options.py
def update_channel_options(channel_options_wid, n_channels, image_is_masked,
                           masked_default=False):
    r"""
    Function that updates the state of a given channel_options widget if the
    image's number of channels or its masked flag has changed. Usage example:

    ::

        channel_options_wid = channel_options(n_channels=2,
                                              image_is_masked=True)
        display(channel_options_wid)
        format_channel_options(channel_options_wid)
        update_channel_options(channel_options_wid, n_channels=36,
                               image_is_masked=False)

    Parameters
    ----------
    channel_options_wid : widget
        The widget object generated by the `channel_options()` function.
    n_channels : `int`
        The number of channels.
    image_is_masked : `boolean`
        Flag that defines whether the image is an instance of :map:`MaskedImage`
        or subclass.
    masked_default : `boolean`, optional
        The value to be assigned at the masked checkbox.
    """
    # if image_is_masked flag has actually changed from the previous value
    if image_is_masked != channel_options_wid.selected_values['image_is_masked']:
        # change the channel_options output
        channel_options_wid.selected_values['image_is_masked'] = image_is_masked
        channel_options_wid.selected_values['masked_enabled'] = masked_default
        # set the masked checkbox state
        channel_options_wid.children[1].children[0].children[1].visible = \
            channel_options_wid.children[0].value and image_is_masked
        channel_options_wid.children[1].children[0].children[1].value = False

    # if n_channels are actually different from the previous value
    if n_channels != channel_options_wid.selected_values['n_channels']:
        # change the channel_options output
        channel_options_wid.selected_values['n_channels'] = n_channels
        channel_options_wid.selected_values['channels'] = 0
        # set the rgb checkbox state
        channel_options_wid.children[1].children[1].children[1].children[
            2].visible = \
            n_channels == 3 and channel_options_wid.children[0].value
        # set the channel options state (apart from the masked checkbox)
        if n_channels == 1:
            # set sliders max and min values
            channel_options_wid.children[1].children[1].children[0].children[
                0].max = 1
            channel_options_wid.children[1].children[1].children[0].children[
                1].max = 1
            channel_options_wid.children[1].children[1].children[0].children[
                0].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                1].min = 0
            # set sliders state
            channel_options_wid.children[1].children[1].children[0].children[
                0].disabled = True
            channel_options_wid.children[1].children[1].children[0].children[
                1].visible = False
            # set glyph/sum state
            channel_options_wid.children[1].children[1].children[1].children[
                0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[1].disabled = True
            # set mode state
            channel_options_wid.children[1].children[0].children[
                0].disabled = True
            # set mode and sliders values
            for k in range(4):
                if k == 0:
                    channel_options_wid.children[1].children[1].children[
                        1].children[2].value = False
                elif k == 1:
                    channel_options_wid.children[1].children[0].children[
                        0].value = "Single"
                elif k == 2:
                    channel_options_wid.children[1].children[1].children[
                        0].children[0].value = 0
                else:
                    channel_options_wid.children[1].children[1].children[
                        0].children[1].value = 0
        else:
            # set sliders max and min values
            channel_options_wid.children[1].children[1].children[0].children[
                0].max = n_channels - 1
            channel_options_wid.children[1].children[1].children[0].children[
                1].max = n_channels - 1
            channel_options_wid.children[1].children[1].children[0].children[
                0].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                1].min = 0
            # set sliders state
            channel_options_wid.children[1].children[1].children[0].children[
                0].disabled = False
            channel_options_wid.children[1].children[1].children[0].children[
                1].visible = False
            # set glyph/sum state
            channel_options_wid.children[1].children[1].children[1].children[
                0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[1].disabled = False
            # set mode state
            channel_options_wid.children[1].children[0].children[
                0].disabled = False
            # set mode and sliders values
            for k in range(4):
                if k == 0:
                    channel_options_wid.children[1].children[1].children[
                        1].children[2].value = n_channels == 3
                elif k == 1:
                    channel_options_wid.children[1].children[0].children[
                        0].value = "Single"
                elif k == 2:
                    channel_options_wid.children[1].children[1].children[
                        0].children[0].value = 0
                else:
                    channel_options_wid.children[1].children[1].children[
                        0].children[1].value = 0
r"""
    Function that updates the state of a given channel_options widget if the
    image's number of channels or its masked flag has changed. Usage example:

    ::

        channel_options_wid = channel_options(n_channels=2,
                                              image_is_masked=True)
        display(channel_options_wid)
        format_channel_options(channel_options_wid)
        update_channel_options(channel_options_wid, n_channels=36,
                               image_is_masked=False)

    Parameters
    ----------
    channel_options_wid : widget
        The widget object generated by the `channel_options()` function.
    n_channels : `int`
        The number of channels.
    image_is_masked : `boolean`
        Flag that defines whether the image is an instance of :map:`MaskedImage`
        or subclass.
    masked_default : `boolean`, optional
        The value to be assigned at the masked checkbox.
    
r"""
Function that updates the state of a given channel_options widget if the
image's number of channels or its masked flag has changed. Usage example.
r " " " Function that updates the state of a given channel_options widget if the image ' s number of channels or its masked flag has changed . Usage example .
def update_channel_options(channel_options_wid, n_channels, image_is_masked,
                           masked_default=False):
    if image_is_masked != channel_options_wid.selected_values['image_is_masked']:
        channel_options_wid.selected_values['image_is_masked'] = image_is_masked
        channel_options_wid.selected_values['masked_enabled'] = masked_default
        channel_options_wid.children[1].children[0].children[1].visible = \
            channel_options_wid.children[0].value and image_is_masked
        channel_options_wid.children[1].children[0].children[1].value = False
    if n_channels != channel_options_wid.selected_values['n_channels']:
        channel_options_wid.selected_values['n_channels'] = n_channels
        channel_options_wid.selected_values['channels'] = 0
        channel_options_wid.children[1].children[1].children[1].children[
            2].visible = \
            n_channels == 3 and channel_options_wid.children[0].value
        if n_channels == 1:
            channel_options_wid.children[1].children[1].children[0].children[
                0].max = 1
            channel_options_wid.children[1].children[1].children[0].children[
                1].max = 1
            channel_options_wid.children[1].children[1].children[0].children[
                0].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                1].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                0].disabled = True
            channel_options_wid.children[1].children[1].children[0].children[
                1].visible = False
            channel_options_wid.children[1].children[1].children[1].children[
                0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[0].disabled = True
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[1].disabled = True
            channel_options_wid.children[1].children[0].children[
                0].disabled = True
            for k in range(4):
                if k == 0:
                    channel_options_wid.children[1].children[1].children[
                        1].children[2].value = False
                elif k == 1:
                    channel_options_wid.children[1].children[0].children[
                        0].value = "Single"
                elif k == 2:
                    channel_options_wid.children[1].children[1].children[
                        0].children[0].value = 0
                else:
                    channel_options_wid.children[1].children[1].children[
                        0].children[1].value = 0
        else:
            channel_options_wid.children[1].children[1].children[0].children[
                0].max = n_channels - 1
            channel_options_wid.children[1].children[1].children[0].children[
                1].max = n_channels - 1
            channel_options_wid.children[1].children[1].children[0].children[
                0].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                1].min = 0
            channel_options_wid.children[1].children[1].children[0].children[
                0].disabled = False
            channel_options_wid.children[1].children[1].children[0].children[
                1].visible = False
            channel_options_wid.children[1].children[1].children[1].children[
                0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[0].disabled = False
            channel_options_wid.children[1].children[1].children[1].children[
                1].children[1].children[1].disabled = False
            channel_options_wid.children[1].children[0].children[
                0].disabled = False
            for k in range(4):
                if k == 0:
                    channel_options_wid.children[1].children[1].children[
                        1].children[2].value = n_channels == 3
                elif k == 1:
                    channel_options_wid.children[1].children[0].children[
                        0].value = "Single"
                elif k == 2:
                    channel_options_wid.children[1].children[1].children[
                        0].children[0].value = 0
                else:
                    channel_options_wid.children[1].children[1].children[
                        0].children[1].value = 0
def update_channel_options ( channel_options_wid , n_channels , image_is_masked , masked_default = False ) : if image_is_masked != channel_options_wid . selected_values [ 'image_is_masked' ] : channel_options_wid . selected_values [ 'image_is_masked' ] = image_is_masked channel_options_wid . selected_values [ 'masked_enabled' ] = masked_default channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 1 ] . visible = channel_options_wid . children [ 0 ] . value and image_is_masked channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 1 ] . value = False if n_channels != channel_options_wid . selected_values [ 'n_channels' ] : channel_options_wid . selected_values [ 'n_channels' ] = n_channels channel_options_wid . selected_values [ 'channels' ] = 0 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 2 ] . visible = n_channels == 3 and channel_options_wid . children [ 0 ] . value if n_channels == 1 : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . max = 1 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . max = 1 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . min = 0 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . min = 0 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . disabled = True channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . visible = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = True channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = True channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = True channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . disabled = True channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 0 ] . disabled = True for k in range ( 4 ) : if k == 0 : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 2 ] . value = False elif k == 1 : channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 0 ] . value = "Single" elif k == 2 : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . value = 0 else : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . value = 0 else : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . max = n_channels - 1 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . max = n_channels - 1 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . min = 0 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . min = 0 channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . disabled = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . visible = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 0 ] . disabled = False channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 1 ] . disabled = False channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 0 ] . disabled = False for k in range ( 4 ) : if k == 0 : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 1 ] . children [ 2 ] . value = n_channels == 3 elif k == 1 : channel_options_wid . children [ 1 ] . children [ 0 ] . children [ 0 ] . value = "Single" elif k == 2 : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . value = 0 else : channel_options_wid . children [ 1 ] . children [ 1 ] . children [ 0 ] . children [ 1 ] . value = 0
r"""
Function that updates the state of a given channel_options widget if the
image's number of channels or its masked flag has changed.
r " " " Function that updates the state of a given channel_options widget if the image ' s number of channels or its masked flag has changed .
r"""
    Function that updates the state of a given channel_options widget if the
    image's number of channels or its masked flag has changed. Usage example:

    ::

        channel_options_wid = channel_options(n_channels=2,
                                              image_is_masked=True)
        display(channel_options_wid)
        format_channel_options(channel_options_wid)
        update_channel_options(channel_options_wid, n_channels=36,
                               image_is_masked=False)

    Parameters
    ----------
    channel_options_wid : widget
        The widget object generated by the `channel_options()` function.
    n_channels : `int`
        The number of channels.
    image_is_masked : `boolean`
        Flag that defines whether the image is an instance of :map:`MaskedImage`
        or subclass.
    masked_default : `boolean`, optional
        The value to be assigned at the masked checkbox.
    """ # if image_is_masked flag has actually changed from the previous value # change the channel_options output # set the masked checkbox state # if n_channels are actually different from the previous value # change the channel_options output # set the rgb checkbox state # set the channel options state (apart from the masked checkbox) # set sliders max and min values # set sliders state # set glyph/sum state # set mode state # set mode and sliders values # set sliders max and min values # set sliders state # set glyph/sum state # set mode state # set mode and sliders values
channel_options_wid
n_channels
image_is_masked
masked_default
channel_options_wid
widget
The widget object generated by the `channel_options()` function.
n_channels : `int`
The number of channels.
image_is_masked : `boolean`
Flag that defines whether the image is an instance of :map:`MaskedImage`
or subclass.
masked_default : `boolean`, optional
The value to be assigned at the masked checkbox.
widget The widget object generated by the ` channel_options () ` function . n_channels : ` int ` The number of channels . image_is_masked : ` boolean ` Flag that defines whether the image is an instance of : map : ` MaskedImage ` or subclass . masked_default : ` boolean ` optional The value to be assigned at the masked checkbox .