ChannelOptionsWidget

class menpo.visualize.widgets.ChannelOptionsWidget(channel_options, render_function=None, style='minimal')[source]

Bases: FlexBox

Creates a widget for selecting channel options when rendering an image. The widget consists of the following parts from IPython.html.widgets:

No Object Variable (self.) Description
1 RadioButtons mode_radiobuttons

The mode selector

‘Single’ or ‘Multiple’

2 Checkbox masked_checkbox Controls masked mode
3 IntSlider single_slider Single channel selector
4 IntRangeSlider multiple_slider Channels range selector
5 Checkbox rgb_checkbox View as RGB
6 Checkbox sum_checkbox View sum of channels
7 Checkbox glyph_checkbox View glyph
8 BoundedIntText glyph_block_size_text Glyph block size
9 Checkbox glyph_use_negative_checkbox Use negative values
10 VBox glyph_options_box Contains 8, 9
11 VBox glyph_box Contains 7, 10
12 HBox multiple_options_box Contains 6, 11, 5
13 Box sliders_box Contains 3, 4
14 Box sliders_and_multiple_options_box Contains 13, 12
15 VBox mode_and_masked_box Contains 1, 2

Note that:

  • The selected values are stored in the self.selected_values dict.
  • To set the styling please refer to the style() and predefined_style() methods.
  • To update the state of the widget, please refer to the set_widget_state() method.
  • To update the callback function please refer to the replace_render_function() method.
Parameters:
  • channel_options (dict) –

    The dictionary with the initial options. For example

    channel_options = {'n_channels': 10,
                       'image_is_masked': True,
                       'channels': 0,
                       'glyph_enabled': False,
                       'glyph_block_size': 3,
                       'glyph_use_negative': False,
                       'sum_enabled': False,
                       'masked_enabled': True}
    
  • render_function (function or None, optional) – The render function that is executed when a widgets’ value changes. If None, then nothing is assigned.
  • style (See Below, optional) –

    Sets a predefined style at the widget. Possible options are

    Style Description
    ‘minimal’ Simple black and white style
    ‘success’ Green-based style
    ‘info’ Blue-based style
    ‘warning’ Yellow-based style
    ‘danger’ Red-based style
    ‘’ No style

Example

Let’s create a channels widget and then update its state. Firstly, we need to import it:

>>> from menpo.visualize.widgets import ChannelOptionsWidget
>>> from IPython.display import display

Now let’s define a render function that will get called on every widget change and will dynamically print the selected channels and masked flag:

>>> from menpo.visualize import print_dynamic
>>> def render_function(name, value):
>>>     s = "Channels: {}, Masked: {}".format(
>>>         wid.selected_values['channels'],
>>>         wid.selected_values['masked_enabled'])
>>>     print_dynamic(s)

Create the widget with some initial options and display it:

>>> channel_options = {'n_channels': 30,
>>>                    'image_is_masked': True,
>>>                    'channels': [0, 10],
>>>                    'glyph_enabled': False,
>>>                    'glyph_block_size': 3,
>>>                    'glyph_use_negative': False,
>>>                    'sum_enabled': True,
>>>                    'masked_enabled': True}
>>> wid = ChannelOptionsWidget(channel_options,
>>>                            render_function=render_function,
>>>                            style='warning')
>>> display(wid)

By playing around with the widget, printed message gets updated. Finally, let’s change the widget status with a new dictionary of options:

>>> new_options = {'n_channels': 10,
>>>                'image_is_masked': True,
>>>                'channels': [7, 8, 9],
>>>                'glyph_enabled': True,
>>>                'glyph_block_size': 3,
>>>                'glyph_use_negative': True,
>>>                'sum_enabled': False,
>>>                'masked_enabled': False}
>>> wid.set_widget_state(new_options, allow_callback=False)
add_render_function(render_function)[source]

Method that adds a render_function() to the widget. The signature of the given function is also stored in self._render_function.

Parameters:render_function (function or None, optional) – The render function that behaves as a callback. If None, then nothing is added.
predefined_style(style)[source]

Function that sets a predefined style on the widget.

Parameters:style (str (see below)) –

Style options

Style Description
‘minimal’ Simple black and white style
‘success’ Green-based style
‘info’ Blue-based style
‘warning’ Yellow-based style
‘danger’ Red-based style
‘’ No style
remove_render_function()[source]

Method that removes the current self._render_function() from the widget and sets self._render_function = None.

replace_render_function(render_function)[source]

Method that replaces the current self._render_function() of the widget with the given render_function().

Parameters:render_function (function or None, optional) – The render function that behaves as a callback. If None, then nothing is happening.
set_widget_state(channel_options, allow_callback=True)[source]

Method that updates the state of the widget with a new set of values.

Parameters:
  • channel_options (dict) –

    The dictionary with the new options to be used. For example

    channel_options = {'n_channels': 10,
                       'image_is_masked': True,
                       'channels': 0,
                       'glyph_enabled': False,
                       'glyph_block_size': 3,
                       'glyph_use_negative': False,
                       'sum_enabled': False,
                       'masked_enabled': True}
    
  • allow_callback (bool, optional) – If True, it allows triggering of any callback functions.
style(box_style=None, border_visible=False, border_color='black', border_style='solid', border_width=1, border_radius=0, padding=0, margin=0, font_family='', font_size=None, font_style='', font_weight='', slider_width='', slider_colour='')[source]

Function that defines the styling of the widget.

Parameters:
  • box_style (See Below, optional) –

    Style options

    Style Description
    ‘success’ Green-based style
    ‘info’ Blue-based style
    ‘warning’ Yellow-based style
    ‘danger’ Red-based style
    ‘’ Default style
    None No style
  • border_visible (bool, optional) – Defines whether to draw the border line around the widget.
  • border_color (str, optional) – The color of the border around the widget.
  • border_style (str, optional) – The line style of the border around the widget.
  • border_width (float, optional) – The line width of the border around the widget.
  • border_radius (float, optional) – The radius of the corners of the box.
  • padding (float, optional) – The padding around the widget.
  • margin (float, optional) – The margin around the widget.
  • font_family (See Below, optional) –

    The font family to be used. Example options

    {'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace',
     'helvetica'}
    
  • font_size (int, optional) – The font size.
  • font_style ({'normal', 'italic', 'oblique'}, optional) – The font style.
  • font_weight (See Below, optional) –

    The font weight. Example options

    {'ultralight', 'light', 'normal', 'regular', 'book', 'medium',
     'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy',
     'extra bold', 'black'}
    
  • slider_width (str, optional) – The width of the slider.
  • slider_colour (str, optional) – The colour of the sliders.