LandmarkOptionsWidget

class menpo.visualize.widgets.LandmarkOptionsWidget(landmark_options, render_function=None, update_function=None, style='minimal')[source]

Bases: FlexBox

Creates a widget for animating through a list of objects. The widget consists of the following parts from IPython.html.widgets:

No Object Variable (self.) Description
1 Latex no_landmarks_msg

Message in case there are

no landmarks available.

2 Checkbox render_landmarks_checkbox Render landmarks
3 Box landmarks_checkbox_and_msg_box Contains 2, 1
4 Dropdown group_dropdown Landmark group selector
5 ToggleButtons labels_toggles

list of lists with

the labels per group

6 Latex labels_text Labels title text
7 HBox labels_box Contains all 5
8 HBox labels_and_text_box Contains 6, 7
9 VBox group_and_labels_and_text_box Contains 4, 8

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() and replace_update_function() methods.
Parameters:
  • landmark_options (dict) –

    The dictionary with the initial options. For example

    landmark_options = {'has_landmarks': True,
                        'render_landmarks': True,
                        'group_keys': ['PTS', 'ibug_face_68'],
                        'labels_keys': [['all'], ['jaw', 'eye']],
                        'group': 'PTS',
                        'with_labels': ['all']}
    
  • render_function (function or None, optional) – The render function that is executed when a widgets’ value changes. If None, then nothing is assigned.
  • update_function (function or None, optional) – The update function that is executed when the index value changes. If None, then nothing is assigned.
  • style (str (see below)) –

    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 landmarks widget and then update its state. Firstly, we need to import it:

>>> from from menpo.visualize.widgets import LandmarkOptionsWidget
>>> 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 index:

>>> from menpo.visualize import print_dynamic
>>> def render_function(name, value):
>>>     s = "Group: {}, Labels: {}".format(
>>>         wid.selected_values['group'],
>>>         wid.selected_values['with_labels'])
>>>     print_dynamic(s)

Create the widget with some initial options and display it:

>>> landmark_options = {'has_landmarks': True,
>>>                     'render_landmarks': True,
>>>                     'group_keys': ['PTS', 'ibug_face_68'],
>>>                     'labels_keys': [['all'], ['jaw', 'eye', 'mouth']],
>>>                     'group': 'ibug_face_68',
>>>                     'with_labels': ['eye', 'jaw', 'mouth']}
>>> wid = LandmarkOptionsWidget(landmark_options,
>>>                              render_function=render_function,
>>>                              style='danger')
>>> display(wid)

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

>>> new_options = {'has_landmarks': True,
>>>                'render_landmarks': True,
>>>                'group_keys': ['new_group'],
>>>                'labels_keys': [['1', '2', '3']],
>>>                'group': 'new_group',
>>>                'with_labels': None}
>>> 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.
add_update_function(update_function)[source]

Method that adds an update_function() to the widget. The signature of the given function is also stored in self._update_function.

Parameters:update_function (function or None, optional) – The update 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.

remove_update_function()[source]

Method that removes the current self._update_function() from the widget and sets self._update_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.
replace_update_function(update_function)[source]

Method that replaces the current self._update_function() of the widget with the given update_function().

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

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

Parameters:
  • landmark_options (dict) –

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

    landmark_options = {'has_landmarks': True,
                        'render_landmarks': True,
                        'group_keys': ['PTS', 'ibug_face_68'],
                        'labels_keys': [['all'], ['jaw', 'eye']],
                        'group': 'PTS',
                        'with_labels': ['all']}
    
  • 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='', labels_buttons_style='')[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'}
    
  • labels_buttons_style (See Below, optional) –

    Style options

    Style Description
    ‘primary’ Blue-based style
    ‘success’ Green-based style
    ‘info’ Blue-based style
    ‘warning’ Yellow-based style
    ‘danger’ Red-based style
    ‘’ Default style
    None No style