Exemple #1
0
def make_selector(zs, add_row):
    t = Text(description='Query string')
    t.value = 'target-concept: GUNS'
    #     b = Button(description='+')
    #     b.on_click(add_row)
    #     d = Dropdown(values=OrderedDict((describe_field(z), z) for z in zs))
    #     c = HBox(children=(d, t))
    return t
 def user_function_panel(self):
     f = Text(description="Function, Args:")
     link((self.model, "user_f"), (f, "value"))
     fapp = Button(description="Apply")
     fapp.on_click(lambda x: self.model.apply_userf(name='Apply clicked'))
     cp2 = ControlPanel(title='User Defined Function', children=[f, fapp])
     link((self.more, "value"), (cp2, "visible"))
     return cp2
Exemple #3
0
def show_progressbar(bar, show_eta=True, force=False):
    """ shows given bar either using an ipython widget, if in
    interactive session or simply use the string format of it and print it
    to stdout.

    Parameters
    ----------
    bar : instance of pyemma.util.progressbar.ProgressBar
    show_eta : bool (optional)

    """
    currtime = time.time()
    if bar.lastupdate is not None and not force:
        dtlastupdate = currtime - bar.lastupdate
    else:
        dtlastupdate = 9999
    #if not (str(config['show_progress_bars']) == 'True' and __is_tty_or_interactive_session() and dtlastupdate > 0.5):
    if not (__is_tty_or_interactive_session() and dtlastupdate > 0.5):
        return
    bar.lastupdate = currtime

    # note: this check ensures we have IPython.display and so on.
    if ipython_notebook_session:
        # create IPython widgets on first call
        if not hasattr(bar, 'widget'):
            box = Box()
            text = Text()
            progress_widget = IntProgress()

            box.children = [text, progress_widget]
            bar.widget = box
            widget = box

            # make it visible once
            display(box)

            # update css for a more compact view
            progress_widget._css = [("div", "margin-top", "0px")]
            progress_widget.height = "8px"
        else:
            widget = bar.widget

        # update widgets slider value and description text
        desc = bar.description
        desc += ':\t({}/{})'.format(bar.numerator, bar.denominator)
        if show_eta:
            desc += ':\tETA:' + bar._generate_eta(bar._eta.eta_seconds)
        assert isinstance(widget.children[0], Text)
        assert isinstance(widget.children[1], IntProgress)
        widget.children[0].placeholder = desc
        widget.children[1].value = bar.percent
    else:
        sys.stdout.write("\r" + str(bar))
        sys.stdout.flush()
Exemple #4
0
def _widget_abbrev_single_value(o):
    """Make widgets from single values, which can be used as parameter defaults."""
    if isinstance(o, string_types):
        return Text(value=unicode_type(o))
    elif isinstance(o, dict):
        return Dropdown(options=o)
    elif isinstance(o, bool):
        return Checkbox(value=o)
    elif isinstance(o, float):
        min, max, value = _get_min_max_value(None, None, o)
        return FloatSlider(value=o, min=min, max=max)
    elif isinstance(o, int):
        min, max, value = _get_min_max_value(None, None, o)
        return IntSlider(value=o, min=min, max=max)
    else:
        return None
    def unit_panel(self):
        # create spectrum controls.  NOTE: should only be called once.
        specunit = Dropdown(description="Specunit",
                            values=self.model.SPECUNITS.values())
        link((self.model, "spec_unit"), (specunit, "value"))

        varunit = Dropdown(description="Varunit",
                           values=self.model.VARUNITS.values())
        link((self.model, "var_unit"), (varunit, "value"))

        iunit = Text(description="I Unit", values=self.model.iunit)
        link((self.model, "iunit"), (iunit, "value"))

        normunit = Dropdown(description="Normunit",
                            values=self.model.NORMUNITS.values())
        link((self.model, "norm_unit"), (normunit, "value"))

        return ControlPanel(title="Units",
                            children=[normunit, specunit, varunit, iunit])
    def INOUT_panel(self):
        # create correlation controls. NOTE: should only be called once.
        incheck = Checkbox(description='Import')
        link((self.model, "inbox"), (incheck, "value"))
        outcheck = Checkbox(description='Export')
        link((self.model, "outbox"), (outcheck, "value"))

        #loaddata = Checkbox(description="Testdata")
        #link((self.model, "load_spec"), (loaddata, "value"))
        #testdataset = Text(description = "")
        #link((self.model, "testdataset"), (testdataset, "value"))

        filename = Text(description="")
        link((self.model, "file_name"), (filename, "value"))
        loadbutton = Button(color='black',
                            background_color='AliceBlue',
                            description="Load")
        loadbutton.on_click(lambda x: self.model.load_from_ns())
        boxi = HBox([filename, loadbutton])
        #link((self.model, "load_spec"), (specbox, "visible"))

        #        loadfile = Checkbox(description="NB Variable") #Test Data
        #        link((self.model, "load_file"), (loadfile, "value"))

        #                filebox = HBox([loadbutton, filename])
        #link((self.model, "load_file"), (filebox, "visible"))

        #boxi = VBox([
        #HBox([loaddata, loadfile]),
        #loaddata,
        #             specbox,
        #filebox,
        #            ])
        link((self.model, "inbox"), (boxi, "visible"))

        saveplot = Button(color='black',
                          background_color='AliceBlue',
                          description='Save Plot')
        saveplot.on_click(lambda x: self.model.save_plot())
        savespec = Button(color='black',
                          background_color='AliceBlue',
                          description='Export Dataset')
        savespec.on_click(lambda x: self.model.save_to_ns())
        savespecas = Text(description="")
        link((self.model, "save_spec_as"), (savespecas, "value"))

        boxo = VBox([
            savespecas,
            HBox([saveplot, savespec]),
        ])
        link((self.model, "outbox"), (boxo, "visible"))

        #reset = Button(color='white',background_color='violet',description='Reset Defaults')
        #reset.on_click(lambda x: self.model.)

        #redraw = Button(description="Redraw")
        #redraw.on_click(lambda x: self.model.draw())

        return ControlPanel(
            title="Import/Export Dataset",
            children=[HBox([VBox([incheck, outcheck]),
                            VBox([boxi, boxo])])])
    def plot_panel(self):
        # create draw mode controls.  NOTE: should only be called once.
        cbar = Checkbox(description="Colorbar")
        link((self.model, "colorbar"), (cbar, "value"))

        interact = Checkbox(description="Interactive")
        link((self.model, "interactive"), (interact, "value"))

        plug_select = Checkbox(description="Line Selection")
        link((self.model, "selectlines"), (plug_select, "value"))

        autoupdate = Checkbox(description="Auto Update")
        link((self.model, "autoupdate"), (autoupdate, "value"))

        plugin2 = Checkbox(description='Cursor')
        plugin3 = Checkbox(description='plugin3')
        fwidth = FloatText(description='Plot width')
        fheight = FloatText(description='Plot height')
        link((self.model, "figwidth"), (fwidth, "value"))
        link((self.model, "figheight"), (fheight, "value"))

        f = Text(description="Function:")
        link((self.model, "user_f"), (f, "value"))
        fapp = Button(color='black',
                      background_color='AliceBlue',
                      description="Apply")
        fapp.on_click(lambda x: self.model.apply_userf(name='apply clicked'))

        #plugins = HBox([plugin1,plugin2,plugin3])
        #more = Checkbox(description="More Options")### LINK IT
        #link((self, "moreopt"), (more, "value"))
        #popmore = Popup(children=[VBox([HBox([plug_select,plugin2,plugin3]),
        #                                HBox([f,fapp]),
        #                                VBox([fwidth, fheight])
        #                              ])],
        #                description='Advanced', button_text='Advanced')

        more = Checkbox(description="Advanced")
        link((self.model, "advancedbox"), (more, "value"))

        popmore = VBox([
            HBox([
                plug_select,
                plugin2,
                #		plugin3
            ]),
            HBox([f, fapp]),
            HBox([fwidth, fheight])
        ])
        link((self.model, "advancedbox"), (popmore, "visible"))

        cmapcheck = Checkbox(description="Colormap")
        link((self.model, "cmapbox"), (cmapcheck, "value"))

        cmap = Dropdown(description="Colormap", values=self.model.COLORMAPS)
        link((self.model, "colormap"), (cmap, "value"))
        link((self.model, "cmapbox"), (cmap, "visible"))

        colorcheck = Checkbox(description="Color")
        link((self.model, "colorbox"), (colorcheck, "value"))

        color = Dropdown(description="Color", values=self.model.COLORS)
        link((self.model, "color"), (color, "value"))
        link((self.model, "colorbox"), (color, "visible"))

        kind = Dropdown(description="Plot Type", values=PLOTPARSER.keys())
        link((self.model, "kind"), (kind, "value"))

        return ControlPanel(title="Plot Settings",
                            children=[
                                VBox([autoupdate, kind]),
                                HBox([cbar, interact]),
                                HBox([colorcheck, cmapcheck]),
                                HBox([more]), cmap, color, popmore
                            ])