Python ipywidgets.Checkbox() Examples

The following are 17 code examples of ipywidgets.Checkbox(). 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: ABuWGPSBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _pick_stock_base_ui(self):
        """选股策略中通用ui: xd, reversed初始构建"""
        xd_tip = widgets.Label(u'设置选股策略生效周期,默认252天',
                               layout=widgets.Layout(width='300px', align_items='stretch'))
        self.xd = widgets.IntSlider(
            value=252,
            min=1,
            max=252,
            step=1,
            description=u'周期',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.xd_box = widgets.VBox([xd_tip, self.xd])

        reversed_tip = widgets.Label(u'反转选股结果,默认不反转',
                                     layout=widgets.Layout(width='300px', align_items='stretch'))
        self.reversed = widgets.Checkbox(
            value=False,
            description=u'反转结果',
            disabled=False,
        )
        self.reversed_box = widgets.VBox([reversed_tip, self.reversed]) 
Example #2
Source File: data.py    From jupyter-innotater with MIT License 5 votes vote down vote up
def _create_widget(self):
        return Checkbox(description=self.desc, layout=self.layout, disabled=self.disabled) 
Example #3
Source File: TSEBIPythonInterface.py    From pyTSEB with GNU General Public License v3.0 5 votes vote down vote up
def calc_row_options(self):
        '''Widgets for canopy in rows'''

        self.w_row = widgets.Checkbox(
            description='Canopy in rows?', value=self.row)
        self.w_rowaz = widgets.BoundedFloatText(
            value=self.row_az,
            min=0,
            max=360,
            description='Row orientation',
            width=80)
        self.w_rowaz.visible = False 
Example #4
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_single_value_bool():
    for a in (True, False):
        c = interactive(f, a=a)
        w = c.children[0]
        check_widget(w,
            cls=widgets.Checkbox,
            description='a',
            value=a,
        ) 
Example #5
Source File: widget.py    From altair_widgets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _controllers_for(opt):
    """
    Give a string representing the parameter represented, find the appropriate
    command.

    """
    colors = [None, "blue", "red", "green", "black"]
    controllers = {
        "type": widgets.Dropdown(
            options=["auto detect"] + _get_types(), description="type"
        ),
        "bin": widgets.Checkbox(description="bin"),
        "aggregate": widgets.Dropdown(
            options=[None] + _get_functions(), description="aggregate"
        ),
        "zero": widgets.Checkbox(description="zero"),
        "text": widgets.Text(description="text value"),
        "scale": widgets.Dropdown(options=["linear", "log"], description="scale"),
        "color": widgets.Dropdown(options=colors, description="main color"),
        "applyColorToBackground": widgets.Checkbox(
            description="applyColorToBackground"
        ),
        "shortTimeLabels": widgets.Checkbox(description="shortTimeLabels"),
    }

    for title, controller in controllers.items():
        controller.title = title
        if "Checkbox" in str(controller):
            # traits = dir(controller.layout)
            # traits = [t for t in traits if t[0] != '_']
            controller.layout.max_width = "200ex"
            # controller.layout.min_width = '100ex'
            # controller.layout.width = '150ex'

    return controllers[opt] 
Example #6
Source File: initialize.py    From qkit with GNU General Public License v2.0 5 votes vote down vote up
def crop_recording_window(self):
        self._sample.mspec.spec_stop()
        self._sample.mspec.set_averages(1e4)
        self._sample.mspec.set_window(0,512)
        self._sample.mspec.set_segments(1)
        msp = self._sample.mspec.acquire()
        
        def pltfunc(start,end,done):
            if done:
                self._sample.acqu_window = [start,end]
                self._sample.mspec.set_window(start,end)
                self._sw.disabled = True
                self._ew.disabled = True
                self._dw.disabled = True
                self._dw.description = "acqu_window set to [{:d}:{:d}]".format(start,end)
            else:
                plt.figure(figsize=(15,5))
                plt.plot(msp)
                plt.axvspan(0,start,color='k',alpha=.2)
                plt.axvspan(end,len(msp),color='k',alpha=.2)
                plt.xlim(0,len(msp))
                plt.show()
        self._sw =  widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[0],continuous_update=True)
        self._ew = widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[1],continuous_update=True)
        self._dw = widgets.Checkbox(value=False,description="Done!",indent=True)
        self._wgt = widgets.interact(pltfunc,start=self._sw,end=self._ew,done=self._dw)
        self._sample.mspec.set_window(*self._sample.acqu_window) 
Example #7
Source File: cad_display.py    From jupyter-cadquery with Apache License 2.0 5 votes vote down vote up
def create_checkbox(self, kind, description, value, handler):
        checkbox = Checkbox(value=value, description=description, indent=False)
        checkbox.observe(handler, "value")
        checkbox.add_class("view_%s" % kind)
        return checkbox 
Example #8
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

        return ipywidgets.Checkbox(value=self.value, indent=False) 
Example #9
Source File: docker.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.client = None
        self.warning = ipy.HTML(description='<b>Engine status:</b>', value=SPINNER)
        self.devmode_label = ipy.Label('Use local docker images (developer mode)',
                                       layout=ipy.Layout(width='100%'))
        self.devmode_button = ipy.Checkbox(value=mdt.compute.config.devmode,
                                           layout=ipy.Layout(width='15px'))
        self.devmode_button.observe(self.set_devmode, 'value')

        self.engine_config_description = ipy.HTML('Docker host with protocol and port'
                                                  ' (e.g., <code>http://localhost:2375</code>).'
                                                  ' If blank, this'
                                                  ' defaults to the docker engine configured at '
                                                  'your command line.',
                                                  layout=ipy.Layout(width='100%'))
        self.engine_config_value = ipy.Text('blank', layout=ipy.Layout(width='100%'))
        self.engine_config_value.add_class('nbv-monospace')

        self.image_box = ipy.Box()

        self._reset_config_button = ipy.Button(description='Reset',
                                               tooltip='Reset to applied value')
        self._apply_changes_button = ipy.Button(description='Apply',
                                                tooltip='Apply for this session')
        self._save_changes_button = ipy.Button(description='Make default',
                                               tooltip='Make this the default for new sessions')
        self._reset_config_button.on_click(self.reset_config)
        self._apply_changes_button.on_click(self.apply_config)
        self._save_changes_button.on_click(self.save_config)

        self.children = [self.warning,
                         VBox([self.engine_config_description,
                               self.engine_config_value]),
                         HBox([self._reset_config_button,
                               self._apply_changes_button,
                               self._save_changes_button]),
                         HBox([self.devmode_button, self.devmode_label]),
                         self.image_box]
        self.reset_config()
        super().__init__(children=self.children)
        self.connect_to_engine() 
Example #10
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _widgets(self):
        dfrange = [0, self._f]
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:",
            layout=iwgt.Layout(width='50%'))
        w_play = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_play, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.strm_f.event, x=w_frame)
        uidrange = [0, self._u]
        w_select = iwgt.IntRangeSlider(
            value=self._cur_sel,
            min=uidrange[0],
            max=uidrange[1],
            continuous_update=False,
            description="Unit ID:",
            layout=iwgt.Layout(width='50%'))
        w_select.observe(self._set_sel, names='value')
        w_update = iwgt.Button(description="Update")
        w_update.on_click(self._update_plot)
        w_update_mov = iwgt.Checkbox(
            value=self._update_mov, description="Update Movies")
        w_update_mov.observe(self._set_update, names='value')
        w_overlay = iwgt.Checkbox(value=self._overlay, description="Overlay")
        w_overlay.observe(self._set_overlay, names='value')
        return iwgt.VBox([
            iwgt.HBox([w_frame, w_play, w_update_mov]),
            iwgt.HBox([w_select, w_update, w_overlay])
        ]) 
Example #11
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _spatial_all_wgt(self):
        wgt_useAC = pnwgt.Checkbox(
            name='UseAC', value=self._useAC, width=120, height=15)
        def callback_useAC(val):
            self._useAC = val.new
            self.update_AC()
        wgt_useAC.param.watch(callback_useAC, 'value')
        return pn.layout.WidgetBox(wgt_useAC, width=150) 
Example #12
Source File: ABuWGSMTool.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def init_distances_ui(self):
        """距离分析ui"""

        with self._init_widget_list_action(self.distances_analyse, u'距离分析', -1) as widget_list:
            self.distances_mode = widgets.RadioButtons(
                options={u'曼哈顿距离(L1范数)': 0, u'欧式距离(L2范数)': 1, u'余弦距离': 2},
                value=0,
                description=u'距离模式:',
                disabled=False
            )
            widget_list.append(self.distances_mode)

            scale_end_label = widgets.Label(u'对结果矩阵进行标准化处理', layout=self.label_layout)
            self.scale_end = widgets.Checkbox(
                value=True,
                description=u'标准化',
                disabled=False
            )
            scale_end_box = widgets.VBox([scale_end_label, self.scale_end])
            widget_list.append(scale_end_box)

            similar_tip_label = widgets.Label(u'对结果矩阵进行转换相关性', layout=self.label_layout)
            self.to_similar = widgets.Checkbox(
                value=False,
                description=u'转换相关',
                disabled=False
            )
            to_similar_box = widgets.VBox([similar_tip_label, self.to_similar])
            widget_list.append(to_similar_box)

        return widgets.VBox(widget_list,  # border='solid 1px',
                            layout=self.tool_layout) 
Example #13
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) 
Example #14
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) 
Example #15
Source File: visualization.py    From minian with GNU General Public License v3.0 4 votes vote down vote up
def _man_wgt(self):
        usub = self.strm_usub.usub
        usub.sort()
        usub.reverse()
        ulabs = self.unit_labels.sel(unit_id=usub).values
        wgt_sel = {uid: pnwgt.Select(
            name='Unit Label', options=usub+[-1]+ulabs.tolist(),
            value=ulb, height=50, width=100) for uid, ulb in zip(usub, ulabs)}
        def callback_ulab(value, uid):
            self.unit_labels.loc[uid] = value.new
        for uid, sel in wgt_sel.items():
            cb = fct.partial(callback_ulab, uid=uid)
            sel.param.watch(cb, 'value')
        wgt_check = {uid: pnwgt.Checkbox(
            name='Unit ID: {}'.format(uid), value=False,
            height=50, width=100) for uid in usub}
        def callback_chk(val, uid):
            if not val.old == val.new:
                if val.new:
                    self.usub_sel.append(uid)
                else:
                    self.usub_sel.remove(uid)
        for uid, chk in wgt_check.items():
            cb = fct.partial(callback_chk, uid=uid)
            chk.param.watch(cb, 'value')
        wgt_discard = pnwgt.Button(
            name='Discard Selected',
            button_type='primary', width=200)
        def callback_discard(clicks):
            for uid in self.usub_sel:
                wgt_sel[uid].value = -1
        wgt_discard.param.watch(callback_discard, 'clicks')
        wgt_merge = pnwgt.Button(
            name='Merge Selected',
            button_type='primary', width=200)
        def callback_merge(clicks):
            for uid in self.usub_sel:
                wgt_sel[uid].value = self.usub_sel[0]
        wgt_merge.param.watch(callback_merge, 'clicks')
        return pn.layout.Column(
            pn.layout.WidgetBox(wgt_discard, wgt_merge, width=200),
            pn.layout.Row(
                pn.layout.WidgetBox(*wgt_check.values(), width=100),
                pn.layout.WidgetBox(*wgt_sel.values(), width=100))) 
Example #16
Source File: nbwidgets.py    From msticpy with MIT License 4 votes vote down vote up
def __init__(
        self,
        env_var: str,
        help_str: str = None,
        prompt: str = "Enter the value: ",
        auto_display: bool = False,
    ):
        """
        Create a new instance of GetEnvironmentKey.

        Parameters
        ----------
        env_var : str
            Name of the environment variable.
        help_str : str, optional
            Help to display if the environment variable is not set. (the default is None)
        prompt : str, optional
            Prompt to display with the text box.
            (the default is "Enter the value: ")
        auto_display : bool, optional
            Whether to display on instantiation (the default is False)

        """
        self._value = os.environ.get(env_var)
        self._name = env_var

        if not self._value:
            display(widgets.HTML(value=help_str))

        self._w_text = widgets.Text(
            value=self._value,
            description=prompt,
            layout=Layout(width="50%"),
            style={"description_width": "initial"},
        )

        self._w_save_button = widgets.Button(
            description="Set",
            layout=Layout(width="10%", disabled=False),
            style={"description_width": "initial"},
        )
        self._w_check_save = widgets.Checkbox(
            value=True, description="Save as environment var", disabled=False
        )
        self._w_save_button.on_click(self._on_save_button_clicked)
        self._hbox = widgets.HBox(
            [self._w_text, self._w_save_button, self._w_check_save]
        )

        if auto_display:
            self.display() 
Example #17
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")