/usr/lib/python2.7/dist-packages/ipywidgets/widgets/widget_float.py is in python-ipywidgets 5.2.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | """Float class.
Represents an unbounded float using a widget.
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from .domwidget import DOMWidget
from .widget import register
from .trait_types import Color
from traitlets import (Unicode, CFloat, Bool, Int, CaselessStrEnum,
Tuple, TraitError, validate)
class _Float(DOMWidget):
value = CFloat(0.0, help="Float value").tag(sync=True)
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
description = Unicode(help="Description of the value this widget represents").tag(sync=True)
_model_module = Unicode('jupyter-js-widgets').tag(sync=True)
_view_module = Unicode('jupyter-js-widgets').tag(sync=True)
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_Float, self).__init__(**kwargs)
class _BoundedFloat(_Float):
max = CFloat(100.0, help="Max value").tag(sync=True)
min = CFloat(0.0, help="Min value").tag(sync=True)
step = CFloat(0.1, help="Minimum step to increment the value (ignored by some views)").tag(sync=True)
@validate('value')
def _validate_value(self, proposal):
"""Cap and floor value"""
value = proposal['value']
if self.min > value or self.max < value:
value = min(max(value, self.min), self.max)
return value
@validate('min')
def _validate_min(self, proposal):
"""Enforce min <= value <= max"""
min = proposal['value']
if min > self.max:
raise TraitError('Setting min > max')
if min > self.value:
self.value = min
return min
@validate('max')
def _validate_max(self, proposal):
"""Enforce min <= value <= max"""
max = proposal['value']
if max < self.min:
raise TraitError('setting max < min')
if max < self.value:
self.value = max
return max
@register('Jupyter.FloatText')
class FloatText(_Float):
""" Displays a float value within a textbox. For a textbox in
which the value must be within a specific range, use BoundedFloatText.
Parameters
----------
value : float
value displayed
description : str
description displayed next to the text box
color : str Unicode color code (eg. '#C13535')
color of the value displayed
"""
_view_name = Unicode('FloatTextView').tag(sync=True)
_model_name = Unicode('FloatTextModel').tag(sync=True)
@register('Jupyter.BoundedFloatText')
class BoundedFloatText(_BoundedFloat):
""" Displays a float value within a textbox. Value must be within the range specified.
For a textbox in which the value doesn't need to be within a specific range, use FloatText.
Parameters
----------
value : float
value displayed
min : float
minimal value of the range of possible values displayed
max : float
maximal value of the range of possible values displayed
description : str
description displayed next to the textbox
color : str Unicode color code (eg. '#C13535')
color of the value displayed
"""
_view_name = Unicode('FloatTextView').tag(sync=True)
_model_name = Unicode('FloatTextModel').tag(sync=True)
@register('Jupyter.FloatSlider')
class FloatSlider(_BoundedFloat):
""" Slider/trackbar of floating values with the specified range.
Parameters
----------
value : float
position of the slider
min : float
minimal position of the slider
max : float
maximal position of the slider
step : float
step of the trackbar
description : str
name of the slider
orientation : {'horizontal', 'vertical'}
default is 'horizontal', orientation of the slider
readout : {True, False}
default is True, display the current value of the slider next to it
readout_format : str
default is '.2f', specifier for the format function used to represent
slider value for human consumption, modeled after Python 3's format
specification mini-language (PEP 3101).
slider_color : str Unicode color code (eg. '#C13535')
color of the slider
color : str Unicode color code (eg. '#C13535')
color of the value displayed (if readout == True)
"""
_view_name = Unicode('FloatSliderView').tag(sync=True)
_model_name = Unicode('FloatSliderModel').tag(sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
default_value='horizontal', help="Vertical or horizontal.").tag(sync=True)
_range = Bool(False, help="Display a range selector").tag(sync=True)
readout = Bool(True, help="Display the current value of the slider next to it.").tag(sync=True)
readout_format = Unicode('.2f', help="Format for the readout").tag(sync=True)
slider_color = Color(None, allow_none=True).tag(sync=True)
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
@register('Jupyter.FloatProgress')
class FloatProgress(_BoundedFloat):
""" Displays a progress bar.
Parameters
-----------
value : float
position within the range of the progress bar
min : float
minimal position of the slider
max : float
maximal position of the slider
step : float
step of the progress bar
description : str
name of the progress bar
orientation : {'horizontal', 'vertical'}
default is 'horizontal', orientation of the progress bar
bar_style: {'success', 'info', 'warning', 'danger', ''}
color of the progress bar, default is '' (blue)
colors are: 'success'-green, 'info'-light blue, 'warning'-orange, 'danger'-red
"""
_view_name = Unicode('ProgressView').tag(sync=True)
_model_name = Unicode('ProgressModel').tag(sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
default_value='horizontal', help="Vertical or horizontal.").tag(sync=True)
bar_style = CaselessStrEnum(
values=['success', 'info', 'warning', 'danger', ''],
default_value='', allow_none=True, help="""Use a predefined styling for
the progess bar.""").tag(sync=True)
class _FloatRange(_Float):
value = Tuple(CFloat(), CFloat(), default_value=(0.0, 1.0),
help="Tuple of (lower, upper) bounds").tag(sync=True)
@property
def lower(self):
return self.value[0]
@lower.setter
def lower(self, lower):
self.value = (lower, self.value[1])
@property
def upper(self):
return self.value[1]
@upper.setter
def upper(self, upper):
self.value = (self.value[0], upper)
@validate('value')
def _validate_value(self, proposal):
lower, upper = proposal['value']
if upper < lower:
raise TraitError('setting lower > upper')
return lower, upper
class _BoundedFloatRange(_FloatRange):
step = CFloat(1.0, help="Minimum step that the value can take (ignored by some views)").tag(sync=True)
max = CFloat(100.0, help="Max value").tag(sync=True)
min = CFloat(0.0, help="Min value").tag(sync=True)
def __init__(self, *args, **kwargs):
min, max = kwargs.get('min', 0.0), kwargs.get('max', 100.0)
if not kwargs.get('value', None):
kwargs['value'] = (0.75 * min + 0.25 * max,
0.25 * min + 0.75 * max)
super(_BoundedFloatRange, self).__init__(*args, **kwargs)
@validate('min', 'max')
def _validate_bounds(self, proposal):
trait = proposal['trait']
new = proposal['value']
if trait.name == 'min' and new > self.max:
raise TraitError('setting min > max')
if trait.name == 'max' and new < self.min:
raise TraitError('setting max < min')
if trait.name == 'min':
self.value = (max(new, self.value[0]), max(new, self.value[1]))
if trait.name == 'max':
self.value = (min(new, self.value[0]), min(new, self.value[1]))
return new
@validate('value')
def _validate_value(self, proposal):
lower, upper = super(_BoundedFloatRange, self)._validate_value(proposal)
lower, upper = min(lower, self.max), min(upper, self.max)
lower, upper = max(lower, self.min), max(upper, self.min)
return lower, upper
@register('Jupyter.FloatRangeSlider')
class FloatRangeSlider(_BoundedFloatRange):
""" Slider/trackbar that represents a pair of floats bounded by minimum and maximum value.
Parameters
----------
value : float tuple
range of the slider displayed
min : float
minimal position of the slider
max : float
maximal position of the slider
step : float
step of the trackbar
description : str
name of the slider
orientation : {'horizontal', 'vertical'}
default is 'horizontal'
readout : {True, False}
default is True, display the current value of the slider next to it
readout_format : str
default is '.2f', specifier for the format function used to represent
slider value for human consumption, modeled after Python 3's format
specification mini-language (PEP 3101).
slider_color : str Unicode color code (eg. '#C13535')
color of the slider
color : str Unicode color code (eg. '#C13535')
color of the value displayed (if readout == True)
"""
_view_name = Unicode('FloatSliderView').tag(sync=True)
_model_name = Unicode('FloatSliderModel').tag(sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
default_value='horizontal', help="Vertical or horizontal.").tag(sync=True)
_range = Bool(True, help="Display a range selector").tag(sync=True)
readout = Bool(True, help="Display the current value of the slider next to it.").tag(sync=True)
slider_color = Color(None, allow_none=True).tag(sync=True)
continuous_update = Bool(True, help="Update the value of the widget as the user is sliding the slider.").tag(sync=True)
|