Python ipywidgets.SelectMultiple() Examples

The following are 9 code examples of ipywidgets.SelectMultiple(). 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: selection.py    From notebook-molecular-visualization with Apache License 2.0 6 votes vote down vote up
def __init__(self, mol):
        super().__init__(mol)

        self._atomset = collections.OrderedDict()

        self.atom_listname = ipy.Label('Selected atoms:', layout=ipy.Layout(width='100%'))
        self.atom_list = ipy.SelectMultiple(options=list(self.viewer.selected_atom_indices),
                                            layout=ipy.Layout(height='150px'))
        traitlets.directional_link(
            (self.viewer, 'selected_atom_indices'),
            (self.atom_list, 'options'),
            self._atom_indices_to_atoms
        )

        self.select_all_atoms_button = ipy.Button(description='Select all atoms')
        self.select_all_atoms_button.on_click(self.select_all_atoms)

        self.select_none = ipy.Button(description='Clear all selections')
        self.select_none.on_click(self.clear_selections)

        self.representation_buttons = ipy.ToggleButtons(options=['stick','ribbon', 'auto', 'vdw'],
                                                        value='auto')
        self.representation_buttons.observe(self._change_representation, 'value') 
Example #2
Source File: selection.py    From notebook-molecular-visualization with Apache License 2.0 6 votes vote down vote up
def __init__(self, mol):
        super().__init__(mol)

        self._bondset = collections.OrderedDict()
        self._drawn_bond_state = set()

        self.bond_listname = ipy.Label('Selected bonds:', layout=ipy.Layout(width='100%'))
        self.bond_list = ipy.SelectMultiple(options=list(),
                                            layout=ipy.Layout(height='150px'))
        self.viewer.observe(self._update_bondlist, 'selected_atom_indices')

        self.atom_list.observe(self.remove_bondlist_highlight, 'value')

        self.subtools.children = [HBox([self.select_all_atoms_button,
                                        self.select_none])]
        self.toolpane.children = (self.atom_listname,
                                  self.atom_list,
                                  self.bond_listname,
                                  self.bond_list) 
Example #3
Source File: selection.py    From notebook-molecular-visualization with Apache License 2.0 6 votes vote down vote up
def __init__(self, mol):
        super().__init__(mol)

        self.selection_type = ipy.Dropdown(description='Clicks select:',
                                           value=self.viewer.selection_type,
                                           options=('Atom', 'Residue', 'Chain'))

        traitlets.link((self.selection_type, 'value'), (self.viewer, 'selection_type'))

        self.residue_listname = ipy.Label('Selected residues:', layout=ipy.Layout(width='100%'))
        self.residue_list = ipy.SelectMultiple(options=list(), height='150px')
        self.viewer.observe(self._update_reslist, 'selected_atom_indices')

        self.residue_list.observe(self.remove_atomlist_highlight, 'value')
        self.atom_list.observe(self.remove_reslist_highlight, 'value')

        self.subtools.children = [self.representation_buttons]
        self.subtools.layout.flex_flow = 'column'
        self.toolpane.children = [self.selection_type,
                                  HBox([self.select_all_atoms_button, self.select_none]),
                                  self.atom_listname,
                                  self.atom_list,
                                  self.residue_listname,
                                  self.residue_list] 
Example #4
Source File: ABuWGBFBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def subscriber_ui(self, labels):
        """
        构建订阅的已添加的买入策略ui初始化
        :param labels: list序列内部对象str用来描述解释
        """
        # 添加针对指定买入策略的卖出策略
        self.accordion = widgets.Accordion()
        buy_factors_child = []
        for label in labels:
            buy_factors_child.append(widgets.Label(label,
                                                   layout=widgets.Layout(width='300px', align_items='stretch')))
        self.buy_factors = widgets.SelectMultiple(
            options=[],
            description=u'已添加的买入策略:',
            disabled=False,
            layout=widgets.Layout(width='100%', align_items='stretch')
        )
        buy_factors_child.append(self.buy_factors)
        buy_factors_box = widgets.VBox(buy_factors_child)
        self.accordion.children = [buy_factors_box] 
Example #5
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_multiple_selection():
    smw = widgets.SelectMultiple

    # degenerate multiple select
    w = smw()
    check_widget(w, value=tuple())

    # don't accept random other value when no options
    with nt.assert_raises(TraitError):
        w.value = (2,)
    check_widget(w, value=tuple())

    # basic multiple select
    w = smw(options=[(1, 1)], value=[1])
    check_widget(w, cls=smw, value=(1,), options=((1, 1),))

    # don't accept random other value
    with nt.assert_raises(TraitError):
        w.value = w.value + (2,)
    check_widget(w, value=(1,))

    # change options, which resets value
    w.options = w.options + ((2, 2),)
    check_widget(w, options=((1, 1), (2,2)), value=())

    # change value
    w.value = (1,2)
    check_widget(w, value=(1, 2))

    # dict style
    w.options = {1: 1}
    check_widget(w, options={1:1})

    # updating
    with nt.assert_raises(TraitError):
        w.value = (2,)
    check_widget(w, options={1:1}) 
Example #6
Source File: replay.py    From jupyter-cadquery with Apache License 2.0 5 votes vote down vote up
def replay(cad_obj, index=0, debug=False, cad_width=600, height=600):
    r = Replay(debug, cad_width, height)
    
    if isinstance(cad_obj, cq.Workplane):
        workplane = cad_obj
    elif is_cqparts_part(cad_obj):
        workplane = convert_cqparts(cad_obj, replay=True)
    else:
        print("Cannot replay", cad_obj)
        return None

    r.stack = r.format_steps(r.to_array(workplane, result_name=getattr(workplane, "name", None)))
    r.indexes = [index]

    r.select_box = SelectMultiple(
        options=["[%02d] %s" % (i, code) for i, (code, obj) in enumerate(r.stack)],
        index=r.indexes,
        rows=len(r.stack),
        description='',
        disabled=False,
        layout=Layout(width="600px"))
    r.select_box.add_class("monospace")
    r.select_box.observe(r.select_handler)
    display(HBox([r.select_box, r.debug_output]))

    r.select(r.indexes)
    return r


#
# Control functions to enable, disable and reset replay
# 
Example #7
Source File: ABuWGBase.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, show_add_buy=True, add_button_style='default'):
        self.factor_dict = {}
        self.factor_wg_array = []
        # 策略候选池可x轴左右滚动
        self.factor_layout = widgets.Layout(overflow_x='scroll',
                                            # flex_direction='row',
                                            display='flex')
        self.selected_factors = widgets.SelectMultiple(
            options=[],
            description=u'已添加策略:',
            disabled=False,
            layout=widgets.Layout(width='100%', align_items='stretch')
        )
        # 已添加的全局策略可点击删除
        self.selected_factors.observe(self.remove_factor, names='value')
        # 全局策略改变通知接收序列
        self.selected_factors_obs = set()
        self.factor_box = None
        # 默认不启动可滚动因子界面,因为对外的widget版本以及os操作系统不统一
        self.scroll_factor_box = False
        self._sub_children_group_cnt = 3
        self.show_add_buy = show_add_buy
        self.add_button_style = add_button_style
        # 构建具体子类的界面构建
        self._init_widget()
        if self.factor_box is None:
            raise RuntimeError('_init_widget must build factor_box!')
        self.widget = widgets.VBox([self.factor_box, self.selected_factors]) 
Example #8
Source File: ABuWGBase.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, search_result_callable):
        """构建股票池选股ui界面"""
        if not callable(search_result_callable):
            raise TypeError('search_result_select_func must callable!')
        # symbol搜索框构建
        self.search_bt = widgets.Button(description=u'搜索:', layout=widgets.Layout(height='10%', width='7%'))
        self.search_input = widgets.Text(
            value='',
            placeholder=u'交易代码/公司名称/拼音首字母',
            description='',
            disabled=False
        )
        self.search_input.observe(self._search_input_change, names='value')

        # symbol搜索结果框
        self.search_result = widgets.SelectMultiple(
            options=[],
            description=u'搜索结果:',
            disabled=False,
            layout=widgets.Layout(width='300px', align_items='stretch', justify_content='space-between')
        )
        self.search_result.observe(search_result_callable, names='value')
        self.search_bt.on_click(self._do_search)

        # 搜索框 + 按钮 + 结果框 box拼接
        sc_hb = widgets.HBox([self.search_bt, self.search_input])
        self.widget = widgets.VBox([sc_hb, self.search_result])

    # noinspection PyUnusedLocal 
Example #9
Source File: ABuWGUmp.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def _init_predict_ui(self):
        """裁判预测拦截界面初始化"""
        description = widgets.Textarea(
            value=u'裁判预测拦截:\n'
                  u'通过在\'裁判特征训练\'选中\'指定的裁判,选中的裁判将在对应的\n'
                  u'回测中生效,即开始在回测中对交易进行预测拦截等智能交易干涉行为',

            disabled=False,
            layout=widgets.Layout(height='150px')
        )
        # ump已选框
        self.choice_umps = widgets.SelectMultiple(
            description=u'已选裁判:',
            disabled=False,
            layout=widgets.Layout(width='100%', align_items='stretch')
        )
        self.choice_umps.observe(self.remove_ump_select, names='value')

        self.umps = widgets.SelectMultiple(
            description=u'备选裁判:',
            disabled=False,
            layout=widgets.Layout(width='100%', align_items='stretch')
        )
        self.umps.observe(self.on_ump_select, names='value')
        self.load_train_ump(self.umps)

        return widgets.VBox([description, self.choice_umps, self.umps])