Python ipywidgets.IntText() Examples

The following are 8 code examples of ipywidgets.IntText(). 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: 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 #2
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.IntText(value=self.value)
        else:
            return ipywidgets.BoundedIntText(
                value=self.value,
                min=self.min or -(2 ** 63),
                max=self.max or (2 ** 63 - 1),
            ) 
Example #3
Source File: ABuWGSellFactor.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def _init_widget(self):
        """构建AbuFactorSellNDay策略参数界面"""
        self.description = widgets.Textarea(
            value=u'持有N天后卖出策略:\n'
                  u'卖出策略,不管交易现在什么结果,买入后只持有N天\n'
                  u'需要与特定\'买入策略\'形成配合\n,'
                  u'单独使用N天卖出策略意义不大',
            description=u'N天卖出',
            disabled=False,
            layout=self.description_layout
        )
        sell_n_label = widgets.Label(u'设定买入后只持有天数,默认1', layout=self.label_layout)
        self.sell_n = widgets.IntText(
            value=1,
            description=u'N天',
            disabled=False
        )
        sell_n_box = widgets.VBox([sell_n_label, self.sell_n])

        is_sell_today_label = widgets.Label(u'设定买入n天后,当天还是隔天卖出', layout=self.label_layout)
        self.is_sell_today = widgets.Dropdown(
            options={u'N天后隔天卖出': False, u'N天后当天卖出': True},
            value=False,
            description=u'当天隔天:',
        )
        is_sell_today_box = widgets.VBox([is_sell_today_label, self.is_sell_today])

        self.widget = widgets.VBox([self.description, sell_n_box, is_sell_today_box, self.add_box],
                                   # border='solid 1px',
                                   layout=self.widget_layout) 
Example #4
Source File: ABuWGPickStock.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def _init_widget(self):
        """构建AbuPickStockNTop策略参数界面"""
        self.description = widgets.Textarea(
            value=u'涨跌幅top N选股因子策略:\n'
                  u'选股周期上对多只股票涨跌幅进行排序,选取top n个股票做为交易目标:\n'
                  u'(只对在股池中选定的symbol序列生效,对全市场回测暂时不生效)\n',
            description=u'top N涨跌',
            disabled=False,
            layout=self.description_layout
        )

        n_top_label = widgets.Label(u'设定选取top个交易目标数量,默认3', layout=self.label_layout)
        self.n_top = widgets.IntText(
            value=3,
            description=u'TOP N',
            disabled=False
        )
        self.n_top_box = widgets.VBox([n_top_label, self.n_top])

        direction_top_label1 = widgets.Label(u'direction_top参数的意义为选取方向:', layout=self.label_layout)
        direction_top_label2 = widgets.Label(u'默认值为正:即选取涨幅最高的n_top个股票', layout=self.label_layout)
        direction_top_label3 = widgets.Label(u'可设置为负:即选取跌幅最高的n_top个股票', layout=self.label_layout)
        self.direction_top = widgets.Dropdown(
            options={u'正(涨幅)': 1, u'负(跌幅)': -1},
            value=1,
            description=u'选取方向:',
        )
        self.direction_top_box = widgets.VBox([direction_top_label1, direction_top_label2, direction_top_label3,
                                               self.direction_top])

        self.widget = widgets.VBox([self.description, self.n_top_box, self.direction_top_box,
                                    self.xd_box, self.reversed_box, self.add_box],
                                   # border='solid 1px',
                                   layout=self.widget_layout) 
Example #5
Source File: client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _widget(self):
        """ Create IPython widget for display within a notebook """
        try:
            return self._cached_widget
        except AttributeError:
            pass

        if self.asynchronous:
            return None

        try:
            from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML, Accordion
        except ImportError:
            self._cached_widget = None
            return None

        layout = Layout(width="150px")

        title = HTML("<h2>GatewayCluster</h2>")

        status = HTML(self._widget_status(), layout=Layout(min_width="150px"))

        request = IntText(0, description="Workers", layout=layout)
        scale = Button(description="Scale", layout=layout)

        minimum = IntText(0, description="Minimum", layout=layout)
        maximum = IntText(0, description="Maximum", layout=layout)
        adapt = Button(description="Adapt", layout=layout)

        accordion = Accordion(
            [HBox([request, scale]), HBox([minimum, maximum, adapt])],
            layout=Layout(min_width="500px"),
        )
        accordion.selected_index = None
        accordion.set_title(0, "Manual Scaling")
        accordion.set_title(1, "Adaptive Scaling")

        @scale.on_click
        def scale_cb(b):
            with log_errors():
                self.scale(request.value)

        @adapt.on_click
        def adapt_cb(b):
            self.adapt(minimum=minimum.value, maximum=maximum.value)

        name = HTML("<p><b>Name: </b>{0}</p>".format(self.name))

        elements = [title, HBox([status, accordion]), name]

        if self.dashboard_link is not None:
            link = HTML(
                '<p><b>Dashboard: </b><a href="{0}" target="_blank">{0}'
                "</a></p>\n".format(self.dashboard_link)
            )
            elements.append(link)

        self._cached_widget = box = VBox(elements)
        self._status_widget = status

        return box 
Example #6
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 #7
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 #8
Source File: ABuWGPickStock.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuPickRegressAngMinMax策略参数界面"""

        self.description = widgets.Textarea(
            value=u'拟合角度选股因子策略:\n'
                  u'将交易目标前期走势进行线性拟合计算一个角度,选中规则:\n'
                  u'1. 交易目标前期走势拟合角度 > 最小拟合角度\n'
                  u'2. 交易目标前期走势拟合角度 < 最大拟合角度\n',
            description=u'角度选股',
            disabled=False,
            layout=self.description_layout
        )

        self.ang_min_label = widgets.Label(u'设定选股角度最小阀值,默认-5', layout=self.label_layout)
        self.ang_min_float = widgets.IntText(
            value=-5,
            description=u'最小:',
            disabled=False
        )
        self.ang_min_ck = widgets.Checkbox(
            value=True,
            description=u'使用最小阀值',
            disabled=False
        )

        def ang_min_ck_change(change):
            self.ang_min_float.disabled = not change['new']

        self.ang_min_ck.observe(ang_min_ck_change, names='value')
        self.ang_min_box = widgets.VBox([self.ang_min_label, self.ang_min_ck, self.ang_min_float])

        self.ang_max_label = widgets.Label(u'设定选股角度最大阀值,默认5', layout=self.label_layout)
        self.ang_max_float = widgets.IntText(
            value=5,
            description=u'最大:',
            disabled=False
        )
        self.ang_max_ck = widgets.Checkbox(
            value=True,
            description=u'使用最大阀值',
            disabled=False
        )

        def ang_max_ck_change(change):
            self.ang_max_float.disabled = not change['new']

        self.ang_max_ck.observe(ang_max_ck_change, names='value')
        self.ang_max_box = widgets.VBox([self.ang_max_label, self.ang_max_ck, self.ang_max_float])

        self.widget = widgets.VBox([self.description, self.ang_min_box, self.ang_max_box,
                                    self.xd_box, self.reversed_box, self.add_box],
                                   # border='solid 1px',
                                   layout=self.widget_layout)