def _build_procesing_panel(self, processing_info): """ Build up the processing panel for filtering data. Parameters ---------- processing_info: dict Processing information that contains name and parameters. Returns ------- """ self._processing_parameters = processing_info parameter_list = [] # Add the title to the top of the processing area. title = Label('Process: ' + processing_info['name'], style={'font-weight': 'bold', 'font-size': '1.5em'}) title.layout.width = '100%' parameter_list.append(title) # Add all the parameters for parameter in self._processing_parameters.get('parameters'): if isinstance(parameter[1], (int, float, str, list, tuple)): label = Label(parameter[0]) label.layout.width = '50%' # TODO: This needs to be cleaned up / generalized. if isinstance(parameter[1], int): ft = IntText(value=parameter[1]) elif isinstance(parameter[1], float): ft = FloatText(value=parameter[1]) else: ft = Text(value=str(parameter[1])) ft.layout.width = '50%' box = HBox((label, ft )) parameter_list.append(box) # Add the Cancel and Process buttons cancel_button = Button(description='Cancel', value='Cancel') cancel_button.button_style = 'danger' cancel_button.on_click(self._processing_cancel_button_callback) process_button = Button(description='Process', value='Process') process_button.button_style = 'success' process_button.on_click(self._processing_process_button_callback) parameter_list.append(HBox((process_button, cancel_button))) # Add them all to the VBox self._processing_vbox.children = tuple(parameter_list)
def send_clicked(self, btn: Button) -> None: "Callback to be called when the Send button is clicked." btn.button_style = 'info' btn.disabled = True self.logger.logger.info('clicked') url = self.url_txt.value method = self.method_ddn.value headers_text = self.req_pane.get_child_named('Headers').value headers = json.loads(headers_text) if headers_text.strip() else {} data_text = self.req_pane.get_child_named('Data').value data = json.loads(data_text) if data_text.strip() else {} args = [url, method] kwargs = dict(headers=headers, cassette_path=self.cassette_path, logger=self.logger) if data: kwargs['json'] = data self.logger.logger.info('vcr request {} {}'.format(args, kwargs)) if 1: timeout_execute_request = timeout_decorator.timeout(self.timeout)( self.execute_request) try: self.logger.logger.info('callign timeout_execute_request') self.resp, is_cached = timeout_execute_request(*args, **kwargs) self.logger.logger.info('result request {}'.format(self.resp)) except timeout_decorator.TimeoutError: self.logger.logger.info('timed out') self.resp_htm = HBox([ HTML('Response'), HTML('Status: Timed out after {:.3f} secs.'.format( self.timeout)) ], layout=Layout( width='100%', justify_content='space-between')) raise else: self.resp, is_cached = self.execute_request(*args, **kwargs) self.logger.logger.info(self.resp.content) if self.post_process_resp: self.post_process_resp(self.resp) btn.button_style = 'primary' self.show_response(self.resp, is_cached) btn.disabled = False
def new_line(self, data) -> HBox: del_btn = Button(description="Remove", icon="trash") del_btn.button_style = 'danger' hbox = HBox([del_btn, self.data_to_dom(data)], layout=total_width, box_style='info') hbox.data = data def remove_hbox(): children = list(self.children) for i, c in enumerate(children): if id(c) == id(hbox): children.remove(c) self.children = children del_btn.click = remove_hbox return hbox
def control_panel(ric=None): from ipywidgets import Button, HTML, HBox, Accordion from IPython.core.display import display def fmt(inp): if inp is None: return "--" elif type(inp) is float: return "{:.4g}".format(inp) else: return str(inp) if ric is None: ric = qkit.ric def update_instrument_params(b): insdict = ric.get_all_instrument_params() for ins in sorted(insdict): if not ins in b.accordions: b.accordions[ins] = Accordion() table = "<table style='line-height:180%'>" # <tr style='font-weight:bold'><td> Parameter </td><td>Value</td></tr> for p in sorted(insdict[ins]): table += "<tr><td style='text-align:right;padding-right:10px'>" + str( p) + "</td><td>" + fmt( insdict[ins][p][0]) + insdict[ins][p][1] + "</td></tr>" table += """</table>""" b.accordions[ins].children = [HTML(table)] b.accordions[ins].set_title(0, ins) for child in b.accordions.keys(): if child not in insdict: del b.accordions[child] b.hbox.children = b.accordions.values() update_button = Button(description="Update") update_button.on_click(update_instrument_params) update_button.accordions = {} update_button.hbox = HBox() stop_button = Button(description="Stop measurement") stop_button.on_click(lambda b: qkit.ric.stop_measure()) stop_button.button_style = "danger" update_instrument_params(update_button) display(HBox([update_button, stop_button]), update_button.hbox)
def new_line(self, key: str, data: Any) -> HBox: del_btn = Button(description="Remove", icon="trash") del_btn.button_style = 'danger' key_info = HTML(f"<h4 class='text-primary p-1'>{key}</h4>") hbox = HBox([VBox([key_info, del_btn]), self.data_to_dom(data)], layout=total_width, box_style='') hbox.data = data hbox.key = key def remove_hbox(): children = list(self.children) for c in children: if id(c) == id(hbox): children.remove(c) self.children = children self.run_update() del_btn.click = remove_hbox return hbox