RendererOptionsWidget

class menpo.visualize.widgets.RendererOptionsWidget(renderer_options, options_tabs, objects_names=None, labels_per_object=None, selected_object=0, object_selection_dropdown_visible=True, render_function=None, style='minimal', tabs_style='minimal')[source]

Bases: FlexBox

Creates a widget for selecting rendering options. The widget consists of the following parts from IPython.html.widgets and menpo.visualize.widgets.tools:

No Object Variable (self.) Description
1 Dropdown object_selection_dropdown The object selector
2

LineOptionsWidget

MarkerOptionsWidget

ImageOptionsWidget

NumberingOptionsWidget

FigureOptionsWidget

LegendOptionsWidget

GridOptionsWidget

options_widgets

list with the

various rendering

sub-options widgets

3 Tab suboptions_tab Contains all 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() methods.
Parameters:
  • renderer_options (list of dict) –

    The initial rendering options per object. The list must have length n_objects and contain a dict of rendering options per object. For example, in case we had two objects to render

    lines_options = {'render_lines': True,
                     'line_width': 1,
                     'line_colour': ['b', 'r'],
                     'line_style': '-'}
    markers_options = {'render_markers': True,
                       'marker_size': 20,
                       'marker_face_colour': ['w', 'w'],
                       'marker_edge_colour': ['b', 'r'],
                       'marker_style': 'o',
                       'marker_edge_width': 1}
    numbering_options = {'render_numbering': True,
                         'numbers_font_name': 'serif',
                         'numbers_font_size': 10,
                         'numbers_font_style': 'normal',
                         'numbers_font_weight': 'normal',
                         'numbers_font_colour': ['k'],
                         'numbers_horizontal_align': 'center',
                         'numbers_vertical_align': 'bottom'}
    legend_options = {'render_legend': True,
                      'legend_title': '',
                      'legend_font_name': 'serif',
                      'legend_font_style': 'normal',
                      'legend_font_size': 10,
                      'legend_font_weight': 'normal',
                      'legend_marker_scale': 1.,
                      'legend_location': 2,
                      'legend_bbox_to_anchor': (1.05, 1.),
                      'legend_border_axes_pad': 1.,
                      'legend_n_columns': 1,
                      'legend_horizontal_spacing': 1.,
                      'legend_vertical_spacing': 1.,
                      'legend_border': True,
                      'legend_border_padding': 0.5,
                      'legend_shadow': False,
                      'legend_rounded_corners': True}
    figure_options = {'x_scale': 1.,
                      'y_scale': 1.,
                      'render_axes': True,
                      'axes_font_name': 'serif',
                      'axes_font_size': 10,
                      'axes_font_style': 'normal',
                      'axes_font_weight': 'normal',
                      'axes_x_limits': None,
                      'axes_y_limits': None}
    grid_options = {'render_grid': True,
                    'grid_line_style': '--',
                    'grid_line_width': 0.5}
    image_options = {'alpha': 1.,
                     'interpolation': 'bilinear',
                     'cmap_name': 'gray'}
    rendering_dict = {'lines': lines_options,
                      'markers': markers_options,
                      'numbering': numbering_options,
                      'legend': legend_options,
                      'figure': figure_options,
                      'grid': grid_options,
                      'image': image_options}
    renderer_options = [rendering_dict, rendering_dict]
    
  • options_tabs (list of str) –

    List that defines the ordering of the options tabs. Possible values are

    Value Returned class
    ‘lines’ LineOptionsWidget
    ‘markers’ MarkerOptionsWidget
    ‘numbering’ NumberingOptionsWidget
    ‘figure_one’ FigureOptionsOneScaleWidget
    ‘figure_two’ FigureOptionsTwoScalesWidget
    ‘legend’ LegendOptionsWidget
    ‘grid’ GridOptionsWidget
    ‘image’ ImageOptionsWidget
  • objects_names (list of str or None, optional) – A list with the names of the objects that will be used in the selection dropdown menu. If None, then the names will have the format %d.
  • labels_per_object (list of list or None, optional) – A list that contains a list of labels for each object. Those labels are employed by the ColourSelectionWidget. An example for which this option is useful is in the case we wish to create rendering options for multiple LandmarkGroup objects and each one of them has a different set of labels. If None, then labels_per_object is a list of length n_objects with None.
  • selected_object (int, optional) – The object for which to show the rendering options in the beginning, when the widget is created.
  • object_selection_dropdown_visible (bool, optional) – Controls the visibility of the object selection dropdown (self.object_selection_dropdown).
  • 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
  • tabs_style (See Below, optional) –

    Sets a predefined style at the tabs of 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 rendering options widget and then update its state. Firstly, we need to import it:

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

Let’s set some initial options:

>>> options_tabs = ['markers', 'lines', 'grid']
>>> objects_names = ['james', 'patrick']
>>> labels_per_object = [['jaw', 'eyes'], None]
>>> selected_object = 1
>>> object_selection_dropdown_visible = True

Now let’s define a render function that will get called on every widget change and will dynamically print the selected marker face colour for both objects:

>>> from menpo.visualize import print_dynamic
>>> def render_function(name, value):
>>>     s = "{}: {}, {}: {}".format(
>>>         wid.objects_names[0],
>>>         wid.selected_values[0]['markers']['marker_face_colour'],
>>>         wid.objects_names[1],
>>>         wid.selected_values[1]['markers']['marker_face_colour'])
>>>     print_dynamic(s)

Create the widget with some initial options and display it:

>>> # 1st dictionary
>>> markers_options = {'render_markers': True, 'marker_size': 20,
>>>                    'marker_face_colour': ['w', 'w'],
>>>                    'marker_edge_colour': ['b', 'r'],
>>>                    'marker_style': 'o', 'marker_edge_width': 1}
>>> lines_options = {'render_lines': True, 'line_width': 1,
>>>                  'line_colour': ['b', 'r'], 'line_style': '-'}
>>> grid_options = {'render_grid': True, 'grid_line_style': '--',
>>>                 'grid_line_width': 0.5}
>>> rendering_dict_1 = {'lines': lines_options, 'grid': grid_options,
>>>                     'markers': markers_options}
>>>
>>> # 2nd dictionary
>>> markers_options = {'render_markers': True, 'marker_size': 200,
>>>                    'marker_face_colour': [[0.1, 0.2, 0.3]],
>>>                    'marker_edge_colour': ['m'], 'marker_style': 'x',
>>>                    'marker_edge_width': 1}
>>> lines_options = {'render_lines': True, 'line_width': 100,
>>>                  'line_colour': [[0.1, 0.2, 0.3]], 'line_style': '-'}
>>> grid_options = {'render_grid': False, 'grid_line_style': '--',
>>>                 'grid_line_width': 0.5}
>>> rendering_dict_2 = {'lines': lines_options, 'grid': grid_options,
>>>                     'markers': markers_options}
>>>
>>> # Final list
>>> rendering_options = [rendering_dict_1, rendering_dict_2]
>>>
>>> # Create and display widget
>>> wid = AnimationOptionsWidget(index, index_style='buttons',
>>>                              render_function=render_function,
>>>                              style='info')
>>> display(wid)

By playing around, the printed message gets updated. The style of the widget can be changed as:

>>> wid.predefined_style('minimal', 'info')

Finally, let’s change the widget status with a new dictionary of options:

>>> # 1st dictionary
>>> markers_options = {'render_markers': False, 'marker_size': 20,
>>>                    'marker_face_colour': ['k'],
>>>                    'marker_edge_colour': ['c'],
>>>                    'marker_style': 'o', 'marker_edge_width': 1}
>>> lines_options = {'render_lines': False, 'line_width': 1,
>>>                  'line_colour': ['r'], 'line_style': '-'}
>>> grid_options = {'render_grid': True, 'grid_line_style': '--',
>>>                 'grid_line_width': 0.5}
>>> rendering_dict_1 = {'lines': lines_options, 'grid': grid_options,
>>>                     'markers': markers_options}
>>>
>>> # 2nd dictionary
>>> markers_options = {'render_markers': True, 'marker_size': 200,
>>>                    'marker_face_colour': [[0.123, 0.234, 0.345], 'r'],
>>>                    'marker_edge_colour': ['m', 'm'],
>>>                    'marker_style': 'x', 'marker_edge_width': 1}
>>> lines_options = {'render_lines': True, 'line_width': 100,
>>>                  'line_colour': [[0.1, 0.2, 0.3], 'b'], 'line_style': '-'}
>>> grid_options = {'render_grid': False, 'grid_line_style': '--',
>>>                 'grid_line_width': 0.5}
>>> rendering_dict_2 = {'lines': lines_options, 'grid': grid_options,
>>>                     'markers': markers_options}
>>>
>>> # Final list
>>> new_options = [rendering_dict_1, rendering_dict_2]
>>>
>>> # Set new labels per object
>>> labels_per_object = [['1'], ['jaw', 'eyes']]
>>>
>>> # Update widget state
>>> wid.set_widget_state(new_options, labels_per_object,
>>>                      allow_callback=True)
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, tabs_style='minimal')[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
  • tabs_style (str (see below), optional) –

    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(renderer_options, labels_per_object, selected_object=None, object_selection_dropdown_visible=None, allow_callback=True)[source]

Method that updates the state of the widget with a new set of values. Note that the number of objects should not change.

Parameters:
  • renderer_options (list of dict) –

    The selected rendering options per object. The list must have length n_objects and contain a dict of rendering options per object. For example, in case we had two objects to render

    lines_options = {'render_lines': True,
                     'line_width': 1,
                     'line_colour': ['b', 'r'],
                     'line_style': '-'}
    markers_options = {'render_markers': True,
                       'marker_size': 20,
                       'marker_face_colour': ['w', 'w'],
                       'marker_edge_colour': ['b', 'r'],
                       'marker_style': 'o',
                       'marker_edge_width': 1}
    numbering_options = {'render_numbering': True,
                         'numbers_font_name': 'serif',
                         'numbers_font_size': 10,
                         'numbers_font_style': 'normal',
                         'numbers_font_weight': 'normal',
                         'numbers_font_colour': ['k'],
                         'numbers_horizontal_align': 'center',
                         'numbers_vertical_align': 'bottom'}
    legend_options = {'render_legend': True,
                      'legend_title': '',
                      'legend_font_name': 'serif',
                      'legend_font_style': 'normal',
                      'legend_font_size': 10,
                      'legend_font_weight': 'normal',
                      'legend_marker_scale': 1.,
                      'legend_location': 2,
                      'legend_bbox_to_anchor': (1.05, 1.),
                      'legend_border_axes_pad': 1.,
                      'legend_n_columns': 1,
                      'legend_horizontal_spacing': 1.,
                      'legend_vertical_spacing': 1.,
                      'legend_border': True,
                      'legend_border_padding': 0.5,
                      'legend_shadow': False,
                      'legend_rounded_corners': True}
    figure_options = {'x_scale': 1.,
                      'y_scale': 1.,
                      'render_axes': True,
                      'axes_font_name': 'serif',
                      'axes_font_size': 10,
                      'axes_font_style': 'normal',
                      'axes_font_weight': 'normal',
                      'axes_x_limits': None,
                      'axes_y_limits': None}
    grid_options = {'render_grid': True,
                    'grid_line_style': '--',
                    'grid_line_width': 0.5}
    image_options = {'alpha': 1.,
                     'interpolation': 'bilinear',
                     'cmap_name': 'gray'}
    rendering_dict = {'lines': lines_options,
                      'markers': markers_options,
                      'numbering': numbering_options,
                      'legend': legend_options,
                      'figure': figure_options,
                      'grid': grid_options
                      'image': image_options}
    renderer_options = [rendering_dict, rendering_dict]
    
  • labels_per_object (list of list or None, optional) – A list that contains a list of labels for each object. Those labels are employed by the ColourSelectionWidget. An example for which this option is useful is in the case we wish to create rendering options for multiple LandmarkGroup objects and each one of them has a different set of labels. If None, then labels_per_object is a list of lenth n_objects with None.
  • selected_object (int, optional) – The object for which to show the rendering options in the beginning, when the widget is created.
  • object_selection_dropdown_visible (bool, optional) – Controls the visibility of the object selection dropdown (self.object_selection_dropdown).
  • 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.2cm', margin=0, tabs_box_style=None, tabs_border_visible=True, tabs_border_color='black', tabs_border_style='solid', tabs_border_width=1, tabs_border_radius=1, tabs_padding=0, tabs_margin=0, font_family='', font_size=None, font_style='', font_weight='')[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.
  • tabs_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
  • tabs_border_visible (bool, optional) – Defines whether to draw the border line around the tab widgets.
  • tabs_border_color (str, optional) – The color of the border around the tab widgets.
  • tabs_border_style (str, optional) – The line style of the border around the tab widgets.
  • tabs_border_width (float, optional) – The line width of the border around the tab widgets.
  • tabs_border_radius (float, optional) – The radius of the corners of the box of the tab widgets.
  • tabs_padding (float, optional) – The padding around the tab widgets.
  • tabs_margin (float, optional) – The margin around the tab widgets.
  • 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'}
    
update_object_names(objects_names)[source]

Method that updates the options in the dropdown menu for selecting an object. Note that the number of objects should not change.

Parameters:objects_names (list of str) – A list with the names of the objects that will be used in the selection dropdown menu.