class Process: def __init__(self, coil, tube): self.coil = coil coil.tube = tube self.tube = tube tube.coil = coil self.component = Component() self._units = { 'wire diameter': 'm', 'length': 'm', 'volume': u"m\u00B3", 'mass': 'g', 'resistance': u"\u2126", 'current': 'A', 'voltage': 'V', 'power': 'W', 'force': 'N', 'wire_d': 'mm', 'extension': 'm', 'layers': '' } def explore_wire_diameter(self, debug=False, resolution=0.01): options = [ 'resistance', 'length', 'mass', 'volume', 'current', 'voltage', 'power' ] _analyser = Analyser() _analyser.units = self._units def create_graph(val): clear_output(wait=True) output_notebook(hide_banner=True) if val is None: pass elif val[ 'owner'].layout.grid_area == "explore": # disable unused selects _analyser.data["explore"] = val['new'] for key, child in _analyser.unit_children.items(): child.disabled = key not in _analyser.data["explore"] else: _analyser.data[val['owner'].layout.grid_area] = val['new'] display(_analyser.gui) for i in range(1): import time time.sleep(1) _analyser.explore_wire_diameter( self.coil, self.tube, params=list(_analyser.data["explore"]), units=_analyser.units, _start_d=_analyser.data["wire_d_range"][0], _end_d=_analyser.data["wire_d_range"][1] + resolution, _increment_d=resolution, _coil_layer_height=_analyser.data["coil_layer_height"], debug=debug) def update_units(val): _analyser.units[val.owner.layout.grid_area] = val.new create_graph(None) # update # create unit selections units = ["G", "M", "k", "", "c", "m", '\u03BC', "n"] _analyser.unit_children = { opt: self.component.select( update_units, _analyser, options=[s + self._units[opt] for s in units], variable=opt, index=3, width='35px', height='13px', disabled=True) for opt in options } unit_layout = ('"%s"\n' * len(options)) % tuple(options) template_rows = (("%.1f" % (100. / len(options)) + "% ") * len(options))[:-1] unit_gui = self.component.pack(children=list( _analyser.unit_children.values()), layout=unit_layout, template_columns='100%', template_rows=template_rows, width="55px") children = [ unit_gui, self.component.multi_select(create_graph, _analyser, options=options, description="Explore Coil ", variable="explore", width='100%', rows=len(options)), self.component.title('Wire Diameter (mm)', name='wire_title'), self.component.range_slider(create_graph, _analyser, description="Range", variable="wire_d_range", range=(0.2, 1.2), step=resolution, max=2, readout_format='.{}f'.format( str(resolution).count("0"))), self.component.title('Coil Height (mm)', name='coil_title'), self.component.slider(create_graph, _analyser, description="Value", variable="coil_layer_height", increment=14) ] # increment = start value _analyser.gui = self.component.pack( children=children, layout='".. .. .. .."' + ('"explore grid .. .."' * len(options)) + ''' ".. .. .. .." "wire_title .. .. .." "wire_d_range wire_d_range wire_d_range wire_d_range" ".. .. .. .." "coil_title .. .. .." "coil_layer_height coil_layer_height coil_layer_height coil_layer_height" ".. .. .. .." ''', template_columns='30% 12.5% 12.5% 45%', width='650px') create_graph(None) # trigger update def explore_actuator_force(self): _analyser = Analyser() if self.coil.get_layer_count(): display( self.component.title( 'Coil Layers set to %i. Please unset this if you wish to explore.' % self.coil.layer_count)) b = self.component.button('Unset Coil Layers') def on_click_cb(b): self.coil.set_layer_count(None) self.explore_actuator_force() return display(b) b.on_click(on_click_cb) _analyser.explore_actuator_force(self.coil, self.tube, self._units) return def create_graph(val): clear_output(wait=True) output_notebook(hide_banner=True) if val is None: pass else: _analyser.data[val['owner'].layout.grid_area] = val['new'] display(_analyser.gui) _analyser.explore_actuator_force( self.coil, self.tube, self._units, _start=_analyser.data["Range"][0], _end=_analyser.data["Range"][1] + 1, _increment=_analyser.data["Increment"]) children = [ self.component.title('Coil Layers'), self.component.range_slider(create_graph, _analyser, description="Range", variable="Range", range=(0, 10), max=100), self.component.slider(create_graph, _analyser, description="Increment", variable="Increment", increment=10, min=1) ] _analyser.gui = self.component.pack(children=children, layout=''' ".. .. .." "title title title" "Range Range Range" "Increment Increment Increment" ''') create_graph(None) # trigger update def out(self, s): return self.component.title(s)