Python ipywidgets.Accordion() Examples

The following are 10 code examples of ipywidgets.Accordion(). 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: 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 #2
Source File: map.py    From ipygee with MIT License 5 votes vote down vote up
def handle_object_inspector(self, **change):
        """ Handle function for the Object Inspector Widget

        DEPRECATED
        """
        event = change['type'] # event type
        thewidget = change['widget']
        if event == 'click':  # If the user clicked
            # Clear children // Loading
            thewidget.children = [HTML('wait a second please..')]
            thewidget.set_title(0, 'Loading...')

            widgets = []
            i = 0

            for name, obj in self.EELayers.items(): # for every added layer
                the_object = obj['object']
                try:
                    properties = the_object.getInfo()
                    wid = create_accordion(properties) # Accordion
                    wid.selected_index = None # this will unselect all
                except Exception as e:
                    wid = HTML(str(e))
                widgets.append(wid)
                thewidget.set_title(i, name)
                i += 1

            thewidget.children = widgets 
Example #3
Source File: map.py    From ipygee with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        desc = 'Select one or more layers'
        super(CustomInspector, self).__init__(description=desc, **kwargs)
        self.selector = SelectMultiple()
        self.main = Accordion()
        self.children = [self.selector, self.main] 
Example #4
Source File: logs.py    From dask-cloudprovider with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _widget(self):
        from ipywidgets import Accordion

        accordion = Accordion(children=[log._widget() for log in self.values()])
        [accordion.set_title(i, title) for i, title in enumerate(self.keys())]
        return accordion 
Example #5
Source File: ipytools.py    From geebap with GNU General Public License v3.0 5 votes vote down vote up
def info2map(map):
    """ Add an information Tab to a map displayed with `geetools.ipymap`
    module

    :param map: the Map where the tab will be added
    :type map: geetools.ipymap.Map
    :return:
    """
    try:
        from ipywidgets import Accordion
    except:
        print('Cannot use ipytools without ipywidgets installed\n'
              'ipywidgets.readthedocs.io')

    map.addTab('BAP Inspector', info_handler, Accordion()) 
Example #6
Source File: job_widgets.py    From qiskit-terra with Apache License 2.0 5 votes vote down vote up
def build_job_viewer():
    """Builds the job viewer widget

    Returns:
        widget: Job viewer.
    """
    acc = widgets.Accordion(children=[widgets.VBox(layout=widgets.Layout(max_width='710px',
                                                                         min_width='710px'))],
                            layout=widgets.Layout(width='auto',
                                                  max_width='750px',
                                                  max_height='500px',
                                                  overflow_y='scroll',
                                                  overflow_x='hidden'))
    acc.set_title(0, 'IBMQ Jobs')
    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 #7
Source File: ri_client.py    From qkit with GNU General Public License v2.0 5 votes vote down vote up
def control_panel(ric = None):
    from ipywidgets import Button, HTML,HBox,Accordion
    from IPython.core.display import display
    def fmt(inp):
        if inp is None:
            return "--"
        elif type(inp) is float:
            return "{:.4g}".format(inp)
        else:
            return str(inp)

    if ric is None:
        ric = qkit.ric

    def update_instrument_params(b):
        insdict = ric.get_all_instrument_params()
        for ins in sorted(insdict):
            if not ins in b.accordions:
                b.accordions[ins] = Accordion()
            table = "<table style='line-height:180%'>"  # <tr style='font-weight:bold'><td> Parameter </td><td>Value</td></tr>
            for p in sorted(insdict[ins]):
                table += "<tr><td style='text-align:right;padding-right:10px'>" + str(p) + "</td><td>" + fmt(insdict[ins][p][0]) + insdict[ins][p][
                    1] + "</td></tr>"
            table += """</table>"""
            b.accordions[ins].children = [HTML(table)]
            b.accordions[ins].set_title(0, ins)
        for child in b.accordions.keys():
            if child not in insdict:
                del b.accordions[child]
        b.hbox.children = b.accordions.values()

    update_button = Button(description="Update")
    update_button.on_click(update_instrument_params)
    update_button.accordions = {}
    update_button.hbox = HBox()
    stop_button = Button(description="Stop measurement")
    stop_button.on_click(lambda b: qkit.ric.stop_measure())
    stop_button.button_style = "danger"
    update_instrument_params(update_button)
    display(HBox([update_button,stop_button]),update_button.hbox) 
Example #8
Source File: dashboard.py    From qiskit-ibmq-provider with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 children: Optional[List] = None,
                 **kwargs: Any):
        """AccordionWithThread constructor.

        Args:
            children: A list of widgets to be attached to the accordion.
            **kwargs: Additional keywords to be passed to ``ipywidgets.Accordion``.
        """
        children = children or []
        super(AccordionWithThread, self).__init__(children=children, **kwargs)
        self._thread = None
        # Devices VBox.
        self._device_list = None  # type: Optional[wid.VBox] 
Example #9
Source File: preview.py    From ipygee with MIT License 4 votes vote down vote up
def image(image, region=None, visualization=None, name=None,
          dimensions=(500, 500), do_async=None):
    """ Preview an Earth Engine Image """
    if do_async is None:
        do_async = CONFIG.get('do_async')

    start = time()

    if name:
        label = '{} (Image)'.format(name)
        loading = 'Loading {} preview...'.format(name)
    else:
        label = 'Image Preview'
        loading = 'Loading preview...'

    formatdimension = "x".join([str(d) for d in dimensions])

    wid = Accordion([Label(loading)])
    wid.set_title(0, loading)

    def compute(image, region, visualization):
        if not region:
            region = tools.geometry.getRegion(image)
        else:
            region = tools.geometry.getRegion(region)
        params = dict(dimensions=formatdimension, region=region)
        if visualization:
            params.update(visualization)
        url = image.getThumbURL(params)
        req = requests.get(url)
        content = req.content
        rtype = req.headers['Content-type']
        if rtype in ['image/jpeg', 'image/png']:
            img64 = base64.b64encode(content).decode('utf-8')
            src = '<img src="data:image/png;base64,{}"></img>'.format(img64)
            result = HTML(src)
        else:
            result = Label(content.decode('utf-8'))

        return result

    def setAccordion(acc):
        widget = compute(image, region, visualization)
        end = time()
        elapsed = end-start
        acc.children = [widget]
        elapsed = utils.format_elapsed(elapsed)
        acc.set_title(0, '{} [{}]'.format(label, elapsed))

    if do_async:
        thread = threading.Thread(target=setAccordion, args=(wid,))
        thread.start()
    else:
        setAccordion(wid)

    return wid 
Example #10
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