TextPrintWidget

class menpo.visualize.widgets.TextPrintWidget(n_lines, text_per_line, style='minimal')[source]

Bases: FlexBox

Creates a widget for printing text. Specifically, it consists of a list of IPython.html.widgets.Latex objects, i.e. one per text line.

Note that:

  • 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.
Parameters:
  • n_lines (int) – The number of lines of the text to be printed.
  • text_per_line (list of length n_lines) – The text to be printed per line.
  • 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 text widget and then update its state. Firstly, we need to import it:

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

Create the widget with some initial options and display it:

>>> n_lines = 3
>>> text_per_line = ['> The', '> Menpo', '> Team']
>>> wid = TextPrintWidget(n_lines, text_per_line, style='success')
>>> display(wid)

The style of the widget can be changed as:

>>> wid.predefined_style('danger')

Update the widget state as:

>>> wid.set_widget_state(5, ['M', 'E', 'N', 'P', 'O'])
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
set_widget_state(n_lines, text_per_line)[source]

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

Parameters:
  • n_lines (int) – The number of lines of the text to be printed.
  • text_per_line (list of length n_lines) – The text to be printed per line.
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'}