Python ipywidgets.Box() Examples

The following are 25 code examples of ipywidgets.Box(). 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: library.py    From qiskit-terra with Apache License 2.0 6 votes vote down vote up
def circuit_diagram_widget() -> wid.Box:
    """Create a circuit diagram widget.

    Returns:
        Output widget.
    """
    # The max circuit height corresponds to a 20Q circuit with flat
    # classical register.
    top_out = wid.Output(layout=wid.Layout(width='100%',
                                           height='auto',
                                           max_height='1000px',
                                           overflow='hidden scroll',))

    top = wid.Box(children=[top_out], layout=wid.Layout(width='100%', height='auto'))

    return top 
Example #2
Source File: ABuWGBFBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _init_widget(self):
        """构建内置的买入策略可视化组件,构造出self.factor_box"""

        from ..WidgetBu.ABuWGBuyFactor import BuyDMWidget, BuyXDWidget, BuyWDWidget
        from ..WidgetBu.ABuWGBuyFactor import BuySDWidget, BuyWMWidget, BuyDUWidget

        self.bf_array = []
        self.bf_array.append(BuyDMWidget(self))
        self.bf_array.append(BuyXDWidget(self))
        self.bf_array.append(BuyWDWidget(self))
        self.bf_array.append(BuySDWidget(self))
        self.bf_array.append(BuyWMWidget(self))
        self.bf_array.append(BuyDUWidget(self))

        # bf() call用widget组list
        children = [bf() for bf in self.bf_array]

        if self.scroll_factor_box:
            self.factor_box = widgets.Box(children=children,
                                          layout=self.factor_layout)
        else:
            # 一行显示两个,n个为一组,组装sub_children_group序列,
            sub_children_group = self._sub_children(children, len(children) / self._sub_children_group_cnt)
            sub_children_box = [widgets.HBox(sub_children) for sub_children in sub_children_group]
            self.factor_box = widgets.VBox(sub_children_box) 
Example #3
Source File: ABuWGPSBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _init_widget(self):
        """构建内置的卖出策略可视化组件,构造出self.factor_box"""

        from ..WidgetBu.ABuWGPickStock import PSPriceWidget, PSRegressAngWidget
        from ..WidgetBu.ABuWGPickStock import PSShiftDistanceWidget, PSNTopWidget
        self.ps_array = []
        self.ps_array.append(PSPriceWidget(self))
        self.ps_array.append(PSRegressAngWidget(self))
        self.ps_array.append(PSShiftDistanceWidget(self))
        self.ps_array.append(PSNTopWidget(self))

        #  ps() call用widget组list
        children = [ps() for ps in self.ps_array]
        if self.scroll_factor_box:
            self.factor_box = widgets.Box(children=children,
                                          layout=self.factor_layout)
        else:
            # 一行显示两个,3个为一组,组装sub_children_group序列,
            sub_children_group = self._sub_children(children, len(children) / self._sub_children_group_cnt)
            sub_children_box = [widgets.HBox(sub_children) for sub_children in sub_children_group]
            self.factor_box = widgets.VBox(sub_children_box)
        # 买入因子是特殊的存在,都需要买入因子的全局数据
        self.buy_factor_manger = None 
Example #4
Source File: ABuWGPosBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _init_widget(self):
        """构建内置的仓位资金管理可视化组件,构造出self.factor_box"""

        from ..WidgetBu.ABuWGPosition import AtrPosWidget, KellyPosWidget, PtPosition
        self.pos_array = []
        self.pos_array.append(AtrPosWidget(self))
        self.pos_array.append(KellyPosWidget(self))
        self.pos_array.append(PtPosition(self))

        #  ps() call用widget组list
        children = [pos() for pos in self.pos_array]
        if self.scroll_factor_box:
            self.factor_box = widgets.Box(children=children,
                                          layout=self.factor_layout)
        else:
            # 一行显示两个,n个为一组,组装sub_children_group序列,
            sub_children_group = self._sub_children(children, len(children) / self._sub_children_group_cnt)
            sub_children_box = [widgets.HBox(sub_children) for sub_children in sub_children_group]
            self.factor_box = widgets.VBox(sub_children_box)
        # 买入因子是特殊的存在,都需要买入因子的全局数据
        self.buy_factor_manger = None 
Example #5
Source File: ABuWGTLTool.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, tool_set):
        """初始化技术分析界面"""
        super(WidgetTLTool, self).__init__(tool_set)

        rs_box = self.init_rs_ui()
        jump_box = self.init_jump_ui()
        pair_speed = self.init_pair_speed_ui()
        shift_distance = self.init_shift_distance_ui()
        regress = self.init_regress_ui()
        golden = self.init_golden_line_ui()
        skeleton = self.init_skeleton_ui()

        children = [rs_box, jump_box, pair_speed, shift_distance, regress, golden, skeleton]
        if self.scroll_factor_box:
            tl_box = widgets.Box(children,
                                 layout=self.scroll_widget_layout)
            # 需要再套一层VBox,不然外部的tab显示有问题
            self.widget = widgets.VBox([tl_box])
        else:
            # 一行显示两个,2个为一组,组装sub_children_group序列,
            sub_children_group = self._sub_children(children, len(children) / self._sub_children_group_cnt)
            sub_children_box = [widgets.HBox(sub_children) for sub_children in sub_children_group]
            self.widget = widgets.VBox(sub_children_box) 
Example #6
Source File: ABuProgress.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def init_ui_progress(self):
        """初始化ui进度条"""
        if not self.show_progress:
            return

        if not ABuEnv.g_is_ipython or self._total < 2:
            return

        if ABuEnv.g_main_pid == os.getpid():
            # 如果是在主进程下显示那就直接来
            self.progress_widget = FloatProgress(value=0, min=0, max=100)
            self.text_widget = Text('pid={} begin work'.format(os.getpid()))
            self.progress_box = Box([self.text_widget, self.progress_widget])
            display(self.progress_box)
        else:
            if g_show_ui_progress and g_socket_fn is not None:
                # 子进程下通过socket通信将pid给到主进程,主进程创建ui进度条
                ABuOsUtil.socket_send_msg(g_socket_fn, '{}|init'.format(os.getpid()))

    # 不管ui进度条有什么问题,也不能影响任务工作的进度执行,反正有文字进度会始终显示 
Example #7
Source File: variable_inspector.py    From lantern with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        self._sc = Sidecar(title='Variables')
        get_ipython().user_ns_hidden['widgets'] = widgets
        get_ipython().user_ns_hidden['NamespaceMagics'] = NamespaceMagics

        self.closed = False
        self.namespace = NamespaceMagics()
        self.namespace.shell = get_ipython().kernel.shell

        self._box = widgets.Box()
        self._box.layout.overflow_y = 'scroll'
        self._table = widgets.HTML(value='Not hooked')
        self._box.children = [self._table]

        self._ipython = get_ipython()
        self._ipython.events.register('post_run_cell', self._fill) 
Example #8
Source File: compute.py    From notebook-molecular-visualization with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        from .docker import DockerConfig
        from .interfaces import InterfaceStatus
        from .visualization import MdtExtensionConfig

        self.interface_status = InterfaceStatus()
        self.compute_config = DockerConfig()
        self.nbextension_config = MdtExtensionConfig()
        self.changelog = ChangeLog()
        self.tab_list = StyledTab([ipy.Box(),
                                   self.nbextension_config,
                                   self.interface_status,
                                   self.compute_config,
                                   self.changelog])
        self.tab_list.set_title(0, '^')
        self.tab_list.set_title(1, 'Notebook config')
        self.tab_list.set_title(2, "Interfaces")
        self.tab_list.set_title(3, 'Docker config')
        self.tab_list.set_title(4, "What's new")
        self.children = [self.make_header(), self.tab_list]
        super().__init__(children=self.children) 
Example #9
Source File: options.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def widget(self):
        import ipywidgets

        def handler(change):
            self.set(change.new)

        input = self._widget()
        input.observe(handler, "value")
        self._widgets.add(input)

        label = ipywidgets.HTML(
            "<p style='font-weight: bold; margin-right: 8px'>%s:</p>" % self.label
        )

        row = ipywidgets.Box(
            children=[label, input],
            layout=ipywidgets.Layout(
                display="flex", flex_flow="row wrap", justify_content="space-between"
            ),
        )

        return row 
Example #10
Source File: options.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _widget(self):
        if not hasattr(self, "_cached_widget"):
            try:
                import ipywidgets

                children = [ipywidgets.HTML("<h2>Cluster Options</h2>")]
                children.extend([f.widget() for f in self._fields.values()])
                column = ipywidgets.Box(
                    children=children,
                    layout=ipywidgets.Layout(
                        display="flex", flex_flow="column", align_items="stretch"
                    ),
                )
                widget = ipywidgets.Box(children=[column])
            except ImportError:
                widget = None
            object.__setattr__(self, "_cached_widget", widget)
        return self._cached_widget 
Example #11
Source File: jobs_widget.py    From qiskit-ibmq-provider with Apache License 2.0 5 votes vote down vote up
def jobs_tab(backend: Union[IBMQBackend, FakeBackend]) -> wid.HBox:
    """Construct a widget containing job information for an input backend.

    Args:
        backend: Input backend.

    Returns:
        An widget containing job summary.
    """
    title = wid.HTML('<h4>Click graph to display jobs</h4>')
    table = wid.HTML('', layout=wid.Layout(max_height='500px',
                                           height='500px',
                                           width='100%',
                                           overflow='hidden scroll',))

    sun_wid = _job_summary(backend)
    sun_wid._table = table
    sun_wid._title = title

    left = wid.Box(children=[sun_wid],
                   layout=wid.Layout(width='40%',
                                     overflow='hidden hidden'))

    right = wid.VBox(children=[title, table],
                     layout=wid.Layout(width='60%',
                                       overflow='hidden hidden'))

    out = wid.HBox(children=[left, right],
                   layout=wid.Layout(max_height='500px',
                                     margin='10px'))
    return out 
Example #12
Source File: provider_buttons.py    From qiskit-ibmq-provider with Apache License 2.0 5 votes vote down vote up
def provider_buttons(providers: List[str]) -> wid.VBox:
    """Generate a collection of provider buttons for a backend.

    When one of these buttons is clicked, the code to get the particular
    provider is copied to the clipboard.

    Args:
        providers: A list of provider names.

    Returns:
        A widget with provider buttons.
    """
    vbox_buttons = []
    for pro in providers:
        button = wid.Box(children=[vue.Btn(color='#f5f5f5', small=True,
                                           children=[pro],
                                           style_="font-family: Arial,"
                                                  "sans-serif; font-size:10px;")],
                         layout=wid.Layout(margin="0px 0px 2px 0px",
                                           width='350px'))

        button.children[0].on_event('click', _copy_text)
        vbox_buttons.append(button)

    return wid.VBox(children=vbox_buttons,
                    layout=wid.Layout(width='350px',
                                      max_width='350px')) 
Example #13
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 #14
Source File: components.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def __init__(self, mol):
        self.mol = mol

        self.toolpane = VBox()
        self.viewer = self.VIEWERTYPE(mol, width=self.VIEWERWIDTH)

        self.subtools = ipy.Box()
        self.viewer_pane = VBox([self.viewer, self.subtools])
        self.main_pane = HBox([self.viewer_pane, self.toolpane])

        super().__init__([self.main_pane]) 
Example #15
Source File: configurator.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def __init__(self, paramlist, paramdefs, title=None):
        super(Configurator, self).__init__(layout=ipy.Layout(display='flex',
                                                             flex_flow='column',
                                                             align_self='flex-start',
                                                             align_items='stretch',
                                                             max_width='100%'))
        self.paramlist = paramlist
        self.paramdefs = paramdefs

        self.apply_button = ipy.Button(description='Apply')
        self.apply_button.on_click(self.apply_values)

        self.reset_button = ipy.Button(description='Reset')
        self.reset_button.on_click(self.reset_values)
        self.buttons = ipy.Box([self.reset_button, self.apply_button],
                               layout=ipy.Layout(align_self='center'))

        self.selectors = collections.OrderedDict([(p.name, ParamSelector(p)) for p in paramdefs])
        self.reset_values()

        title = utils.if_not_none(title, 'Configuration')
        self.title = ipy.HTML('<center><h4>%s</h4></center><hr>' % title,
                              align_self='center')

        self.currentconfig = ipy.Textarea(description='<i>Current params</i>',
                                          disabled=True,
                                          value=self._pretty_print_config(),
                                          layout=ipy.Layout(width='350px', min_height='300px',
                                                            max_height='500px',
                                                            display='flex', flex_flow='column'))
        self.middle = HBox([VBox(list(self.selectors.values())), self.currentconfig])
        self.children = [self.title, self.middle, self.buttons] 
Example #16
Source File: logwidget.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def _capture_logging_displays(display=False, **kwargs):
    global _current_tabs, _prev_tabs
    _prev_tabs = _current_tabs
    if widgets_enabled:
        _current_tabs = LoggingTabs(OrderedDict(x=ipy.Box()), display=display,
                                    **wu.process_widget_kwargs(kwargs))
    else:
        _current_tabs = None
        enable_logging_widgets(False)
        print('Failed to create UI logging system. Logging widgets disabled') 
Example #17
Source File: ABuProgress.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, a_pid):
        """通过进程pid初始化ui组件"""
        self.progress_widget = FloatProgress(value=0, min=0, max=100)
        self.text_widget = Text('pid={} begin work'.format(a_pid))
        # 通过box容器都放到一个里面
        self.progress_box = Box([self.text_widget, self.progress_widget])
        display(self.progress_box) 
Example #18
Source File: test_widget_box.py    From pySINDy with MIT License 5 votes vote down vote up
def test_construction_invalid_style(self):
        with self.assertRaises(TraitError):
            widgets.Box(box_style='invalid') 
Example #19
Source File: test_widget_box.py    From pySINDy with MIT License 5 votes vote down vote up
def test_construction_style(self):
        box = widgets.Box(box_style='warning')
        assert box.get_state()['box_style'] == 'warning' 
Example #20
Source File: test_widget_box.py    From pySINDy with MIT License 5 votes vote down vote up
def test_construction_with_children(self):
        html = widgets.HTML('some html')
        slider = widgets.IntSlider()
        box = widgets.Box([html, slider])
        children_state = box.get_state()['children']
        assert children_state == [
            widgets.widget._widget_to_json(html, None),
            widgets.widget._widget_to_json(slider, None),
        ] 
Example #21
Source File: ABuWGSFBase.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def _init_widget(self):
        """构建内置的卖出策略可视化组件,构造出self.factor_box"""

        from ..WidgetBu.ABuWGSellFactor import SellXDWidget, SellAtrNStopWidget, SellCloseAtrNWidget
        from ..WidgetBu.ABuWGSellFactor import SellPreAtrNWidget, SellDMWidget, SellNDWidget

        self.sf_array = []
        self.sf_array.append(SellAtrNStopWidget(self))
        self.sf_array.append(SellCloseAtrNWidget(self))
        self.sf_array.append(SellPreAtrNWidget(self))
        self.sf_array.append(SellXDWidget(self))
        self.sf_array.append(SellDMWidget(self))
        self.sf_array.append(SellNDWidget(self))

        # sf() call用widget组list
        children = [sf() for sf in self.sf_array]
        if self.scroll_factor_box:
            self.factor_box = widgets.Box(children=children,
                                          layout=self.factor_layout)
        else:
            # 一行显示两个,3个为一组,组装sub_children_group序列,
            sub_children_group = self._sub_children(children, len(children) / self._sub_children_group_cnt)
            sub_children_box = [widgets.HBox(sub_children) for sub_children in sub_children_group]
            self.factor_box = widgets.VBox(sub_children_box)

        # 买入因子是特殊的存在,都需要买入因子的全局数据
        self.buy_factor_manger = None 
Example #22
Source File: test_widget_box.py    From pySINDy with MIT License 5 votes vote down vote up
def test_construction(self):
        box = widgets.Box()
        assert box.get_state()['children'] == [] 
Example #23
Source File: ABuWGToolBase.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        """初始化基础设置界面"""

        mdm_box = self.init_env_set_ui()
        tm_box = self.init_time_mode_ui()
        self.sc = WidgetSymbolChoice()
        self.sc.cs_tip.value = u'如果股池为空,将使用示例的symbol进行分析'
        # 默认1年的数据分析
        self.run_years.value = 1
        # self.widget = widgets.Box([self.sc.widget, tm_box, mdm_box], layout=self.widget_layout)
        self.widget = widgets.VBox([self.sc.widget, tm_box, mdm_box]) 
Example #24
Source File: dashboard.py    From qiskit-ibmq-provider with Apache License 2.0 4 votes vote down vote up
def build_dashboard_widget() -> AccordionWithThread:
    """Build the dashboard widget.

    Returns:
        Dashboard widget.
    """
    tabs = wid.Tab(layout=wid.Layout(width='760px',
                                     max_height='650px')
                   )

    devices = wid.VBox(children=[],
                       layout=wid.Layout(width='740px',
                                         height='100%')
                       )

    device_list = wid.Box(children=[devices], layout=wid.Layout(width='auto',
                                                                max_height='600px'
                                                                ))

    jobs_box = wid.VBox(layout=wid.Layout(max_width='740px',
                                          min_width='740px',
                                          justify_content='flex-start'))
    tabs.children = [device_list, jobs_box]
    tabs.set_title(0, 'Devices')
    tabs.set_title(1, 'Jobs')

    acc = AccordionWithThread(children=[tabs],
                              layout=wid.Layout(width='auto',
                                                max_height='700px',
                                                ))

    acc._device_list = acc.children[0].children[0].children[0]

    acc.set_title(0, 'IQX Dashboard')
    acc.selected_index = None
    acc.layout.visibility = 'hidden'
    display(acc)
    acc._dom_classes = ['job_widget']
    display(Javascript("""$('div.job_widget')
        .detach()
        .appendTo($('#header'))
        .css({
            'z-index': 999,
             'position': 'fixed',
            'box-shadow': '5px 5px 5px -3px black',
            'opacity': 0.95,
            'float': 'left,'
        })
        """))
    acc.layout.visibility = 'visible'
    return acc 
Example #25
Source File: visuals.py    From python-esppy with Apache License 2.0 4 votes vote down vote up
def createContent(self):
        if self.hasOpt("center"):
            self._map.center = self.getOpt("center")
        if self.hasOpt("zoom"):
            self._map.zoom = self.getOpt("zoom")

        self._lat = self.getOpt("lat")
        if self._lat == None:
            raise Exception("you must specify the lat property")

        self._lon = self.getOpt("lon")
        if self._lon == None:
            raise Exception("you must specify the lon property")

        #if len(self._circles) > 0:
            #for o in self._circles:
                #self._map.add_layer(o["layers"])

        #if len(self._polygons) > 0:
            #for o in self._polygons:
                #self._map.add_layer(o["layers"])

        self._colors = None

        if self.hasOpt("colormap"):
            self._colors = tools.Colors(colormap=self.getOpt("colormap"))
        elif self.hasOpt("colors"):
            self._colors = tools.Colors(colors=self.getOpt("colors"))
        else:
            self._colors = self._visuals._colors

        if self._colors != None:
            if self.hasOpt("color_range"):
                range = self.getOpt("color_range")
                self._colorRange = tools.ColorRange(self._colors,range[0],range[1])

        components = []

        components.append(self._banner)

        colorbar = None

        if self.hasOpt("color"):
            #data = go.Scatter(x=[None],y=[None],marker=dict(colorscale=self._visuals._colors.colorscale,showscale=True,cmin=-5,cmax=5,colorbar=dict(xpad=0,ypad=0,ticks="")))
            data = go.Scatter(x=[None],y=[None],marker=dict(colorscale=self._visuals._colors.colorscale,showscale=True,colorbar=dict(thickness=30)))
            layout = dict(xaxis=dict(visible=False),yaxis=dict(visible=False),showlegend=False)
            #self._colorbar = go.FigureWidget(data=data,layout=layout)
            #colorbar = widgets.Box([self._colorbar],layout=widgets.Layout(width="150px",margin="0px",padding="0px"))

        if colorbar != None:
            components.append(widgets.HBox([self._map,colorbar]))
        else:
            components.append(self._map)

        self.children = components