def TrajectorySliderView(traj, frame=0, **kwargs): """IPython notebook widget for viewing trajectories in the browser with an interactiver slider. Parameters ---------- traj : Trajectory Trajectory for which you want the viewer. frame : int, default=0 Frame to set the slider to by default Other Parameters ---------------- kwargs : string See TrajectoryView for all available options. See Also -------- TrajectoryView: IPython notebook widget for displaying trajectories in the browser with WebGL. """ widget = TrajectoryView(traj, frame=frame, **kwargs) def slide(frame): widget.frame = frame s = IntSlider(min=0, max=traj.n_frames - 1, value=frame) slider = interactive(slide, frame=s) container = Box() container.children = [widget, slider] return container
def displayGlobalButton(): ''' 显示全局按钮 :return: ''' config = Config(GLOBAL_SECTION) if not config.isReady(): config.initConf(GLOBAL_SECTION) config.writeConf(GLOBAL_SECTION, 'ref', 'True') config.writeConf(GLOBAL_SECTION, 'debug', 'False') isDisplayRef = config.readConf(GLOBAL_SECTION, 'ref', 'True') == str(True) isDisplayDebug = config.readConf(GLOBAL_SECTION, 'debug', 'True') == str(True) btnRef = ToggleButton(description = '隐藏参考信息' if isDisplayRef else '显示参考信息', value = isDisplayRef) btnDebug = ToggleButton(description = '隐藏调试信息' if isDisplayDebug else '显示调试信息', value = isDisplayDebug) btnDebugClear = Button(description = '清除调试信息') debug.setCleaner(btnDebugClear) if isDisplayDebug: debug.enable() else: debug.disable() btnRef.observe(on_ref_change) btnDebug.observe(on_debug_change) btnDebugClear.on_click(on_debugclear_clicked) boxGlobal = Box([btnRef, btnDebug, btnDebugClear]) display(boxGlobal)
def displayPrepare(self, env): ''' 准备数据 :param env: 当前环境 :return: ''' self.env = env if not self.cf.isReady(): print(Fore.RED + '配置项尚未初始化!') else: self.boxParams = VBox() self.boxParams.layout = Layout(flex_flow = 'column', display = 'flex') self.packageWidgets() display(self.boxParams) self.gdParamValue = qgrid.show_grid(pd.DataFrame([]), grid_options = {'filterable': False, 'autoHeight': True, 'editable': False}) self.gdParamValue.layout = Layout(width = '90%') self.packageParams() self.txtBodyValue = Textarea(value = self.data if self.data is not None else '') self.txtBodyValue.layout = Layout(width = '90%', height = '200px', margin = '6px 2px 2px 2px') boxRequest = Box([ VBox([Label(value = '请求参数值:'), self.gdParamValue], layout = Layout(flex = '1 1 0%', width = 'auto')), VBox([Label(value = '请求体参数值:'), self.txtBodyValue], layout = Layout(flex = '1 1 0%', width = 'auto'))], layout = Layout(flex_flow = 'row', display = 'flex')) acRef = Accordion(children = [boxRequest]) acRef.set_title(0, '输入参考') toggleRefDisplay(acRef) display(acRef) ref.append(acRef)
def TrajectoryHeatmap(trajectory, x, y, fig=None, **kwargs): if fig is None: fig = pp.figure(figsize=(5, 5)) ax = fig.add_subplot(1, 1, 1) ax.hexbin(x, y) ax.set_xlabel('x') ax.set_ylabel('y') else: ax = fig.get_axes()[0] heatmap = MPLFigureButton(fig=fig, height='200px') viewer = TrajectoryView(trajectory, **kwargs) pointToDataCoordinates = ax.transData.inverted() kdtree = cKDTree(np.vstack((x, y)).T) def callback(b, content): x, y = pointToDataCoordinates.transform( [content['mouseX'], content['mouseY']]) _, index = kdtree.query(x=[x, y], k=1) print(x, y, index) viewer.frame = index heatmap.on_click(callback) return Box(children=(heatmap, viewer))
def create_settings(self): word = self.create_checkbox('define', 'pos', 'grammar', 'examples') phrase = self.create_checkbox('text', 'define', 'examples') dictionary = self.create_checkbox('Cambridge', 'Merriam', 'Etymology') merriam = self.create_checkbox('first use', 'etymology') etymology = self.create_checkbox('description', 'image(if any)') translate = self.create_checkbox('requirment') setting = GridspecLayout(8, 6) setting[0, 2] = Label('settings') setting[1, 1:len(dictionary) + 1] = Box(dictionary) setting[1, 0] = Label('dictionary') setting[2, 2] = Label('output') setting[3, 0] = Label('word') setting[3, 1:len(word) + 1] = Box(word) setting[4, 0] = Label('phrase') setting[4, 1:len(phrase) + 1] = Box(phrase) setting[5, 0] = Label('Merriam') setting[5, 1:len(merriam) + 1] = Box(merriam) setting[6, 0] = Label('Etymology') setting[6, 1:len(etymology) + 1] = Box(etymology) setting[7, 0] = Label('Translate') setting[7, 1:len(translate) + 1] = Box(translate) return setting
def RGB_colourspace_models_transformation_matrix_widget(): title_Label = Label('RGB Colourspace Models Transformation Matrix') title_Label.add_class('widget-title') default_layout = {'flex': '1 1 auto', 'width': 'auto'} input_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) output_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) chromatic_adaptation_transforms_Dropdown = Dropdown( options=sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS), layout=default_layout) formatter_Dropdown = Dropdown( options=['str', 'repr', 'Nuke'], layout=default_layout) decimals_IntSlider = IntSlider(value=10, max=15, layout=default_layout) RGB_to_RGB_matrix_Textarea = Textarea(rows=3, layout=default_layout) RGB_to_RGB_matrix_Textarea.add_class('widget-output-textarea') def set_RGB_to_RGB_matrix_Textarea(): M = colour.RGB_to_RGB_matrix( colour.RGB_COLOURSPACES[input_colourspace_Dropdown.value], colour.RGB_COLOURSPACES[output_colourspace_Dropdown.value], chromatic_adaptation_transforms_Dropdown.value) with colour.utilities.numpy_print_options( formatter={ 'float': ('{{:0.{0}f}}'.format(decimals_IntSlider.value)).format }, threshold=np.nan): if formatter_Dropdown.value == 'str': M = str(M) elif formatter_Dropdown.value == 'repr': M = repr(M) else: M = NUKE_COLORMATRIX_NODE_TEMPLATE.format( nuke_format_matrix(M, decimals_IntSlider.value), '{0}_to_{1}'.format( input_colourspace_Dropdown.value.replace(' ', '_'), output_colourspace_Dropdown.value.replace(' ', '_'))) RGB_to_RGB_matrix_Textarea.rows = len(M.split('\n')) RGB_to_RGB_matrix_Textarea.value = M def on_input_change(change): if change['type'] == 'change' and change['name'] == 'value': set_RGB_to_RGB_matrix_Textarea() input_colourspace_Dropdown.observe(on_input_change) output_colourspace_Dropdown.observe(on_input_change) chromatic_adaptation_transforms_Dropdown.observe(on_input_change) formatter_Dropdown.observe(on_input_change) decimals_IntSlider.observe(on_input_change) set_RGB_to_RGB_matrix_Textarea() widget = Box([ VBox( [ title_Label, Textarea( 'This widget computes the colour transformation ' 'matrix from the Input RGB Colourspace to the ' 'Output RGB Colourspace using the given ' 'Chromatic Adaptation Transform.', rows=2, layout=default_layout), Label('Input RGB Colourspace'), input_colourspace_Dropdown, Label('Output RGB Colourspace'), output_colourspace_Dropdown, Label('Chromatic Adaptation Transform'), chromatic_adaptation_transforms_Dropdown, Label('Formatter'), formatter_Dropdown, HBox([Label('Decimals:'), decimals_IntSlider]), Label('RGB Transformation Matrix'), RGB_to_RGB_matrix_Textarea, ], layout={ 'border': 'solid 2px', 'width': '55%' }) ]) return widget
def RGB_colourspace_models_chromatically_adapted_primaries_widget(): title_Label = Label( 'RGB Colourspace Models Chromatically Adapted Primaries') title_Label.add_class('widget-title') default_layout = {'flex': '1 1 auto', 'width': 'auto'} input_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) illuminant_Dropdown = Dropdown( options=sorted( colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']), layout=default_layout) chromatic_adaptation_transforms_Dropdown = Dropdown( options=sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS), layout=default_layout) formatter_Dropdown = Dropdown( options=['str', 'repr'], layout=default_layout) decimals_IntSlider = IntSlider(value=10, max=15, layout=default_layout) primaries_Textarea = Textarea(rows=3, layout=default_layout) primaries_Textarea.add_class('widget-output-textarea') def set_primaries_Textarea(): input_colourspace = colour.RGB_COLOURSPACES[ input_colourspace_Dropdown.value] P = colour.chromatically_adapted_primaries( input_colourspace.primaries, input_colourspace.whitepoint, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][ illuminant_Dropdown.value], chromatic_adaptation_transforms_Dropdown.value) with colour.utilities.numpy_print_options( formatter={ 'float': ('{{:0.{0}f}}'.format(decimals_IntSlider.value)).format }, threshold=np.nan): if formatter_Dropdown.value == 'str': P = str(P) elif formatter_Dropdown.value == 'repr': P = repr(P) primaries_Textarea.rows = len(P.split('\n')) primaries_Textarea.value = P def on_input_change(change): if change['type'] == 'change' and change['name'] == 'value': set_primaries_Textarea() input_colourspace_Dropdown.observe(on_input_change) illuminant_Dropdown.observe(on_input_change) chromatic_adaptation_transforms_Dropdown.observe(on_input_change) formatter_Dropdown.observe(on_input_change) decimals_IntSlider.observe(on_input_change) set_primaries_Textarea() widget = Box([ VBox( [ title_Label, Textarea( 'This widget computes the Chromatically Adapted Primaries ' 'of the given RGB Colourspace Model to the given ' 'Illuminant using the ' 'given Chromatic Adaptation Transform.', rows=3, layout=default_layout), Label('Input RGB Colourspace'), input_colourspace_Dropdown, Label('Illuminant'), illuminant_Dropdown, Label('Chromatic Adaptation Transform'), chromatic_adaptation_transforms_Dropdown, Label('Formatter'), formatter_Dropdown, HBox([Label('Decimals:'), decimals_IntSlider]), Label('RGB Transformation Matrix'), primaries_Textarea, ], layout={ 'border': 'solid 2px', 'width': '55%' }) ]) return widget
def __init__(self, df: pd.DataFrame, col_name: str, df_name: str, page_size: int): self._clusterer = Clusterer(df, col_name, df_name) self._clusterer.cluster("fingerprint") self._page_size = page_size # clustering dropdown and export code checkbox, used in the top row self._clustering_method_label = Label( " Clustering Method: ", layout=Layout(margin="2px 0 0 20px")) self._clustering_method_drop = Dropdown( options=[ "fingerprint", "ngram-fingerprint", "phonetic-fingerprint", "levenshtein" ], layout=Layout(width="150px", margin="0 0 0 10px"), ) self._clustering_method_drop.observe(self._cluster_method_change, names="value") self._export_code = Checkbox( value=True, description="export code", layout=Layout(width="165px", margin="0 0 0 482px"), style={"description_width": "initial"}, ) self._dropds = HBox( [ self._clustering_method_label, self._clustering_method_drop, self._export_code, ], layout=Layout(height="35px", margin="10px 0 0 0"), ) # text boxes for clustering parameters used in the top row self._ngram_text = Text( value=DEFAULT_NGRAM, description="n-gram", layout=Layout(width="130px"), continuous_update=False, ) self._radius_text = Text( value=DEFAULT_RADIUS, description="Radius", layout=Layout(width="130px"), continuous_update=False, ) self._block_chars_text = Text( value=DEFAULT_BLOCK_SIZE, description="Block Chars", layout=Layout(width="130px"), continuous_update=False, ) self._ngram_text.observe(self._param_recluster, names="value") self._radius_text.observe(self._param_recluster, names="value") self._block_chars_text.observe(self._param_recluster, names="value") # create header labels, second row headers = HBox( [ Label("Distinct values", layout=Layout(margin="0 0 0 10px")), Label("Total values", layout=Layout(margin="0 0 0 35px")), Label("Cluster values", layout=Layout(margin="0 0 0 95px")), Label("Merge?", layout=Layout(margin="0 0 0 295px")), Label("Representative value", layout=Layout(margin="0 0 0 50px")), ], layout=Layout(margin="10px"), ) # create buttons for bottom row self._sel_all = Checkbox(description="Select all", layout=Layout(width="165px")) self._sel_all.observe(self._select_all, names="value") merge_and_recluster = Button(description="Merge and Re-Cluster", layout=Layout(margin="0 0 0 466px", width="150px")) merge_and_recluster.on_click(self._execute_merge) finish = Button(description="Finish", layout=Layout(margin="0 0 0 10px")) finish.on_click(self._close) # next and previous page buttons self._next_button = Button(description="Next") self._next_button.on_click(self._next_page) self._prev_button = Button(description="Previous", layout=Layout(margin="0 0 0 20px")) self._prev_button.on_click(self._prev_page) # an index in the clusters Series indicating the start of the current page self._page_pos = 0 # loading label, displayed when re-clustering or next page load self._loading_label = Label("Loading...", layout=Layout(margin="170px 0 0 440px")) # displayed when the user enters a non integer value into a clustering parameter text box self._invalid_param_label = Label( "Invalid clustering parameter, please enter an integer", layout=Layout(margin="170px 0 0 350px"), ) self._reprs = [ Text(layout=Layout(width="200px", margin="0 10px 0 40px")) for _ in range(self._page_size) ] self._checks = [ Checkbox(indent=False, layout=Layout(width="auto", margin="0 0 0 20px")) for _ in range(self._page_size) ] # VBox containing a VBox with all the clusters in the first row and an optional # second row containing next and previous page buttons self._cluster_and_next_prev = VBox() self._cluster_vbox = VBox( layout=Layout(height="450px", flex_flow="row wrap")) footer = HBox([self._sel_all, merge_and_recluster, finish]) box_children = [ self._dropds, headers, self._cluster_and_next_prev, footer ] box_layout = Layout(display="flex", flex_flow="column", align_items="stretch", border="solid") self._box = Box(children=box_children, layout=box_layout) self._update_clusters()
class UserInterface: """ A user interface used by the clean_duplication function. """ # pylint: disable=too-many-instance-attributes _clusterer: Clusterer _page_size: int _clustering_method_label: Label _clustering_method_drop: Dropdown _export_code: Checkbox _sel_all: Checkbox _next_button: Button _prev_button: Button _page_pos: int _ngram_text: Text _radius_text: Text _block_chars_text: Text _dropds: HBox _reprs: List[Text] _checks: List[Checkbox] _cluster_vbox: VBox _box: Box _loading_label: Label _invalid_param_label: Label def __init__(self, df: pd.DataFrame, col_name: str, df_name: str, page_size: int): self._clusterer = Clusterer(df, col_name, df_name) self._clusterer.cluster("fingerprint") self._page_size = page_size # clustering dropdown and export code checkbox, used in the top row self._clustering_method_label = Label( " Clustering Method: ", layout=Layout(margin="2px 0 0 20px")) self._clustering_method_drop = Dropdown( options=[ "fingerprint", "ngram-fingerprint", "phonetic-fingerprint", "levenshtein" ], layout=Layout(width="150px", margin="0 0 0 10px"), ) self._clustering_method_drop.observe(self._cluster_method_change, names="value") self._export_code = Checkbox( value=True, description="export code", layout=Layout(width="165px", margin="0 0 0 482px"), style={"description_width": "initial"}, ) self._dropds = HBox( [ self._clustering_method_label, self._clustering_method_drop, self._export_code, ], layout=Layout(height="35px", margin="10px 0 0 0"), ) # text boxes for clustering parameters used in the top row self._ngram_text = Text( value=DEFAULT_NGRAM, description="n-gram", layout=Layout(width="130px"), continuous_update=False, ) self._radius_text = Text( value=DEFAULT_RADIUS, description="Radius", layout=Layout(width="130px"), continuous_update=False, ) self._block_chars_text = Text( value=DEFAULT_BLOCK_SIZE, description="Block Chars", layout=Layout(width="130px"), continuous_update=False, ) self._ngram_text.observe(self._param_recluster, names="value") self._radius_text.observe(self._param_recluster, names="value") self._block_chars_text.observe(self._param_recluster, names="value") # create header labels, second row headers = HBox( [ Label("Distinct values", layout=Layout(margin="0 0 0 10px")), Label("Total values", layout=Layout(margin="0 0 0 35px")), Label("Cluster values", layout=Layout(margin="0 0 0 95px")), Label("Merge?", layout=Layout(margin="0 0 0 295px")), Label("Representative value", layout=Layout(margin="0 0 0 50px")), ], layout=Layout(margin="10px"), ) # create buttons for bottom row self._sel_all = Checkbox(description="Select all", layout=Layout(width="165px")) self._sel_all.observe(self._select_all, names="value") merge_and_recluster = Button(description="Merge and Re-Cluster", layout=Layout(margin="0 0 0 466px", width="150px")) merge_and_recluster.on_click(self._execute_merge) finish = Button(description="Finish", layout=Layout(margin="0 0 0 10px")) finish.on_click(self._close) # next and previous page buttons self._next_button = Button(description="Next") self._next_button.on_click(self._next_page) self._prev_button = Button(description="Previous", layout=Layout(margin="0 0 0 20px")) self._prev_button.on_click(self._prev_page) # an index in the clusters Series indicating the start of the current page self._page_pos = 0 # loading label, displayed when re-clustering or next page load self._loading_label = Label("Loading...", layout=Layout(margin="170px 0 0 440px")) # displayed when the user enters a non integer value into a clustering parameter text box self._invalid_param_label = Label( "Invalid clustering parameter, please enter an integer", layout=Layout(margin="170px 0 0 350px"), ) self._reprs = [ Text(layout=Layout(width="200px", margin="0 10px 0 40px")) for _ in range(self._page_size) ] self._checks = [ Checkbox(indent=False, layout=Layout(width="auto", margin="0 0 0 20px")) for _ in range(self._page_size) ] # VBox containing a VBox with all the clusters in the first row and an optional # second row containing next and previous page buttons self._cluster_and_next_prev = VBox() self._cluster_vbox = VBox( layout=Layout(height="450px", flex_flow="row wrap")) footer = HBox([self._sel_all, merge_and_recluster, finish]) box_children = [ self._dropds, headers, self._cluster_and_next_prev, footer ] box_layout = Layout(display="flex", flex_flow="column", align_items="stretch", border="solid") self._box = Box(children=box_children, layout=box_layout) self._update_clusters() def _update_clusters(self) -> None: """ Updates the clusters currently being displayed. """ line = HBox( children=[Label("-" * 186, layout=Layout(margin="0 0 0 18px"))]) self._sel_all.value = False cluster_page = self._clusterer.get_page( self._page_pos, self._page_pos + self._page_size) label_layout = Layout(height="22px", width="360px") box_children = [line] for idx, cluster in enumerate(cluster_page): labels = [] for cluster_val, cnt in cluster: if cnt > 1: cluster_val += f" ({cnt} rows)" labels.append(Label(cluster_val, layout=label_layout)) totals_vals = sum(cnt for _, cnt in cluster) distinct_vals = len(cluster) self._reprs[idx].value = cluster[0][0] self._checks[idx].value = False box_children.append( HBox([ Label(str(distinct_vals), layout=Layout(width="60px", margin="0 0 0 60px")), Label(str(totals_vals), layout=Layout(width="60px", margin="0 0 0 50px")), VBox(children=labels, layout=Layout(margin="0 0 0 80px")), self._checks[idx], self._reprs[idx], ])) box_children.append(line) # no clusters to display if len(cluster_page) == 0: box_children = [ Label( "No clusters, try a different clustering method", layout=Layout(margin="170px 0 0 360px"), ) ] self._cluster_vbox.children = box_children cluster_and_next_prev = [self._cluster_vbox] self._add_next_prev_button_row(cluster_and_next_prev) self._cluster_and_next_prev.children = cluster_and_next_prev def _update_dropds(self, clustering_method: str) -> None: """ Update the dropdowns row of the UI to display the required text boxes for passing parameters needed for the given clustering method. """ if clustering_method in ("fingerprint", "phonetic-fingerprint"): self._export_code.layout.margin = "0 0 0 482px" self._dropds.children = [ self._clustering_method_label, self._clustering_method_drop, self._export_code, ] if clustering_method == "ngram-fingerprint": self._export_code.layout.margin = "0 0 0 348px" self._dropds.children = [ self._clustering_method_label, self._clustering_method_drop, self._ngram_text, self._export_code, ] if clustering_method == "levenshtein": self._export_code.layout.margin = "0 0 0 214px" self._dropds.children = [ self._clustering_method_label, self._clustering_method_drop, self._radius_text, self._block_chars_text, self._export_code, ] def _param_recluster(self, _: Dict[str, Any]) -> None: """ Re-cluster the dataframe with the new clustering parameters. Triggered when the value in a clustering parameter textbox is changed. """ self._display_message(self._loading_label) try: self._clusterer.set_cluster_params(*self._cluster_params()) cluster_method = self._clustering_method_drop.value self._clusterer.cluster(cluster_method) self._page_pos = 0 self._update_clusters() except ValueError: self._display_message(self._invalid_param_label) def _cluster_params(self) -> Tuple[int, int, int]: """ Retrieve clustering parameters from their respective text boxes. """ ngram = self._ngram_text.value if self._ngram_text.value else DEFAULT_NGRAM radius = self._radius_text.value if self._radius_text.value else DEFAULT_RADIUS block_size = self._block_chars_text.value if self._block_chars_text else DEFAULT_BLOCK_SIZE return int(ngram), int(radius), int(block_size) def _select_all(self, change: Dict[str, Any]) -> None: """ Triggered when the select all checkbox is selected or unselected. Changes the value of the cluster checkboxes to match the state of the select all checkbox. """ for check in self._checks: check.value = change["new"] def _cluster_method_change(self, change: Dict[str, Any]) -> None: """ Triggered when the cluster method dropdown state is changed. Re-clusters the DataFrame with the new clustering method. """ self._update_dropds(change["new"]) self._display_message(self._loading_label) cluster_method = self._clustering_method_drop.value self._clusterer.cluster(cluster_method) self._page_pos = 0 self._update_clusters() def _add_next_prev_button_row( self, box_children: List[Union[HBox, VBox]]) -> None: """ Adds a next page or previous page button, if the operation is valid. """ next_prev = [] prev_is_valid = self._page_pos - self._page_size >= 0 next_is_valid = self._page_pos + self._page_size < len( self._clusterer.clusters) if prev_is_valid and next_is_valid: self._next_button.layout.margin = "0 0 0 628px" next_prev.append(self._prev_button) next_prev.append(self._next_button) elif prev_is_valid: next_prev.append(self._prev_button) elif next_is_valid: self._next_button.layout.margin = "0 0 0 795px" next_prev.append(self._next_button) if next_is_valid or prev_is_valid: box_children.append(HBox(next_prev, layout={"height": "50px"})) def _next_page(self, _: Dict[str, Any]) -> None: """ Display the next page of clusters by increasing the page position. """ self._display_message(self._loading_label) self._page_pos += self._page_size self._update_clusters() self._sel_all_on_page() def _prev_page(self, _: Dict[str, Any]) -> None: """ Display the previous page of clusters by decreasing the page position. """ self._display_message(self._loading_label) self._page_pos -= self._page_size self._update_clusters() self._sel_all_on_page() def _display_message(self, message_label: Label) -> None: """ Display a message to the user, used for the loading screen and invalid clustering parameter screen """ self._cluster_vbox.children = [message_label] # don't display next and prev buttons self._cluster_and_next_prev.children = [ self._cluster_and_next_prev.children[0] ] def _sel_all_on_page(self) -> None: """ Select all checkboxes on the current page of clusters if the select all checkbox is selected. """ if self._sel_all.value: for check in self._checks: check.value = True def _close(self, _: Dict[str, Any]) -> None: """ Close the UI and display the final dataframe in the next jupyter notebook cell. """ self._clusterer.final_df() self._box.close() def _execute_merge(self, _: Dict[str, Any]) -> None: """ Merge the selected clusters and re-cluster the dataframe. If the export code checkbox is selected the required replace function calls and add them to the jupyter notebook cell. """ self._display_message(self._loading_label) do_merge = [check.value for check in self._checks] new_values = [text.value for text in self._reprs] cluster_page = self._clusterer.get_page( self._page_pos, self._page_pos + self._page_size) if self._export_code.value: self._clusterer.live_export_code(cluster_page, do_merge, new_values) cluster_method = self._clustering_method_drop.value self._clusterer.execute_merge_code(cluster_page, do_merge, new_values) self._clusterer.cluster(cluster_method) self._update_page_if_empty() self._update_clusters() def _update_page_if_empty(self) -> None: """ Decrease the page if the last page is empty. Needed for when all clusters on the last page are merged. """ if self._page_pos >= len(self._clusterer.clusters): self._page_pos -= self._page_size def display(self) -> Box: """Display the UI.""" return self._box
def displayInterface(self): ''' 显示组件 :return: ''' if not self.cf.isReady(): print(Fore.RED + '配置项尚未初始化!') self.btnInit = Button(description = '立即初始化', button_style = 'danger') self.btnInit.on_click(self.on_init_clicked) display(self.btnInit) else: self.catagoryname = self.cf.readConf(self.default['interface'], 'catagoryname') # 类别名称 self.catagoryname = self.default[ 'catagory'] if self.catagoryname is None else self.catagoryname # 未设置时使用默认配置 self.interfacename = self.cf.readConf(self.default['interface'], 'interfacename') # 接口名称 self.interfacename = self.default[ 'interface'] if self.interfacename is None else self.interfacename # 未设置时使用默认配置 self.catagory = interfaces.get(self.catagoryname, None) if self.catagoryname is not None else None # 类别信息 self.interfaces = self.catagory.get('interface', None) if self.catagory is not None else None # 类别下所有接口信息 self.interface = self.interfaces.get(self.interfacename, None) if self.interfaces is not None and self.interfacename is not None else None # 接口信息 # 组件初始化 self.dpCatagory = Dropdown( options = [key for key in interfaces.keys()], value = self.catagoryname if self.catagoryname is not None else None, description = '类别:' ) debug.out('interfacename = %s' % self.interfacename) tmpOptions = [key for key in interfaces[self.dpCatagory.value]['interface']] if self.catagory is not None else [] self.dpInterface = Dropdown( options = tmpOptions, value = self.interfacename if self.interfacename in tmpOptions else None, description = '接口:' ) self.dpCatagory.observe(self.on_catagory_change) self.dpInterface.observe(self.on_interface_change) self.htmInterface = HTML(value = self.choiceResult()) self.gdParam = qgrid.show_grid(pd.DataFrame(None)) self.gdBody = qgrid.show_grid(pd.DataFrame(None)) if self.interface is not None: self.dfParams = pd.DataFrame(self.interface.get('params', ['无']), index = [0]).T self.dfParams.columns = ['请求参数类型'] self.gdParam = qgrid.show_grid(self.dfParams, grid_options = {'filterable': False, 'editable': False}) self.gdParam.layout = Layout(width = '90%') self.dfBody = pd.DataFrame(self.interface.get('body', ['无'])) self.dfBody.columns = ['请求体参数名称'] self.gdBody = qgrid.show_grid(self.dfBody, grid_options = {'filterable': False, 'editable': False}) self.gdBody.layout = Layout(width = '90%') debug.out('display from interface object=%s' % self) display(self.dpCatagory) display(self.dpInterface) boxRequest = Box([VBox([Label(value = '请求参数:'), self.gdParam], layout = Layout(flex = '1 1 0%', width = 'auto')), VBox([Label(value = '请求体参数:'), self.gdBody], layout = Layout(flex = '1 1 0%', width = 'auto'))], layout = Layout(flex_flow = 'row', display = 'flex')) boxRef = VBox([self.htmInterface, boxRequest]) acRef = Accordion(children = [boxRef]) acRef.set_title(0, '接口参考') toggleRefDisplay(acRef) display(acRef) ref.append(acRef)