def factorizer(): box = widgets.ContainerWidget() header = widgets.HTMLWidget(value="<h1>Integer Factorizer</h1><br>") number = widgets.IntSliderWidget(description="Number:", value=100) speed = widgets.FloatSliderWidget(description="Delay:", min=0.0, max=0.2, value=0.1, step=0.01) subbox = widgets.ContainerWidget() button = widgets.ButtonWidget(description="Calculate") subbox.children = [button] box.children = [header, number, speed, subbox] display(box) box.add_class('align-center') box.add_class('center') box.add_class('well well-small') box.set_css('width', 'auto') subbox.remove_class('vbox') subbox.add_class('hbox') # subbox.add_class('end') def handle_caclulate(sender): plot_primes(number.value, delay=speed.value) button.on_click(handle_caclulate)
def __init__(self): self.stormStuff = StormNameData().splitStormInfo() years = sorted(self.stormStuff.groupby(["Year"]).groups.keys()) # Slider to select year for file self.menuYears = widgets.IntSliderWidget(min=1851, max=2014, step=1, value=2014, description="Year") self.menuNames = widgets.DropdownWidget() self.menuNames.on_trait_change(self._createUrl, 'value') # Button to create dropdown menu of storms for the selected year self.buttonName = widgets.ButtonWidget( description="Get Storm Names") #, value = menuYears.value) self.buttonName.on_click(self._updateNames) # Button to call the plotting class and other necessary classes self.plottingButton = widgets.ButtonWidget( description="Plot Selected Storm", disabled=True) # Container widget to hold storm selection widgets self.stormSelector = widgets.ContainerWidget(children=[ self.menuYears, self.buttonName, self.menuNames, self.plottingButton ], visible=True) # Container widget to hold both storm selectign widgets and plotting button self.form = widgets.ContainerWidget() self.form.children = [self.stormSelector] display(self.form)
def userControls(self): # Button to select new storm from StormSelector self.selectStorm = widgets.ButtonWidget(description="Select New Storm", visible=True) self.selectStorm.on_click(selectNewStorm) # Model selection widgets and controls to change model self.modelSelection = widgets.DropdownWidget( values=self.forecast.groupby(["Group"]).groups.keys(), value="NHC") self.modelSelection.on_trait_change(self.onChangeModel, 'value') # Slider widget to move plots through time self.frameNumber = widgets.IntSliderWidget(min=0, max=1, value=0, step=1, description="Time") # Button widgets to advance and retract time frames add = widgets.ButtonWidget(description="+") subtract = widgets.ButtonWidget(description="-") add.on_click(self.advanceFrame) subtract.on_click(self.subtractFrame) # Checkbox to add multiple tracks to plot clearAll = widgets.ButtonWidget(description="Clear Plot") clearAll.on_click(self.clearPlot) self.check = widgets.CheckboxWidget(description="Add multiple tracks:", value=False) # Widgets to tracks to plot self.newTrackMenu = widgets.DropdownWidget( values=self.forecast.groupby(["Group"]).groups.keys()) self.addTrackButton = widgets.ButtonWidget(description="Add New Track") self.plotMultiTrackButton = widgets.ButtonWidget( description="Plot New Tracks") # Container that holds multiple track widgets self.addNewTrack = widgets.ContainerWidget( visible=False, children=[ self.newTrackMenu, self.addTrackButton, self.plotMultiTrackButton, clearAll ]) # Adding actions to control frameNumber slider widget self.addTrackButton.on_click(self.addingNewTrack) self.plotMultiTrackButton.on_click(self.plottingTracks) self.check.on_trait_change(self.addTracks, 'value') if self.container is None: # Container that holds all widgets self.container = widgets.ContainerWidget(children=[ self.selectStorm, self.frameNumber, add, subtract, self.modelSelection, self.check, self.addNewTrack ]) display(self.container) self.container.visible = True
def _value_changed(self, value): title = widgets.LatexWidget(self.description) children = [title] for elem in value: wcont = widgets.ContainerWidget(description = str(elem)) wtitle = widgets.LatexWidget(value = str(elem)) edit_button = widgets.ButtonWidget(description = "Edit") delete_button = widgets.ButtonWidget(description = "Delete") wcont.children = [wtitle, edit_button, delete_button] children.append(wcont) add_button = widgets.ButtonWidget(description = "Add Command") def add_f(button): if self.add_representation: wr = self.add_representation(self.klass, container_widget = widgets.PopupWidget) else: raise NotImplementedError() wr.create_object() add_button.on_click(add_f) children.append(add_button) self.children = children
def __init__(self, ipython): """Public constructor.""" if VariableInspectorWindow.instance is not None: raise Exception( """Only one instance of the Variable Inspector can exist at a time. Call close() on the active instance before creating a new instance. If you have lost the handle to the active instance, you can re-obtain it via `VariableInspectorWindow.instance`.""") VariableInspectorWindow.instance = self self.closed = False self.namespace = NamespaceMagics() self.namespace.shell = ipython.kernel.shell self._popout = widgets.PopupWidget() self._popout.description = "Variable Inspector" self._popout.button_text = self._popout.description self._modal_body = widgets.ContainerWidget() self._modal_body.set_css('overflow-y', 'scroll') self._modal_body_label = widgets.HTMLWidget(value='Not hooked') self._modal_body.children = [self._modal_body_label] self._popout.children = [ self._modal_body, ] self._ipython = ipython self._ipython.register_post_execute(self._fill)
def _value_changed(self, __ ,value): title = widgets.HTMLWidget(value ='<h5>%s</h5>' % self.description) children = [title] for elem in value: wcont = widgets.ContainerWidget(description = str(elem)) wtitle = widgets.LatexWidget(value = str(elem)) edit_button = widgets.ButtonWidget(description = "Edit") delete_button = widgets.ButtonWidget(description = "Delete") wcont.children = [wtitle, edit_button, delete_button] def edit_f(button): if self.add_representation: wr = self.add_representation(self.klass, container_widget = widgets.PopupWidget, ) else: raise NotImplementedError() def edit_callback(obj): wr.cont.close() wr.edit_object(elem) wr.edit_callback = edit_callback edit_button.on_click(edit_f) def delete_f(button): l = list(self.value) l.remove(elem) self.value = l delete_button.on_click(delete_f) children.append(wcont) wcont.on_displayed(self._set_style) add_button = widgets.ButtonWidget(description = "Add %s" % self.klass.__name__) def add_f(button): if self.add_representation: wr = self.add_representation(self.klass, container_widget = widgets.PopupWidget, ) def handler(obj): self.value = list(self.value) + [obj] wr.cont.close() wr.create_handler = handler else: raise NotImplementedError() wr.create_object() add_button.on_click(add_f) children.append(add_button) self.children = children self._fire_children_displayed()
def show(self): """ Method to cause rendering of the widget. """ buttons = self._backend.get_toolbar() if buttons is not None: toolbar = widgets.ContainerWidget() toolbar.children = buttons display(toolbar) toolbar.remove_class('vbox') toolbar.add_class('hbox') display(self._widget)
def __init__(self, *args, **kwargs): self.defaults = dict( metabotype=METABOTYPE_ALL, database=DATABASE_HMDB, ph=SAMPLE_PH7_10, solvent=SOLVENT_WATER, frequency=FREQUENCY_600, method=METHOD_HIGHEST_NUMBER_NEIGHBOURHOOD, noise=DEFAULT_NOISE_THRESHOLD, confidence=DEFAULT_CONFIDENCE_THRESHOLD, tolerance=DEFAULT_TOLERANCE ) # Overwrite the settings using kwargs passed on create self.settings = dict( self.defaults.items() + kwargs.items() ) # Set up widgets self.form = widgets.ContainerWidget() self.form.set_css({'width':'20ex'}, selector='.widget-hlabel') w_metabotype = widgets.DropdownWidget(description="Metabotype:", value=self.settings['metabotype'], values=METABOTYPES) w_metabotype.on_trait_change(lambda t, value: self.set_value('metabotype', value), 'value' ) w_database = widgets.DropdownWidget(description="Database:", value=self.settings['database'], values=DATABASES) w_database.on_trait_change(lambda t, value: self.set_value('database', value), 'value' ) w_ph = widgets.DropdownWidget(description="pH:", value=self.settings['ph'], values=SAMPLE_PHS) w_ph.on_trait_change(lambda t, value: self.set_value('ph', value), 'value' ) w_solvent = widgets.DropdownWidget(description="Solvent:", value=self.settings['solvent'], values=SOLVENTS) w_solvent.on_trait_change(lambda t, value: self.set_value('solvent', value), 'value' ) w_frequency = widgets.DropdownWidget(description="Frequency MHz:", value=self.settings['frequency'], values=FREQUENCIES) w_frequency.on_trait_change(lambda t, value: self.set_value('frequency', value), 'value' ) w_method = widgets.DropdownWidget(description="Method:", value=self.settings['method'], values=METHODS) w_method.on_trait_change(lambda t, value: self.set_value('method', value), 'value' ) w_noise = widgets.FloatSliderWidget(description="Noise threshold:", value=self.settings['noise'], min=0., max=10., step=0.01) w_noise.on_trait_change(lambda t, value: self.set_value('noise', value), 'value' ) w_confidence = widgets.FloatSliderWidget(description="Confidence threshold:", value=self.settings['confidence'], min=0., max=1., step=0.1) w_confidence.on_trait_change(lambda t, value: self.set_value('confidence', value), 'value' ) w_tolerance = widgets.FloatSliderWidget(description="Shift tolerance:", value=self.settings['tolerance'], min=0., max=10., step=0.01) w_tolerance.on_trait_change(lambda t, value: self.set_value('tolerance', value), 'value' ) self.form.children = [ w_metabotype, w_database, w_ph, w_solvent, w_frequency, w_method, w_noise, w_confidence, w_tolerance]
def distributionSelector(self, directoryName): info = self.distributionInfo(directoryName) time = widgets.DropdownWidget(description="Time", values=info["times"], value=info["times"][-1]) line = widgets.DropdownWidget(description="Sample line", values=info["lines"]) varName = widgets.TextWidget(description="Variable Name") storeButton = widgets.ButtonWidget(description="Store to", disabled=True) def varname_change(name, value): storeButton.description = "Store to " + value if len(value) == 0: storeButton.disabled = True else: dis = False if not value[0].isalpha(): dis = True storeButton.disabled = dis varName.on_trait_change(varname_change, 'value') def store_clicked(b): l = line.value v = varName.value name = self.__getObjectName(self) store = self.__getStorageName() t = time.value print_("Storing distribution at t=", t, "on line", l, "from", directoryName, "in", self.path, "to variable", v) cmd = "%s.distribution('%s','%s','%s')" % (name, directoryName, l, t) if store: sname, sval = store create_code_cell("%s=%s('%s',lambda:%s)" % (v, sname, v, cmd), "below") val = sval(v, lambda: self.distribution(directoryName, l, t)) else: create_code_cell("%s=%s" % (v, cmd), "below") val = self.distribution(directoryName, l, t) get_ipython().push({v: val}) varName.value = "" storeButton.on_click(store_clicked) total = widgets.ContainerWidget( children=[line, time, varName, storeButton]) total.add_class("vbox") display(total)
def select_default_widgets(): from IPython.display import display box = widgets.ContainerWidget(description="Select default widgets") dic = {} children = [] for iname, widget_dict in preferred_widgets.iteritems(): iclass = interface_class(iname) # for name, notebookclass in widgets.iteritems(): values = widget_dict widget = widgets.SelectWidget(description=iclass.__alias__, values=values) children.append(widget) dic[iname] = widget box.children = children box.set_css('border', "1px solid") display(box) return dic
def make_form(self, css_classes): iocont = widgets.ContainerWidget() css_classes[iocont] = ('iobject-container') add_child(iocont, widgets.HTMLWidget(value="<h3>%s</h3>" % self.name)) for inp in self.free_inputs: #We have to filter none kw... allkw = dict(description=inp.name, value=inp.value, default=inp.default) kw = { key: value for (key, value) in allkw.items() if value is not None } w = widgets.TextWidget(**kw) inp.widget = w w.traits()['value'].allow_none = True traitlets.link((inp, 'value'), (w, 'value')) def set_exec(_w): self.executed = False w.on_trait_change(set_exec, name='value') add_child(iocont, w) for out in self.free_outputs: w = widgets.HTMLWidget() out.widget = w add_child(iocont, w) w.traits()['value'].allow_none = True traitlets.link((out, 'value'), (w, 'value')) button = widgets.ButtonWidget(description="Execute %s" % self.name) def _run(b): self.executed = False self.run_sync() button.on_click(_run) add_child(iocont, button) self.widget = iocont self.widget.button = button self.has_widget = True self._toggle_executed() return iocont
def __init__(self, document): """Public constructor.""" self.closed = False self.document = document self._popout = widgets.PopupWidget() self._popout.description = "Create %s" % self.document.__name__ self._popout.button_text = self._popout.description self._modal_body = widgets.ContainerWidget() self._modal_body.set_css('overflow-y', 'scroll') self._popout.children = [ self._modal_body, ] self.fill()
def pickledDataSelector(self): pData = widgets.DropdownWidget(description="Pickled data file", values=self.sol.pickledData, value=self.sol.pickledData[0]) varName = widgets.TextWidget(description="Variable Name") storeButton = widgets.ButtonWidget(description="Store to", disabled=True) def varname_change(name, value): storeButton.description = "Store to " + value if len(value) == 0: storeButton.disabled = True else: dis = False if not value[0].isalpha(): dis = True storeButton.disabled = dis varName.on_trait_change(varname_change, 'value') def store_clicked(b): p = pData.value v = varName.value name = self.__getObjectName(self) store = self.__getStorageName() print_("Storing Pickled Data from", p, "to variable", v) cmd = "%s.pickledData('%s')" % (name, p) if store: sname, sval = store create_code_cell("%s=%s('%s',lambda:%s)" % (v, sname, v, cmd), "below") val = sval(v, lambda: self.pickledData(p)) else: create_code_cell("%s=%s" % (v, cmd), "below") val = self.pickledData(p) get_ipython().push({v: val}) varName.value = "" storeButton.on_click(store_clicked) total = widgets.ContainerWidget(children=[pData, varName, storeButton]) total.add_class("vbox") display(total)
def make_control(self): control_container = widgets.ContainerWidget() run_all_btn = widgets.ButtonWidget(description="Run all") def _ra(btn): result = self.run_all() display(result) run_all_btn.on_click(_ra) add_child(control_container, widgets.HTMLWidget(value="<h2>%s</h2>" % self.name)) add_child(control_container, run_all_btn) css_classes = {control_container: 'control-container'} for node in self.sorted_iterate(): add_child(control_container, node.make_form(css_classes)) display(control_container) for (widget, klass) in css_classes.items(): if isinstance(widget, widgets.ContainerWidget): widget.remove_class("vbox") widget.add_class(klass)
def handle_graph(graph): if len(existing_graphs) > 0: for graph_popup in existing_graphs: graph_popup.close() del existing_graphs[:] floating_container = widgets.ContainerWidget() floating_container.description = "Factors" floating_container.button_text = "Factors" floating_container.set_css({ 'width': '620px', 'height': '450px' }, selector='modal') d3 = ForceDirectedGraphWidget(graph) d3.charge = -400. floating_container.children = [d3] floating_container.set_css('background', BACKGROUND) d3.width = 600 d3.height = 400 display(floating_container) existing_graphs.append(floating_container)
def __init__(self, df): Browse.instance = self self.closed = False self._popout = widgets.PopupWidget() self._popout.description = getattr(df, 'name', 'df') self._popout.button_text = self._popout.description self._modal_body = widgets.ContainerWidget() self._modal_body.set_css('overflow-y', 'scroll') self._modal_body_label = widgets.HTMLWidget(value='Not hooked') self._modal_body.children = [self._modal_body_label] self._popout.children = [ self._modal_body, ] self._df = df self._ipython = get_ipython() self._ipython.register_post_execute(self._fill) self.ncols = len(df._info_axis) self.nrows = len(df)
from IPython.html import widgets from IPython.display import clear_output, display, HTML, Image, Javascript # From http://nbviewer.ipython.org/gist/anonymous/840b5cec9e19f3e39090 hbox = lambda x: (x.remove_class("vbox"), x.add_class("hbox")) # frame = lambda x: x.set_css({ "border": "outset 1px", "padding": 5, "border-radius": 5, "display": "inline-box", "margin": "5px" }) # Example if __name__ == "__main__": c = widgets.CheckboxWidget( description="", value=True) #, width=100, font_size='14pt', fore_color='red') t = widgets.HTMLWidget( value= "how solution with a very long text how to align on the left? how solution with a very long text how to align on the left? how solution with a very long text how to align on the left?" ) t.set_css({'font-size': 16, 'width': '80%', 'margin-top': 4}) cont = widgets.ContainerWidget(children=[c, t]) frame(cont) display(cont) _ = hbox(cont)
def display_ipython(self): """ Method to display the visualization inside the Ipython notebook. It is only supported by IPython versions>=2.0.0 """ self.create_static_html(silent=True) self._widget_dict = OrderedDict() self.container = widgets.ContainerWidget() components = [] for var, init_val in \ zip(self.constant_variables, self.constant_values): self._widget_dict[str(var)] = widgets.FloatTextWidget( value=init_val, description=str(var)) components.append(self._widget_dict[str(var)]) self.button = widgets.ButtonWidget(description="Rerun Simulations") def button_click(clicked): self.button.add_class('disabled') self.button.description = 'Rerunning Simulation ...' self.constant_values = [] for i in self._widget_dict.values(): self.constant_values.append(i.value) if self.system is not None: #update system constants self.system.constants = dict( zip(self.system.constants, self.constant_values)) self.generate_visualization_json_system(self.system) else: self.generate_visualization_json( self.dynamic_variables, self.constant_variables, self.dynamic_values, self.constant_values, fps=self.fps, outfile_prefix=self.outfile_prefix) self.create_static_html(overwrite=True, silent=True) js = 'jQuery("#json-input").val("{}");'.format( 'static/' + self.scene_json_file) display(Javascript(js)) display(Javascript('jQuery("#simulation-load").click()')) self.button.remove_class('disabled') self.button.description = 'Rerun Simulation' self.button.on_click(button_click) #components.append(button) html_file = open("static/index_ipython.html") self.html_widget = widgets.HTMLWidget(value=html_file.read().format( load_url='static/' + self.scene_json_file)) self.container.children = components self.container.set_css({ "max-height": "10em", "overflow-y": "scroll", "display": "block" }) self.html_widget.set_css({"display": "block", "float": "left"}) display(self.container) display(self.button) display(self.html_widget) self.button.add_class('btn-info')
def sampleSelector(self, directoryName): info = self.sampleInfo(directoryName) mode = widgets.ToggleButtonsWidget(description="Mode", values=["Time", "Field"]) field = widgets.DropdownWidget(description="Field", values=info["values"]) time = widgets.DropdownWidget(description="Time", values=info["times"], value=info["times"][-1]) line = widgets.DropdownWidget(description="Sample line", values=info["lines"]) varName = widgets.TextWidget(description="Variable Name") storeButton = widgets.ButtonWidget(description="Store to", disabled=True) def mode_changed(name, value): if value == "Time": time.disabled = False field.disabled = True else: time.disabled = True field.disabled = False mode.on_trait_change(mode_changed, 'value') mode_changed('value', mode.value) def varname_change(name, value): storeButton.description = "Store to " + value if len(value) == 0: storeButton.disabled = True else: dis = False if not value[0].isalpha(): dis = True storeButton.disabled = dis varName.on_trait_change(varname_change, 'value') def store_clicked(b): l = line.value v = varName.value name = self.__getObjectName(self) store = self.__getStorageName() if mode.value == "Time": t = time.value print_("Storing fields at t=", t, "on line", l, "from", directoryName, "in", self.path, "to variable", v) cmdBase = "%s.sampleTime('%s','%s','%s')" % ( name, directoryName, l, t) if store: sname, sval = store cmd = "%s=%s('%s',lambda:%s)" % (v, sname, v, cmdBase) val = sval(v, lambda: self.sampleTime(directoryName, l, t)) else: cmd = "%s=%s" % (v, cmdBase) val = self.sampleTime(directoryName, l, t) elif mode.value == "Field": f = field.value print_("Storing fields", f, " at all times on line", l, "from", directoryName, "in", self.path, "to variable", v) cmdBase = "%s.sampleField('%s','%s','%s')" % ( name, directoryName, l, f) if store: sname, sval = store cmd = "%s=%s('%s',lambda:%s)" % (v, sname, v, cmdBase) val = sval(v, lambda: self.sampleField(directoryName, l, f)) else: cmd = "%s=%s" % (v, cmdBase) val = self.sampleField(directoryName, l, f) else: print_("Unknown mode", mode) return create_code_cell(cmd, "below") get_ipython().push({v: val}) varName.value = "" storeButton.on_click(store_clicked) total = widgets.ContainerWidget( children=[mode, line, field, time, varName, storeButton]) total.add_class("vbox") display(total)
def timelineSelector(self, directoryName): info = self.timelineInfo(directoryName) lst = [widgets.LatexWidget(value="Fields:")] fieldsSelected = set() storeButton = widgets.ButtonWidget(description="Store to", disabled=True) def make_field_toggle(fName): def f(name, value): if value: fieldsSelected.add(fName) else: try: fieldsSelected.remove(fName) except KeyError: pass # this should not happen, but hey! if len(fieldsSelected) > 0: storeButton.disabled = False else: storeButton.disabled = True return f for f in info["fields"]: w = widgets.ToggleButtonWidget(description=f) w.on_trait_change(make_field_toggle(f), 'value') lst.append(w) fields = widgets.ContainerWidget(description="Fields", children=lst) fields.add_class("hbox") varName = widgets.TextWidget(description="Variable Name") def varname_change(name, value): storeButton.description = "Store to " + value if len(value) == 0 or len(fieldsSelected) == 0: storeButton.disabled = True else: dis = False if not value[0].isalpha(): dis = True storeButton.disabled = dis varName.on_trait_change(varname_change, 'value') def store_clicked(b): v = varName.value f = list(fieldsSelected) print_("Storing", f, "from", directoryName, "in", self.path, "to variable", v) name = self.__getObjectName(self) store = self.__getStorageName() cmd = "%s.timeline('%s',%s)" % (name, directoryName, str(f)) if store: sname, sval = store create_code_cell("%s=%s('%s',lambda:%s)" % (v, sname, v, cmd), "below") val = sval(v, lambda: self.timeline(directoryName, f)) else: create_code_cell("%s=%s" % (v, cmd), "below") val = self.timeline(directoryName, f) get_ipython().push({v: val}) varName.value = "" storeButton.on_click(store_clicked) total = widgets.ContainerWidget( children=[fields, varName, storeButton]) total.add_class("vbox") display(total)
def __init__( self, panels, lma_ctrl, scatter_ctrl, charge_lasso, d ): #, station_number_selection, charge_lasso_widget, draw_lasso_widget, color_field_widget, animation_time_widget, animate_button, label, LMA_Controlsa, LMA_Controlsb, tools_popup, number_of_stations): self.panels = panels self.lma_ctrl = lma_ctrl self.d = d self.scatter_ctrl = scatter_ctrl self.charge_lasso = charge_lasso #Max Chi2 Value: chi2_selection = widgets.BoundedFloatTextWidget( description='Max Chi2:', min='0.0', max='1000.0', value='1') chi2_selection.set_css({ 'max-width': '30px', }) chi2_selection.on_trait_change(self.max_chi2, 'value') #Station Number Selection: station_number_selection = widgets.DropdownWidget( description='Number of Stations:', values=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], value=7) station_number_selection.set_css({ 'background-dropdown': '#888888', 'color': 'white', }) station_number_selection.on_trait_change(self.number_of_stations, 'value') #Charge Lasso and Draw Button: charge_lasso_widget = widgets.RadioButtonsWidget( description='Charge Selection:', values=["-1", "0", "1"], value="-1") charge_lasso_widget.on_trait_change(self.change_lasso_charge, 'value') draw_lasso_widget = widgets.ButtonWidget(description='Draw') draw_lasso_widget.set_css({ 'background': '#888888', 'color': 'white', }) draw_lasso_widget.on_click(self.lasso_button) #Color Field Selection: color_field_widget = widgets.RadioButtonsWidget( description='Color By:', values=["chi2", "time", "charge"], value="time") color_field_widget.on_trait_change(self.change_color_field, 'value') #Animate (Slider and Button) Optional Manual Numerical Input commented out: animation_time_widget = widgets.IntSliderWidget( description='Animation Time:', min='0', max='30') animation_time_widget.value = '5' # animation_time_widget = widgets.TextWidget(Description='Animation Time') # animation_time_widget.placeholder = "value" animate_button = widgets.ButtonWidget(description="Animate") animate_button.set_css({ 'display': 'flex', 'align-content': 'flex-end', 'background': '#888888', 'color': 'white', }) animate_button.on_click(self.run_animation_button) #FOR CONTAINERS AND POPUP label = widgets.LatexWidget(value='LMA Tools') label.set_css({ 'font-size': '20px', 'font-weight': 'bold', 'align-self': 'center', 'padding': '15px', 'background': 'd8d8d8', }) LMA_Controlsa = widgets.ContainerWidget() LMA_Controlsa.children = [ station_number_selection, charge_lasso_widget, draw_lasso_widget, chi2_selection ] LMA_Controlsa.set_css({ 'display': 'flex', 'flex-direction': 'column', # 'max-width': '300px', 'flex-flow': 'row wrap', 'align-content': 'flex-start', 'padding': '10px', 'background': '#e8e8e8', 'font-weight': 'bold', }) LMA_Controlsa.remove_class('vbox') LMA_Controlsa.add_class('hbox') LMA_Controlsb = widgets.ContainerWidget() LMA_Controlsb.children = [ color_field_widget, animation_time_widget, animate_button ] LMA_Controlsb.set_css({ 'display': 'flex', 'flex-flow': 'wrap', 'align-items': 'right', 'columns': '1', 'padding': '10px', 'background': '#e8e8e8', 'font-weight': 'bold', }) LMA_Controlsb.remove_class('vbox') LMA_Controlsb.add_class('hbox') tools_popup = widgets.PopupWidget(description='LMA Control Hub') tools_popup.set_css({ 'font-size': '14px', 'align-self': 'center', 'padding': '15px', 'border': '5px ridge #989898', 'background': '#e8e8e8', }) tools_popup.children = [label, LMA_Controlsa, LMA_Controlsb] self.chi2_selection = chi2_selection self.station_number_selection = station_number_selection self.charge_lasso_widget = charge_lasso_widget self.draw_lasso_widget = draw_lasso_widget self.color_field_widget = color_field_widget self.animation_time_widget = animation_time_widget self.animate_button = animate_button self.label = label self.LMA_Controlsa = LMA_Controlsa self.LMA_Controlsb = LMA_Controlsb self.tools_popup = tools_popup
def display_ipython(self): """Displays the scene using an IPython widget inside an IPython notebook cell. Notes ===== IPython widgets are only supported by IPython versions >= 2.0.0. """ # Raise error whenever display_ipython() is called and IPython is # not installed or IPython < '2.0.0' if IPython is None: raise ImportError('IPython is not installed but is required. ' + 'Please install IPython >= 2.0 and try again') elif ipython_less_than_3 is None: raise ImportError('You have IPython ' + IPython.__version__ + ' installed but PyDy supports IPython >= 2.0.0' + 'Please update IPython and try again') self.create_static_html(silent=True) # Only create the constants input boxes and the rerun simulation # button if the scene was generated with a System. if self._system is not None: # Construct a container that holds all of the constants input # text widgets. if ipython_less_than_3: self._constants_container = widgets.ContainerWidget() self._constants_container.set_css({"max-height": "10em", "overflow-y": "scroll", "display": "block"}) else: self._constants_container = widgets.Box() self._constants_container._css = [("canvas", "width", "100%")] self._constants_text_widgets = OrderedDict() self._fill_constants_widgets() # Add all of the constants widgets to the container. self._constants_container.children = \ self._constants_text_widgets.values() self._initialize_rerun_button() display(self._constants_container) display(self._rerun_button) with open("static/index_ipython.html", 'r') as html_file: html = html_file.read() html = html.format(load_url='static/' + self._scene_json_file) if ipython_less_than_3: self._html_widget = widgets.HTMLWidget(value=html) self._html_widget.set_css({"display": "block", "float": "left"}) else: self._html_widget = widgets.HTML(value=html) display(self._html_widget)