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 display_beautifully(self): content_items = [] for i in range(len(self.data_results)): news, titles, texts, urls, scores = self.data_results[i] #content_items.append(self.rsspedia_search.display_beautifully(titles, texts, urls, scores)) content_items.append( HTML(value="{}".format( self.rsspedia_search.display_beautifully( titles, texts, urls, scores)))) accordion = Accordion(children=(content_items), ) for i in range(len(self.data_titles)): accordion.set_title(i, "{}. {}".format(i + 1, self.data_titles[i])) display(accordion)
def __init__(self, lp, filename='', **kwargs): self.__lp = lp self.filename = filename self.__accordion = Accordion() self.__auto_apply_cbx = Checkbox(description='Auto apply') self.__auto_save_cbx = Checkbox(description='Auto save') self.__apply_btn = Button(description='Apply changes') self.__save_btn = Button(description='Save changes') self.__add_category_btn = Button(description='Add category') self.__add_category_txt = Text(placeholder='category name') self.__initialize() super().__init__([ VBox([ HBox([ HBox((self.__apply_btn, self.__auto_apply_cbx)), HBox((self.__save_btn, self.__auto_save_cbx)), HBox((self.__add_category_btn, self.__add_category_txt)) ], layout=Layout(flex_flow='row wrap', margin='5px')), self.__accordion ], layout=Layout(margin='5px')) ], **kwargs)
def __initialize(self): if self.__lp.is_valid(): children, titles = self.__build_gui() accordion = Accordion(children) for i, title in enumerate(titles): accordion.set_title(i, title) self.__accordion = accordion self.__auto_apply_cbx.observe(self.__on_auto_apply_cbx_change, names='value') self.__auto_save_cbx.observe(self.__on_auto_save_cbx_change, names='value') self.__apply_btn.on_click( lambda x: self.on_lpy_context_change(self.__lp.dumps())) self.__save_btn.on_click(lambda x: self.__save()) self.__add_category_btn.on_click(lambda x: self.__add_category( self.__add_category_txt.value.strip()))
def columns_accordion_widget(df): accordion = Accordion(selected_index=None, layout=layout) children = [] for i, colname in enumerate(df.columns): accordion.set_title(i, colname) # build each column dummy output (accordion children) child_widget = Label() # column_output_widget(df, colname) children.append(child_widget) # set accordion children accordion.children = children # create accordion handler flag = {} def accordion_handler(change): children = list(change.owner.children) for i in range(len(children)): if change.new == i and (not flag.get(i, 0)): # build child widget colname = change.owner._titles[str(i)] column_output_widget(df, colname, index=i, children=children, parent=change.owner) flag[i] = 1 break return # set observer accordion.observe(accordion_handler) return accordion
def displayEnv(self): ''' 显示环境组件 :return: ''' if not self.cf.isReady(): print(Fore.RED + '配置项尚未初始化!') else: self.envcode = self.cf.readConf(self.default['interface'], 'env') # 环境代码 self.testercode = self.cf.readConf(self.default['interface'], 'tester') # 测试员代码 self.catagoryname = self.cf.readConf(self.default['interface'], 'catagoryname') # 接口类别名称 self.server = servers[self.envcode] if self.envcode is not None else None # 服务器地址 self.tester = testers[self.testercode] if self.envcode is not None else None # 测试信息 # 组件初始化 self.dpEnv = Dropdown( options = [key for key, value in servers.items()], value = self.envcode if self.envcode is not None else None, description = '环境:' ) self.dpTester = Dropdown( options = [key for key, value in testers.items() if value['envcode'] == self.dpEnv.value], value = self.testercode if self.testercode is not None else None, description = '账号:' ) self.dpEnv.observe(self.on_env_change) self.dpTester.observe(self.on_tester_change) self.htmEnv = HTML(value = self.choiceResult()) debug.out('display from env object=%s' % self) display(self.dpEnv) display(self.dpTester) acRef = Accordion(children = [self.htmEnv]) acRef.set_title(0, '环境参考') toggleRefDisplay(acRef) display(acRef) ref.append(acRef)
buffer_value = BoundedFloatText(value=0.2, min=0, max=1, step=0.01, description='Buffer around location:', disabled=False, style={'description_width': 'initial'}) #Gauge option check_gauge = Checkbox(value=False, description='Use gauge location', disabled=False, indent=False, style={'description_width': 'initial'}) use_gauge_location = Accordion(children=[check_gauge]) # user option check_own = Checkbox(value=False, description='Define my own location', disabled=False, indent=False, style={'description_width': 'initial'}) input_lat = BoundedFloatText(value=0.0, min=-99999999999999, max=999999999999999, step=0.0001, description='Latitude:', disabled=False) input_lon = BoundedFloatText(value=0.0,
def test_titles(self): accordion = Accordion(self.children, selected_index=None) assert accordion.get_state()['titles'] == ('', '') assert accordion.titles == ('', '') accordion.set_title(1, 'Title 1') assert accordion.get_state()['titles'] == ('', 'Title 1') assert accordion.titles[1] == 'Title 1' assert accordion.get_title(1) == 'Title 1' # Backwards compatible with 7.x api accordion.set_title(1, None) assert accordion.get_state()['titles'] == ('', '') assert accordion.titles[1] == '' assert accordion.get_title(1) == '' with self.assertRaises(IndexError): accordion.set_title(2, 'out of bounds') with self.assertRaises(IndexError): accordion.get_title(2) accordion.children = tuple(accordion.children[:1]) assert len(accordion.children) == 1 assert accordion.titles == ('', )
def test_selected_index_out_of_bounds(self): with self.assertRaises(TraitError): Accordion(self.children, selected_index=-1)
def test_selected_index(self): accordion = Accordion(self.children, selected_index=1) state = accordion.get_state() assert state['selected_index'] == 1
def test_selected_index_none(self): accordion = Accordion(self.children, selected_index=None) state = accordion.get_state() assert state['selected_index'] is None
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)