AnimationOptionsWidget¶
-
class
menpo.visualize.widgets.
AnimationOptionsWidget
(index, render_function=None, update_function=None, index_style='buttons', interval=0.5, description='Index: ', minus_description='-', plus_description='+', loop_enabled=True, text_editable=True, 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 and menpo.visualize.widgets.tools:
No Object Variable (self.) Description 1 ToggleButton play_stop_toggle The play/stop button 2 ToggleButton play_options_toggle Button that toggles
the options menu
3 Checkbox loop_checkbox Repeat mode 4 FloatText interval_text Interval (secs) 5 VBox loop_interval_box Contains 3, 4 6 VBox play_options_box Contains 2, 5 7 HBox animation_box Contains 1, 6 8 IndexButtonsWidget
IndexSliderWidget
index_wid The index selector
widget
Note that:
- The selected values are stored in the
self.selected_values
dict. - To set the styling please refer to the
style()
andpredefined_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()
andreplace_update_function()
methods.
Parameters: - index (dict) –
The dictionary with the initial options. For example
index = {'min': 0, 'max': 100, 'step': 1, 'index': 10}
- render_function (function or
None
, optional) – The render function that is executed when a widgets’ value changes. IfNone
, then nothing is assigned. - update_function (function or
None
, optional) – The update function that is executed when the index value changes. IfNone
, then nothing is assigned. - index_style ({
'buttons'
,'slider'
}, optional) – If'buttons'
, then IndexButtonsWidget() class is called. If'slider'
, then ‘IndexSliderWidget()’ class is called. - interval (float, optional) – The interval between the animation progress.
- description (str, optional) – The title of the widget.
- minus_description (str, optional) – The title of the button that decreases the index.
- plus_description (str, optional) – The title of the button that increases the index.
- loop_enabled (bool, optional) – If
True
, then after reach the minimum (maximum) index values, the counting will continue from the end (beginning). IfFalse
, the counting will stop at the minimum (maximum) value. - text_editable (bool, optional) – Flag that determines whether the index text will be editable.
- 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 an animation widget and then update its state. Firstly, we need to import it:
>>> from menpo.visualize.widgets import AnimationOptionsWidget >>> 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 = "Selected index: {}".format(wid.selected_values['index']) >>> print_dynamic(s)
Create the widget with some initial options and display it:
>>> index = {'min': 0, 'max': 100, 'step': 1, 'index': 10} >>> wid = AnimationOptionsWidget(index, index_style='buttons', >>> render_function=render_function, >>> style='info') >>> display(wid)
By pressing the buttons (or simply pressing the Play button), the printed message gets updated. Finally, let’s change the widget status with a new dictionary of options:
>>> new_options = {'min': 0, 'max': 20, 'step': 2, 'index': 16} >>> 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. IfNone
, 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. IfNone
, 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. IfNone
, 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. IfNone
, then nothing is happening.
-
set_widget_state
(index, allow_callback=True)[source]¶ Method that updates the state of the widget with a new set of values.
Parameters: - index (dict) –
The dictionary with the new options to be used. For example
index = {'min': 0, 'max': 100, 'step': 1, 'index': 10}
- allow_callback (bool, optional) – If
True
, it allows triggering of any callback functions.
- index (dict) –
-
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='')[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'}
- box_style (See Below, optional) –
- The selected values are stored in the