def _repr_html_(self): box = HBox() box.children = [ self.value_text, self.vary_checkbox, self.min_checkbox, self.min_text, self.max_checkbox, self.max_text ] display(box)
def _repr_html_(self): display(self.models_menu) button_box = HBox() button_box.children = [self.fit_button, self.guess_button] display(button_box) for pw in self.param_widgets: display(pw) self.plot()
def __init__(self,start,end): self.pbar = IntProgress(orientation='horizontal',min=start, max=end) self.ptext = HTML() # Only way to place text to the right of the bar is to use a container container = HBox(children=[self.pbar, self.ptext]) display(container)
def make_aggregator(xs, ys): dx = Dropdown(description='"X" Axis', values=OrderedDict((describe_field(x), x) for x in xs)) dy = Dropdown(description='"Y" Axis', values=OrderedDict((describe_field(y), y) for y in ys)) dx.value = 'perspective' dy.value = 'source-schemafamilies' c = HBox(children=(dx, dy)) return c
def __init__(self, maxval=None, widgets=None, term_width=None, poll=1, left_justify=True, fd=sys.stderr): """Initializes a progress bar with sane defaults.""" # Don't share a reference with any other progress bars if widgets is None: widgets = list(self._DEFAULT_WIDGETS) self.maxval = maxval self.widgets = widgets self.fd = fd self.left_justify = left_justify self.signal_set = False if term_width is not None: self.term_width = term_width else: try: self._handle_resize() signal.signal(signal.SIGWINCH, self._handle_resize) self.signal_set = True except (SystemExit, KeyboardInterrupt) as e: raise e except: self.term_width = self._env_size() self.__iterable = None self._update_widgets() self.currval = 0 self.finished = False self.last_update_time = None self.poll = poll self.seconds_elapsed = 0 self.start_time = None self.update_interval = 1 self.next_update = 0 self.bar_widget = None self.container_widget = None if ipython: self.bar_widget = IntProgress() self.container_widget = HBox() self.container_widget.align = "center" display(self.container_widget) children = [] for widget_type in self.widgets: if isinstance(widget_type, pbar_widgets.WidgetHFill): children.append(self.bar_widget) else: text_widget = Latex() children.append(text_widget) self.container_widget.children = children
def status_printer(_, total=None, desc=None, ncols=None, img=None): """ Manage the printing of an IPython/Jupyter Notebook progress bar widget. """ # Fallback to text bar if there's no total # DEPRECATED: replaced with an 'info' style bar # if not total: # return super(mytqdm, mytqdm).status_printer(file) # fp = file # Prepare IPython progress bar try: if total: pbar = IntProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status pbar = IntProgress(min=0, max=1) pbar.value = 1 pbar.bar_style = 'info' except NameError: # #187 #451 #558 raise ImportError( "IntProgress not found. Please update jupyter and ipywidgets." " See https://ipywidgets.readthedocs.io/en/stable" "/user_install.html") if desc: pbar.description = desc if IPYW >= 7: pbar.style.description_width = 'initial' # Prepare status text ptext = HTML() timg = HTML() if img: timg.value = "<br>%s<br>" % img # Only way to place text to the right of the bar is to use a container container = VBox([HBox(children=[pbar, ptext]), timg]) # Prepare layout if ncols is not None: # use default style of ipywidgets # ncols could be 100, "100px", "100%" ncols = str(ncols) # ipywidgets only accepts string try: if int(ncols) > 0: # isnumeric and positive ncols += 'px' except ValueError: pass pbar.layout.flex = '2' container.layout.width = ncols container.layout.display = 'inline-flex' container.layout.flex_flow = 'row wrap' display(container) return container
def status_printer(_, total=None, desc=None, ncols=None): """ Manage the printing of an IPython/Jupyter Notebook progress bar widget. """ # Fallback to text bar if there's no total # DEPRECATED: replaced with an 'info' style bar # if not total: # return super(tqdm_notebook, tqdm_notebook).status_printer(file) # fp = file # Prepare IPython progress bar if IProgress is None: # #187 #451 #558 #872 raise ImportError( "IProgress not found. Please update jupyter and ipywidgets." " See https://ipywidgets.readthedocs.io/en/stable" "/user_install.html") if total: pbar = IProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status pbar = IProgress(min=0, max=1) pbar.value = 1 pbar.bar_style = 'info' if ncols is None: pbar.layout.width = "20px" ltext = HTML() rtext = HTML() if desc: ltext.value = desc container = HBox(children=[ltext, pbar, rtext]) # Prepare layout if ncols is not None: # use default style of ipywidgets # ncols could be 100, "100px", "100%" ncols = str(ncols) # ipywidgets only accepts string try: if int(ncols) > 0: # isnumeric and positive ncols += 'px' except ValueError: pass pbar.layout.flex = '2' container.layout.width = ncols container.layout.display = 'inline-flex' container.layout.flex_flow = 'row wrap' display(container) return container
def __init__(self, model=None, model_config=None, *args, **kwargs): # RUN HTML self.model = model or Spectrogram( **(model_config or {})) #Need to access spectrogram if defaulting... # Create alert widget (refactor into its own function?) alert = Alert(description="Alert or something") link((self.model, "message"), (alert, "value")) # Create a GUI kwargs["orientation"] = 'horizontal' kwargs["children"] = [ HBox([ VBox([self.INOUT_panel(), self.model, alert]), VBox([ self.plot_panel(), self.slicing_panel(), self.unit_panel() ]), ]) ] super(SpectraGui, self).__init__(*args, **kwargs) self._dom_classes += ("spectroscopy row", )
def status_printer(_, total=None, desc=None, ncols=None): """ Manage the printing of an IPython/Jupyter Notebook progress bar widget. """ # Fallback to text bar if there's no total # DEPRECATED: replaced with an 'info' style bar # if not total: # return super(tqdm_notebook, tqdm_notebook).status_printer(file) # fp = file # Prepare IPython progress bar try: if total: pbar = IntProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status pbar = IntProgress(min=0, max=1) pbar.value = 1 pbar.bar_style = 'info' except NameError: # #187 #451 #558 raise ImportError( "IntProgress not found. Please update jupyter and ipywidgets." " See https://ipywidgets.readthedocs.io/en/stable" "/user_install.html") if desc: pbar.description = desc if IPYW >= 7: pbar.style.description_width = 'initial' # Prepare status text ptext = HTML() # Only way to place text to the right of the bar is to use a container container = HBox(children=[pbar, ptext]) # Prepare layout if ncols is not None: # use default style of ipywidgets # ncols could be 100, "100px", "100%" ncols = str(ncols) # ipywidgets only accepts string try: if int(ncols) > 0: # isnumeric and positive ncols += 'px' except ValueError: pass pbar.layout.flex = '2' container.layout.width = ncols container.layout.display = 'inline-flex' container.layout.flex_flow = 'row wrap' display(container) def print_status(s='', close=False, bar_style=None, desc=None): # Note: contrary to native tqdm, s='' does NOT clear bar # goal is to keep all infos if error happens so user knows # at which iteration the loop failed. # Clear previous output (really necessary?) # clear_output(wait=1) # Get current iteration value from format_meter string if total: # n = None if s: npos = s.find(r'/|/') # cause we use bar_format=r'{n}|...' # Check that n can be found in s (else n > total) if npos >= 0: n = float(s[:npos]) # get n from string s = s[npos + 3:] # remove from string # Update bar with current n value if n is not None: pbar.value = n # Print stats if s: # never clear the bar (signal: s='') s = s.replace('||', '') # remove inesthetical pipes s = escape(s) # html escape special characters (like '?') ptext.value = s # Change bar style if bar_style: # Hack-ish way to avoid the danger bar_style being overriden by # success because the bar gets closed after the error... if not (pbar.bar_style == 'danger' and bar_style == 'success'): pbar.bar_style = bar_style # Special signal to close the bar if close and pbar.bar_style != 'danger': # hide only if no error try: container.close() except AttributeError: container.visible = False # Update description if desc: pbar.description = desc if IPYW >= 7: pbar.style.description_width = 'initial' return print_status
def status_printer(_, total=None, desc=None): """ Manage the printing of an IPython/Jupyter Notebook progress bar widget. """ # Fallback to text bar if there's no total # DEPRECATED: replaced with an 'info' style bar # if not total: # return super(tqdm_notebook, tqdm_notebook).status_printer(file) # fp = file # Prepare IPython progress bar if total: pbar = IntProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status pbar = IntProgress(min=0, max=1) pbar.value = 1 pbar.bar_style = 'info' if desc: pbar.description = desc # Prepare status text ptext = HTML() # Only way to place text to the right of the bar is to use a container container = HBox(children=[pbar, ptext]) display(container) def print_status(s='', close=False, bar_style=None): # Note: contrary to native tqdm, s='' does NOT clear bar # goal is to keep all infos if error happens so user knows # at which iteration the loop failed. # Clear previous output (really necessary?) # clear_output(wait=1) # Get current iteration value from format_meter string if total: n = None if s: npos = s.find(r'/|/') # cause we use bar_format=r'{n}|...' # Check that n can be found in s (else n > total) if npos >= 0: n = int(s[:npos]) # get n from string s = s[npos + 3:] # remove from string # Update bar with current n value if n is not None: pbar.value = n # Print stats if s: # never clear the bar (signal: s='') s = s.replace('||', '') # remove inesthetical pipes s = escape(s) # html escape special characters (like '?') ptext.value = s # Change bar style if bar_style: # Hack-ish way to avoid the danger bar_style being overriden by # success because the bar gets closed after the error... if not (pbar.bar_style == 'danger' and bar_style == 'success'): pbar.bar_style = bar_style # Special signal to close the bar if close and pbar.bar_style != 'danger': # hide only if no error container.visible = False return print_status
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 slicing_panel(self): """ create spectrum controls. NOTE: should only be called once.""" model = self.model #For readability # ALL WIDGETS ARE CAPITALIZED. #AXIS = RadioButtons(values=[0,1],description="Axis") #link((model, "slice_axis"), (AXIS, "value")) SPECSTART = FloatSlider( description="Spec Start", min=model.specslice_position_start) #Will not try to update link((model, "specslice_position_start"), (SPECSTART, "value")) link((model, "specstep"), (SPECSTART, "step")) link((model, "specslider_start"), (SPECSTART, "min")) # Start end values (IE slider_min / slider_max) link((model, "specslider_end"), (SPECSTART, "max")) SPECEND = FloatSlider( description="Spec End", max=model.specslice_position_end) # Will not try to update link((model, "specslice_position_end"), (SPECEND, "value")) link((model, "specstep"), (SPECEND, "step")) link((model, "specslider_start"), (SPECEND, "min")) link((model, "specslider_end"), (SPECEND, "max")) # SPACING WIDGET SPECSPACING = IntText(description="Spec Sample by", value=1) link((model, "specspacing"), (SPECSPACING, "value")) TIMESTART = FloatSlider(description="Var Start", min=model.timeslice_position_start) link((model, "timeslice_position_start"), (TIMESTART, "value")) link((model, "timestep"), (TIMESTART, "step")) link((model, "timeslider_start"), (TIMESTART, "min")) link((model, "timeslider_end"), (TIMESTART, "max")) TIMEEND = FloatSlider(description="Var End", max=model.timeslice_position_end) link((model, "timeslice_position_end"), (TIMEEND, "value")) link((model, "timestep"), (TIMEEND, "step")) link((model, "timeslider_start"), (TIMEEND, "min")) link((model, "timeslider_end"), (TIMEEND, "max")) TIMESPACING = IntText(description="Var Sample by", value=1) link((model, "timespacing"), (TIMESPACING, "value")) speccheck = Checkbox(description="Spectral Axis") link((model, "specbox"), (speccheck, "value")) SPECRANGED = VBox([SPECSTART, SPECEND, SPECSPACING]) link((model, "specbox"), (SPECRANGED, "visible")) timecheck = Checkbox(description="Variation Axis") link((model, "timebox"), (timecheck, "value")) TIMERANGED = VBox([TIMESTART, TIMEEND, TIMESPACING]) link((model, "timebox"), (TIMERANGED, "visible")) return ControlPanel( title="Slicing/Sampling", children=[HBox([speccheck, timecheck]), SPECRANGED, TIMERANGED])
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 ])
def status_printer(self, _, total=None, desc=None, ncols=None): """ Manage the printing of an IPython/Jupyter Notebook progress bar widget. """ # Fallback to text bar if there's no total # DEPRECATED: replaced with an 'info' style bar # if not total: # return super(tqdm_notebook_EX, tqdm_notebook).status_printer(file) # fp = file # Prepare IPython progress bar if total: pbar = IntProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status pbar = IntProgress(min=0, max=1) pbar.value = 1 pbar.bar_style = 'info' if desc: pbar.description = desc # Prepare status text ptext = HTML() # Only way to place text to the right of the bar is to use a container container = HBox(children=[pbar, ptext]) if self.vbox: self.vbox.children = self.vbox.children + (container, ) else: display(container) # Prepare layout if ncols is not None: # use default style of ipywidgets # ncols could be 100, "100px", "100%" ncols = str(ncols) # ipywidgets only accepts string if ncols[-1].isnumeric(): # if last value is digit, assume the value is digit ncols += 'px' pbar.layout.flex = '2' container.layout.width = ncols container.layout.display = 'inline-flex' container.layout.flex_flow = 'row wrap' def print_status(s='', close=False, bar_style=None, desc=None): # Note: contrary to native tqdm, s='' does NOT clear bar # goal is to keep all infos if error happens so user knows # at which iteration the loop failed. # Clear previous output (really necessary?) # clear_output(wait=1) # Get current iteration value from format_meter string if total: # n = None if s: npos = s.find(r'/|/') # cause we use bar_format=r'{n}|…' # Check that n can be found in s (else n > total) if npos >= 0: n = int(s[:npos]) # get n from string s = s[npos + 3:] # remove from string # Update bar with current n value if n is not None: pbar.value = n # Print stats if s: # never clear the bar (signal: s='') s = s.replace('||', '') # remove inesthetical pipes s = escape(s) # html escape special characters (like '?') ptext.value = s # Change bar style if bar_style: # Hack-ish way to avoid the danger bar_style being overriden by # success because the bar gets closed after the error… if not (pbar.bar_style == 'danger' and bar_style == 'success'): pbar.bar_style = bar_style # Special signal to close the bar if close and pbar.bar_style != 'danger': # hide only if no error try: container.close() except AttributeError: container.visible = False if self.vbox: self.vbox.children = tuple(ch for ch in self.vbox.children if ch is not container) # Update description if desc: pbar.description = desc return print_status
def _repr_html_(self): box = HBox() box.children = [self.value_text, self.vary_checkbox, self.min_checkbox, self.min_text, self.max_checkbox, self.max_text] display(box)