Python ipywidgets.FloatText() Examples

The following are 10 code examples of ipywidgets.FloatText(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ipywidgets , or try the search function .
Example #1
Source File: TSEBIPythonInterface.py    From pyTSEB with GNU General Public License v3.0 6 votes vote down vote up
def define_site_description_time_series(self):
        '''Widgets for site description parameters'''

        self.w_lat = widgets.BoundedFloatText(
            value=self.lat, min=-90, max=90, description='Lat.', width=100)
        self.w_lon = widgets.BoundedFloatText(
            value=self.lon, min=-180, max=180, description='Lon.', width=100)
        self.w_alt = widgets.FloatText(
            value=self.alt, description='Alt.', width=100)
        self.w_stdlon = widgets.BoundedFloatText(
            value=self.stdlon, min=-180, max=180, description='Std. Lon.', width=100)
        self.w_z_u = widgets.BoundedFloatText(
            value=self.zu,
            min=0.001,
            description='Wind meas. height',
            width=100)
        self.w_z_T = widgets.BoundedFloatText(
            value=self.zt, min=0.001, description='T meas. height', width=100)
        self.site_page = widgets.VBox([widgets.HBox([self.w_lat,
                                                    self.w_lon,
                                                    self.w_alt,
                                                    self.w_stdlon]),
                                      widgets.HBox([self.w_z_u,
                                                    self.w_z_T])],
                                      background_color='#EEE') 
Example #2
Source File: qubit_widget.py    From scqubits with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_widget(callback_func, init_params, image_filename=None):
    """
    Displays ipywidgets for initialization of a QuantumSystem object.

    Parameters
    ----------
    callback_func: function
        callback_function depends on all the parameters provided as keys (str) in the parameter_dict, and is called upon
        changes of values inside the widgets
    init_params: {str: value, str: value, ...}
        names and values of initialization parameters
    image_filename: str, optional
        file name for circuit image to be displayed alongside the qubit
    Returns
    -------

    """
    widgets = {}
    box_list = []
    for name, value in init_params.items():
        label = ipywidgets.Label(value=name)
        if isinstance(value, float):
            enter_widget = ipywidgets.FloatText
        else:
            enter_widget = ipywidgets.IntText

        widgets[name] = enter_widget(value=value, description='', disabled=False)
        box_list.append(ipywidgets.HBox([label, widgets[name]], layout=ipywidgets.Layout(justify_content='flex-end')))

    if image_filename:
        file = open(image_filename, "rb")
        image = file.read()
        image_widget = ipywidgets.Image(value=image, format='png', layout=ipywidgets.Layout(width='400px'))
        ui_widget = ipywidgets.HBox([ipywidgets.VBox(box_list), ipywidgets.VBox([image_widget])])
    else:
        ui_widget = ipywidgets.VBox(box_list)

    out = ipywidgets.interactive_output(callback_func, widgets)
    display(ui_widget, out) 
Example #3
Source File: widgets.py    From tyssue with GNU General Public License v3.0 6 votes vote down vote up
def parameter_settings(eptm):
    specs = eptm.specs
    elements = []

    for element in ["edge", "vert", "face"]:
        if element not in specs:
            continue

        spec = specs[element]
        fts = []
        for param, val in spec.items():

            def update_param(change):
                specs[element][param] = change["new"]
                print(change)
                print("{} {} changed to {}".format(element, param, change["new"]))

            w = ipw.FloatText(val, description=param)
            w.observe(update_param, names="value")
            fts.append(w)
        elements.append(ipw.VBox(fts))

    return ipw.HBox(elements) 
Example #4
Source File: TSEBIPythonInterface.py    From pyTSEB with GNU General Public License v3.0 5 votes vote down vote up
def calc_G_options(self):
        '''Widgets for method for computing soil heat flux'''

        self.w_G_form = widgets.ToggleButtons(
            description='Select method for soil heat flux',
            options={
                'Ratio of soil net radiation': 1,
                'Constant or measured value': 0,
                'Time dependent (Santanelo & Friedl)': 2},
            value=self.G_form,
            width=300)
        self.w_Gratio = widgets.BoundedFloatText(
            value=self.Gratio, min=0, max=1, description='G ratio (G/Rn)', width=80)
        self.w_Gconstant = widgets.FloatText(
            value=self.Gconstant, description='Value (W m-2)', width=80)
        self.w_Gconstant.visible = False
        self.w_Gconstanttext = widgets.HTML(
            value="Set G value (W m-2), ignored if G is present in the input file")
        self.w_Gconstanttext.visible = False
        self.w_Gconstant.visible = False
        self.w_G_amp = widgets.BoundedFloatText(
            value=self.G_amp, min=0, max=1, description='Amplitude (G/Rn)', width=80)
        self.w_G_amp.visible = False
        self.w_G_phase = widgets.BoundedFloatText(
            value=self.G_phase, min=-24, max=24, description='Time Phase (h)', width=80)
        self.w_G_phase.visible = False
        self.w_G_shape = widgets.BoundedFloatText(
            value=self.G_shape, min=0, max=24, description='Time shape (h)', width=80)
        self.w_G_shape.visible = False 
Example #5
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_annotations():
    @annotate(n=10, f=widgets.FloatText())
    def f(n, f):
        pass

    c = interactive(f)
    check_widgets(c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatText,
        ),
    ) 
Example #6
Source File: options.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _widget(self):
        import ipywidgets

        if self.min is None and self.max is None:
            return ipywidgets.FloatText(value=self.value)
        else:
            return ipywidgets.BoundedFloatText(
                value=self.value,
                min=self.min or float("-inf"),
                max=self.max or float("inf"),
            ) 
Example #7
Source File: widgets.py    From gpkit with MIT License 4 votes vote down vote up
def create_settings(box):
    "Creates a widget Container for settings and info of a particular slider."
    _, slider, sl_units = box.children

    enable = widgets.Checkbox(value=box.visible, width="3ex")
    link((box, 'visible'), (enable, 'value'))

    def slider_link(obj, attr):
        "Function to link one object to an attr of the slider."
        # pylint: disable=unused-argument
        def link_fn(name, new_value):
            "How to update the object's value given min/max on the slider. "
            if new_value >= slider.max:
                slider.max = new_value
            # if any value is greater than the max, the max slides up
            # however, this is not held true for the minimum, because
            # during typing the max or value will grow, and we don't want
            # to permanently anchor the minimum to unfinished typing
            if attr == "max" and new_value <= slider.value:
                if slider.max >= slider.min:
                    slider.value = new_value
                else:
                    pass  # bounds nonsensical, probably because we picked up
                          # a small value during user typing.
            elif attr == "min" and new_value >= slider.value:
                slider.value = new_value
            setattr(slider, attr, new_value)
            slider.step = (slider.max - slider.min)/24.0
        obj.on_trait_change(link_fn, "value")
        link((slider, attr), (obj, "value"))

    text_html = "<span class='form-control' style='width: auto;'>"
    setvalue = widgets.FloatText(value=slider.value,
                                 description=slider.description)
    slider_link(setvalue, "value")
    fromlabel = widgets.HTML(text_html + "from")
    setmin = widgets.FloatText(value=slider.min, width="10ex")
    slider_link(setmin, "min")
    tolabel = widgets.HTML(text_html + "to")
    setmax = widgets.FloatText(value=slider.max, width="10ex")
    slider_link(setmax, "max")

    units = widgets.Label()
    units.width = "6ex"
    units.font_size = "1.165em"
    link((sl_units, 'value'), (units, 'value'))
    descr = widgets.HTML(text_html + slider.varkey.descr.get("label", ""))
    descr.width = "40ex"

    return widgets.HBox(children=[enable, setvalue, units, descr,
                                  fromlabel, setmin, tolabel, setmax],
                        width="105ex") 
Example #8
Source File: configurator.py    From notebook-molecular-visualization with Apache License 2.0 4 votes vote down vote up
def __init__(self, paramdef):
        super(ParamSelector, self).__init__(layout=ipy.Layout(display='flex',
                                                              flex_flow='nowrap',
                                                              align_content='stretch'))

        self.paramdef = paramdef

        children = []
        self.name = ipy.HTML("<p style='text-align:right'>%s:</p>" % paramdef.displayname,
                             layout=ipy.Layout(width='200px'))
        children.append(self.name)

        if paramdef.choices:
            self.selector = ipy.Dropdown(options=paramdef.choices, **self.WIDGETKWARGS)
        elif paramdef.type == bool:
            self.selector = ipy.ToggleButtons(options=[True, False], **self.WIDGETKWARGS)
        elif paramdef.units:
            self.selector = UnitText(units=paramdef.units, **self.WIDGETKWARGS)
        elif paramdef.type == float:
            self.selector = ipy.FloatText(**self.WIDGETKWARGS)
        elif paramdef.type == int:
            self.selector = ipy.IntText(**self.WIDGETKWARGS)
        elif paramdef.type == str:
            self.selector = ipy.Text(**self.WIDGETKWARGS)
        else:
            self.selector = ReadOnlyRepr(**self.WIDGETKWARGS)
        children.append(self.selector)

        children = [self.name, self.selector]

        self.default_button = None
        if paramdef.default:
            self.default_button = ipy.Button(description='Default',
                                             tooltip='Set to default: %s' % self.paramdef.default,
                                             layout=ipy.Layout(width='75px'))
            self.default_button.on_click(self.default)
            children.append(self.default_button)
            self.default()

        self.help_link = None
        if paramdef.help_url:
            self.help_link = ipy.HTML('<a href="%s" target="_blank">?</a>' % paramdef.help_url)
            children.append(self.help_link)

        self.children = children 
Example #9
Source File: ros_widgets.py    From jupyter-ros with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def add_widgets(msg_instance, widget_dict, widget_list, prefix=''):
    """
    Adds widgets.

    @param msg_type The message type
    @param widget_dict The form list
    @param widget_list The widget list

    @return widget_dict and widget_list
    """
    # import only here so non ros env doesn't block installation
    from genpy import Message
    if msg_instance._type.split('/')[-1] == 'Image':
        w = widgets.Text()
        widget_dict['img'] = w
        w_box = widgets.HBox([widgets.Label(value='Image path:'), w])
        widget_list.append(w_box)
        return widget_dict, widget_list

    for idx, slot in enumerate(msg_instance.__slots__):
        attr = getattr(msg_instance, slot)
        s_t = msg_instance._slot_types[idx]
        w = None

        if s_t in ['float32', 'float64']:
            w = widgets.FloatText()
        if s_t in ['int8', 'uint8', 'int32', 'uint32', 'int64', 'uint64']:
            w = widgets.IntText()
        if s_t in ['string']:
            w = widgets.Text()

        if isinstance(attr, Message):
            widget_list.append(widgets.Label(value=slot))
            widget_dict[slot] = {}
            add_widgets(attr, widget_dict[slot], widget_list, slot)

        if w:
            widget_dict[slot] = w
            w_box = widgets.HBox([widgets.Label(value=slot, layout=widgets.Layout(width="100px")), w])
            widget_list.append(w_box)

    return widget_dict, widget_list 
Example #10
Source File: ABuWGPickStock.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuPickStockPriceMinMax策略参数界面"""

        self.description = widgets.Textarea(
            value=u'价格选股因子策略:\n'
                  u'根据交易目标的一段时间内收盘价格的最大,最小值进行选股,选中规则:\n'
                  u'1. 交易目标最小价格 > 最小价格阀值\n'
                  u'2. 交易目标最大价格 < 最大价格阀值\n',
            description=u'价格选股',
            disabled=False,
            layout=self.description_layout
        )

        self.price_min_label = widgets.Label(u'设定选股价格最小阀值,默认15', layout=self.label_layout)
        self.price_min_float = widgets.FloatText(
            value=15,
            description=u'最小:',
            disabled=False
        )
        self.price_min_ck = widgets.Checkbox(
            value=True,
            description=u'使用最小阀值',
            disabled=False
        )

        def price_min_ck_change(change):
            self.price_min_float.disabled = not change['new']

        self.price_min_ck.observe(price_min_ck_change, names='value')
        self.price_min_box = widgets.VBox([self.price_min_label, self.price_min_ck, self.price_min_float])

        self.price_max_label = widgets.Label(u'设定选股价格最大阀值,默认50', layout=self.label_layout)
        self.price_max_float = widgets.FloatText(
            value=50,
            description=u'最大:',
            disabled=False
        )
        self.price_max_ck = widgets.Checkbox(
            value=True,
            description=u'使用最大阀值',
            disabled=False
        )

        def price_max_ck_change(change):
            self.price_max_float.disabled = not change['new']

        self.price_max_ck.observe(price_max_ck_change, names='value')
        self.price_max_box = widgets.VBox([self.price_max_label, self.price_max_ck, self.price_max_float])
        self.widget = widgets.VBox([self.description, self.price_min_box, self.price_max_box,
                                    self.xd_box, self.reversed_box, self.add_box],
                                   # border='solid 1px',
                                   layout=self.widget_layout)