コード例 #1
0
    def _update_ipython_widget(self, value=None):
        """
        Update the progress bar to the given value (out of a total
        given to the constructor).

        This method is for use in the IPython notebook 2+.
        """

        # Create and display an empty progress bar widget,
        # if none exists.
        if not hasattr(self, '_widget'):
            # Import only if an IPython widget, i.e., widget in iPython NB
            if ipython_major_version < 4:
                from IPython.html import widgets
                self._widget = widgets.FloatProgressWidget()
            else:
                from ipywidgets import widgets
                self._widget = widgets.FloatProgress()
            from IPython.display import display

            display(self._widget)
            self._widget.value = 0

        # Calculate percent completion, and update progress bar
        frac = (value / self._total)
        self._widget.value = frac * 100
        self._widget.description = ' ({:>6.2%})'.format(frac)
コード例 #2
0
ファイル: gui.py プロジェクト: astrofrog/reducer
    def __init__(self, *args, **kwd):
        super(ToggleGo, self).__init__(*args, **kwd)
        self._go_container = widgets.HBox(visible=self.toggle.value)
        self._go_button = widgets.Button(description="Lock settings and Go!",
                                         disabled=True, visible=False)
        self._change_settings = widgets.Button(description="Unlock settings",
                                               disabled=True,
                                               visible=False)
        self._go_container.children = [self._go_button, self._change_settings]
        self._progress_container = widgets.Box()
        self._progress_bar = widgets.FloatProgress(min=0, max=1.0,
                                                   step=0.01, value=0.0,
                                                   visible=False)
        self._progress_container.children = [self._progress_bar]
        # we want the go button to be in a container below the
        #  ToggleContainer's container -- actually, no, want these
        # buttons controlled by toggle...wait, no, I really do want that, but
        # I also want to tie their visibility to the toggle.
        kids = list(self.children)
        kids.append(self._go_container)
        kids.append(self._progress_container)
        self.children = kids

        # Tie visibility of go button to toggle state. Needs to be separate
        # from the container.
        link((self._go_container, str('visible')), (self.toggle, str('value')))

        self._go_button.on_click(self.go())
        self._change_settings.on_click(self.unlock())

        # Tie self._state_monitor to both go button and color of toggle button
        self._state_monitor.on_trait_change(self.state_change_handler(),
                                            str('value'))
        self._state_monitor.on_trait_change(set_color_for(self), str('value'))
コード例 #3
0
    def _update_ipython_widget(self, value=None):
        """
        Update the progress bar to the given value (out of a total
        given to the constructor).

        This method is for use in the IPython notebook 2+.
        """

        # Create and display an empty progress bar widget,
        # if none exists.
        if not hasattr(self, '_widget'):
            # Import only if an IPython widget, i.e., widget in iPython NB
            if ipython_major_version < 4:
                self._widget = widgets.FloatProgressWidget()
            else:
                self._widget = widgets.FloatProgress()

            if is_widgets_available():
                display(self._widget)
            self._widget.value = 0

        # Calculate percent completion, and update progress bar
        percent = (float(value)/self._total) * 100.0
        self._widget.value = percent
        self._widget.description =' ({0:>6s}%)'.format('{0:.2f}'.format(percent))