def display(self): """Show the widgets""" widgets = [self.widgets['html']] widgets.extend([ v for k, v in self.widgets.items() if k not in ['html', 'trigger'] ]) if not self.auto: widgets.append(self.widgets['trigger']) return Box(children=widgets)
def carousel(children=(), **layout): "A horizontally scrolling carousel" def_layout = dict(overflow='scroll hidden', flex_flow='row', display='flex') res = Box([], layout=merge(def_layout, layout)) res.observe(_update_children, names='children') res.children = children return res
def _make_theme_box(self): if self.widget_theme is None: self.widget_theme = Box([ self._make_button_theme(), self._make_button_reset_theme(hide_toolbar=False), self._make_button_reset_theme(hide_toolbar=True), self._make_button_clean_error_output() ]) return self.widget_theme
def _create_controls(self): """Create widget controls""" self.send_updates_to_renderer = False # Layout alpha_slider_item_layout = Layout(overflow_x='hidden', height='180px', max_width='20px') color_picker_item_layout = Layout(overflow_x='hidden', height='20px', max_width='20px') box_layout = Layout(display='inline-flex') # Sliders self._alpha_sliders = [ widgets.IntSlider(continuous_update=self._continuous_update, layout=alpha_slider_item_layout, description=str(i), orientation='vertical', readout=True, value=self._palette[i][3] * 256, min=0, max=255, step=1) for i in range(len(self._palette)) ] # Color pickers self._color_pickers = [ ColorPicker(layout=color_picker_item_layout, concise=True, disabled=False) for i in range(len(self._palette)) ] # Display controls color_box = Box(children=self._color_pickers) alpha_box = Box(children=self._alpha_sliders) box = VBox([color_box, alpha_box], layout=box_layout) # Attach observers for i in range(len(self._palette)): self._alpha_sliders[i].observe(self._update_colormap, names='value') self._color_pickers[i].observe(self._update_colorpicker, names='value') display(box) self._send_updates_to_renderer = True
def on_button_clicked(b): global lives global blank_word global word global length global box_1 global box_2 global box_3 global box_4 value = b.description if(lives > 0): b.disabled=True print(value) if (value not in word): print("틀렸습니다.") lives -= 1 b. button_style = '' if(lives == 6): image1 = cv2.imread(imageLife6, cv2. COLOR_RGB2BGR) elif(lives == 5): image1 = cv2.imread(imageLife5, cv2. COLOR_RGB2BGR) elif(lives == 4): image1 = cv2.imread(imageLife4, cv2. COLOR_RGB2BGR) elif(lives == 3): image1 = cv2.imread(imageLife3, cv2. COLOR_RGB2BGR) elif(lives == 2): image1 = cv2.imread(imageLife2, cv2. COLOR_RGB2BGR) elif(lives == 1): image1 = cv2.imread(imageLife1, cv2. COLOR_RGB2BGR) else: image1 = cv2.imread(imageLife0, cv2. COLOR_RGB2BGR) print("hangman을 구하는데 실패하였습니다.") print("정답은 " + str(''.join(word)) + " 입니다.") image1 = cv2.imencode(".png", image1)[1].tostring() wImg.value = image1 else: print("맞았습니다.") for i in range(length): if value == word[i]: blank_word[i] = value wLabel.value = ' '.join(blank_word) if(blank_word == word): print("hangman을 구했습니다.") box_Lable = Box(children=items_label, layout=box_layout) widgets.VBox([wImg, box_Lable, box_1, box_2,box_3,box_4])
def box(self): jslink((self.play, 'value'), (self.step_slider, 'value')) self.step_slider.observe(self.replot, 'value') self.product_select.observe(self.replot_image, 'value') for xz in ('X', 'Z'): self.slider[xz].observe(self.replot_spectra, 'value') return VBox([ Box([self.play, self.step_slider, self.product_select]), self.plots_box ])
def _relayout(box, form_item_layout): form_items = [] for kid in box.children: if hasattr(kid, 'description') and not isinstance(kid, (Button, ToggleButton)): label_value = kid.description kid.description = '' else: label_value = '' if isinstance(kid, Button): box2 = Box([ kid, ], layout=form_item_layout) else: box2 = Box([Label(value=label_value), kid], layout=form_item_layout) form_items.append(box2) return form_items
def __init__(self, obj=None): """ TESTS:: sage: from sage_explorer.sage_explorer import SageExplorer sage: S = StandardTableaux(15) sage: t = S.random_element() sage: widget = SageExplorer(t) """ super(SageExplorer, self).__init__() self.title = Title() self.propsbox = VBox() # Will be a VBox full of HBoxes, one for each property self.titlebox = VBox() self.titlebox.add_class('titlebox') self.titlebox.add_class('lightborder') self.titlebox.children = [self.title, self.propsbox] self.visualbox = Box() self.visualtext = Textarea('', rows=8) self.visualwidget = None self.visualbox.add_class('visualbox') self.visualbox.children = [self.visualtext] self.top = HBox([self.titlebox, self.visualbox], layout=justified_h_layout) self.menus = Accordion(selected_index=None) self.menusbox = VBox([Title("Menus", 2), self.menus]) self.menusbox.add_class('catalog-menus') self.menusbox.add_class('lightborder') self.inputs = HBox() self.gobutton = Button(description='Run!', tooltip='Run the function or method, with specified arguments') self.output = HTML() self.worktab = VBox((self.inputs, self.gobutton, self.output)) self.doc = HTML() self.doctab = HTML() # For the method docstring self.tabs = Tab((self.worktab, self.doctab)) # Will be used when a method is selected self.tabs.add_class('tabs') self.tabs.set_title(0, 'Call') self.tabs.set_title(1, 'Help') self.main = Box((self.doc, self.tabs)) self.main.add_class('lightborder') self.tabs.add_class('invisible') # Hide tabs at first display self.bottom = HBox((self.menusbox, self.main), layout=main_h_layout) self.children = (self.top, self.bottom) self.history = [] self.set_value(obj)
def _make_button_export_image(self): slider_factor = IntSlider(value=4, min=1, max=10, description='scale') checkbox_antialias = Checkbox(value=True, description='antialias') checkbox_trim = Checkbox(value=False, description='trim') checkbox_transparent = Checkbox(value=False, description='transparent') filename_text = Text(value='Screenshot', description='Filename') delay_text = FloatText(value=1, description='delay (s)', tooltip='hello') start_text, stop_text, step_text = (IntText(value=0, description='start'), IntText(value=self._view.count, description='stop'), IntText(value=1, description='step')) start_text.layout.max_width = stop_text.layout.max_width = step_text.layout.max_width \ = filename_text.layout.max_width = delay_text.layout.max_width = default.DEFAULT_TEXT_WIDTH button_movie_images = Button(description='Export Images') def download_image(filename): self._view.download_image(factor=slider_factor.value, antialias=checkbox_antialias.value, trim=checkbox_trim.value, transparent=checkbox_transparent.value, filename=filename) @button_movie_images.on_click def on_click_images(button_movie_images): for i in range(start_text.value, stop_text.value, step_text.value): self._view.frame = i time.sleep(delay_text.value) download_image(filename=filename_text.value + str(i)) time.sleep(delay_text.value) vbox = VBox([ button_movie_images, start_text, stop_text, step_text, delay_text, filename_text, slider_factor, checkbox_antialias, checkbox_trim, checkbox_transparent, ]) form_items = _relayout(vbox, make_form_item_layout()) form = Box(form_items, layout=_make_box_layout()) # form = _relayout_master(vbox) return form
def interact(self, **kwargs): c = [] for name, abbrev in kwargs.items(): default = getattr(self, name) widget = interactive.widget_from_abbrev(abbrev, default) if not widget.description: widget.description = name widget.link = link((widget, 'value'), (self, name)) c.append(widget) cont = Box(children=c) return cont
def addBox(self, ulx, uly, lrx, lry, fill="purple", wallcolor=None): if wallcolor is None: wallcolor = fill ulx, lrx = min(ulx, lrx), max(ulx, lrx) uly, lry = max(uly, lry), min(uly, lry) self.addWall(ulx, uly, ulx, lry, wallcolor) self.addWall(ulx, uly, lrx, uly, wallcolor) self.addWall(ulx, lry, lrx, lry, wallcolor) self.addWall(lrx, uly, lrx, lry, wallcolor) self.addShape(Box((ulx, uly), (lrx, lry), fill=fill, outline=wallcolor))
def _relayout_master(box, width='20%'): """make nicer layout for box. This method will take the `description` of each child to make corresponding Label The `description` will be cleared. """ old_children = box.children[:] form_items = _relayout(box, make_form_item_layout()) form = Box(form_items, layout=_make_box_layout(width=width)) form._ngl_children = old_children return form
def on_client_clicked(b): clear_output() df = data dfx = df[df['Advertiser']==b.description].copy() y = sorted(list(set(dfx['Order']))) camp_layout = Layout(height='50px', min_width='300px') camp_buttons = [Button(layout=camp_layout, description=str(campaign), button_style='info') for campaign in y] for button in camp_buttons: button.on_click(on_order_clicked) carousel = Box(children=camp_buttons, layout=box_layout) return(display(carousel))
def run_and_display(A): # Create input text boxes and buttons for users gna_hh = FloatText(value=0, layout=Layout(width='100px')) gk_hh = FloatText(value=0, layout=Layout(width='100px')) gl_hh = FloatText(value=2.0e-5, layout=Layout(width='100px')) cur_inj = FloatText(value=1, layout=Layout(width='100px')) run_button = Button(description="Run Model", button_style='info') clear_button = Button(description="Clear Output", button_style='warning') # Use a form to hold the Labels and Input Boxes form_items = [ Box([Label(value='Leak Channel (gl_hh)', layout=Layout(width='195px')), gl_hh]), Box([Label(value='Sodium Channel (gnabar_hh)', layout=Layout(width='195px')), gna_hh]), Box([Label(value='Potassium Channel (gkbar_hh)', layout=Layout(width='195px')), gk_hh]), Box([Label(value='Current Injection Amplitude (nA)', layout=Layout(width='195px')), cur_inj]), ] # Define the parameters of the form_items form = Box(form_items, layout=Layout( display='flex', flex_flow='column', align_items='initial', width='295px' )) # Display form and buttons display(form, HBox([run_button, clear_button])) #display(HBox([f])) plt.figure # Define functions that run when the user clicks a button def run_button_clicked(b): t,v=run_simulation(gl_hh.value, gna_hh.value, gk_hh.value, cur_inj.value) plt.plot(t,v) plt.show() def clear_button_clicked(b): clear_output() run_button.on_click(run_button_clicked) clear_button.on_click(clear_button_clicked)
def display(self, gui=False, use_box=False): if gui: if use_box: box = Box([self, self.player._display()]) box._gui_style = 'row' return box else: display(self) display(self.player._display()) return None else: return self
def box(self): jslink((self.play, 'value'), (self.step_slider, 'value')) jslink((self.play, 'interval'), (self.fps_slider, 'value')) self.play.observe(self.replot, 'value') self.product_select.observe(self.replot, 'value') for xy in ('x', 'y'): self.slider[xy].observe(self.replot, 'value') return VBox([ Box([self.play, self.step_slider, self.fps_slider]), self.product_select, self.plots_box ])
def _make_req_param(self) -> VBox: self.params_box = Textarea( placeholder=( "Please separate key and value by ':' ; while each key-value pair needs to be " "separated by ',' (e.g. name:abcdefg, date:2019-12-12)" ), layout={"width": "100%", "height": "100%"}, ) carousel_2 = Box(children=[self.params_box], layout=BOX_LAYOUT) param_box = VBox([_make_header(2, "Request Parameters"), carousel_2]) return param_box
def carousel( children: (tuple, list) = (), # `Box` objects to display in a carousel **layout ) -> Box: # An `ipywidget`'s carousel "A horizontally scrolling carousel" def_layout = dict(overflow='scroll hidden', flex_flow='row', display='flex') res = Box([], layout=merge(def_layout, layout)) res.observe(_update_children, names='children') res.children = children return res
def aug_dash_choice(): """Augmention parameter display helper""" button_aug_dash = widgets.Button(description='View', button_style='success') item_erase_val = widgets.HBox( [aug.b_max, aug.b_pval, aug.b_asp, aug.b_len, aug.b_ht]) item_erase = widgets.VBox([aug_paras.hh, item_erase_val]) item_contrast_val = widgets.HBox([aug.b1_max, aug.b1_pval, aug.b1_draw]) item_contrast = widgets.VBox([aug_paras.cc, item_contrast_val]) item_rotate_val = widgets.HBox([aug.b2_max, aug.b2_pval]) item_rotate = widgets.VBox([aug_paras.dd, item_rotate_val]) item_warp_val = widgets.HBox([aug.b3_mag, aug.b3_pval]) item_warp = widgets.VBox([aug_paras.ee, item_warp_val]) item_bright_val = widgets.HBox([aug.b4_max, aug.b4_pval]) item_bright = widgets.VBox([aug_paras.ff, item_bright_val]) item_dihedral_val = widgets.HBox([aug.b5_pval, aug.b5_draw]) item_dihedral = widgets.VBox([aug_paras.gg, item_dihedral_val]) item_zoom_val = widgets.HBox([aug.b6_zoom, aug.b6_pval]) item_zoom = widgets.VBox([aug_paras.ii, item_zoom_val]) items = [ item_erase, item_contrast, item_rotate, item_warp, item_bright, item_dihedral, item_zoom ] dia = Box(items, layout=Layout(display='flex', flex_flow='column', flex_grow=0, flex_wrap='wrap', border='solid 1px', align_items='flex-start', align_content='flex-start', justify_content='space-between', width='flex')) display(dia) display(button_aug_dash) aug_dash_out = widgets.Output() display(aug_dash_out) def on_button_two(b): with aug_dash_out: clear_output() stats_info() code_test() button_aug_dash.on_click(on_button_two)
def widget0(): # True value # n = [-2, 1] alpha = FloatText(value=-2, description=r'\(\alpha \)') beta = FloatText(value=1, description=r'\(\beta\)') w = [alpha, beta] box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', width='100%') box = Box(children=w, layout=box_layout) display(box) return w
def generatePara(templateFile): items = [] with open(templateFile, 'r') as fd: for line in fd.readlines(): g = re.search(r'[\w:]*\s*.*=*\s*\${(.*)}',line) if g: label_value = '' isTB = False for match in re.findall(r'(\w+)=("[^"]*"|\'[^\']*|[^,\n]*)', g.group(1)): if match[0] == 'label': lbs = match[1].split('/') label_value = lbs[0] if len(lbs) == 2: isTB = True if match[0] == 'option': ops = match[1].split('/') # if the first element of options is 'CO', remove it's label name. if ops[0] == 'CO': label = Label(layout = Layout(width = "150px")) if not isTB: togBtns = ToggleButtons(options = ops[1:]) else: togBtns = ToggleButton(description = ops[1], value = True) else: label = Label(value = label_value, layout = Layout(width = "150px")) if not isTB: togBtns = ToggleButtons(options = ops) else: togBtns = ToggleButton(description = ops[0], value = True) box = Box([label, togBtns], layout = Layout(width = '100%', justify_content = 'flex-start')) items.append(box) if match[0] == 'value': label = Label(value = label_value, layout = Layout(width = "150px")) text = Text(value = match[1]) box = Box([label, text], layout = Layout(width = '100%', justify_content = 'flex-start')) items.append(box) fd.close() return items
def show_progress(line: str): show_full_progress = line == 'full' global __experiment_config, __experiment_selectors with open(__experiment_config, 'r') as f: total_progress, experiments_progress = ClusterWork.get_progress(f, __experiment_selectors) box_layout = Layout(display='flex', flex_flow='column', align_items='stretch', widht='100%') items = [__create_exp_progress_box(*progress, show_full_progress) for progress in experiments_progress] total_progress_bar = FloatProgress(value=total_progress, min=.0, max=1., description='Total', bar_style='success') return Box(children=items + [total_progress_bar], layout=box_layout)
def widget2(): # True value # n = [-1.6, -1.6, -1.6, -2.2] n1 = FloatText(value=-1.6, description=r'\(n_{1}^{(1)} \)') n2 = FloatText(value=-1.6, description=r'\(n_{2}^{(1)} \)') n3 = FloatText(value=-1.6, description=r'\(n_{3}^{(1)} \)') n4 = FloatText(value=-2.2, description=r'\(offset\)') N = [n1, n2, n3, n4] box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', width='100%') box = Box(children=N, layout=box_layout) display(box) return N
def build_learned_seq_widget(self): from ipywidgets import FloatProgress, HBox, VBox, HTML, Layout, Button, Box learned_seq_desc = Button(description='Learning Sequence', min_width='140px') learned_seq_desc.style.button_color = 'lightgreen' learned_seq_desc.style.font_weight = 'bold' self.learned_seq = HTML() label_layout = Layout(display='flex', flex_flow='row', flex='0 0 auto', width='150px') learned_seq_layout = Layout(display='flex', flex_flow='row', align_items='flex-start', align_content='flex-start', width='100%') learned_seq_desc_widget = Box(children=[learned_seq_desc], layout=label_layout) return Box(children=[learned_seq_desc_widget, self.learned_seq], layout=learned_seq_layout)
def init_ui_progress(self): """初始化ui进度条""" if not ABuEnv.g_is_ipython or self._total < 2: return if ABuEnv.g_main_pid == os.getpid(): # 如果是在主进程下显示那就直接来 self.progress_widget = FloatProgress(value=0, min=0, max=100) self.text_widget = Text('pid={} begin work'.format(os.getpid())) self.progress_box = Box([self.text_widget, self.progress_widget]) display(self.progress_box) else: if g_show_ui_progress and g_socket_fn is not None: # 子进程下通过socket通信将pid给到主进程,主进程创建ui进度条 ABuOsUtil.socket_send_msg(g_socket_fn, '{}|init'.format(os.getpid()))
def _make_url(self) -> VBox: self.url_area = Text(disabled=False, placeholder="URL", layout={"width": "100%"}) self.request_type = Dropdown( options=["GET", "POST", "PUT"], value="GET", disabled=False, layout={"width": "max-content"}, ) request_box = VBox( [ _make_header(1, "API URL"), Box(children=[self.url_area, self.request_type], layout=BOX_LAYOUT), ] ) return request_box
def _build(self, classes): from ipywidgets import HTML, VBox, Layout, Box self._html = HTML(value="No data to annotate") self._info = HTML(value=" ") self._history = VBox(layout=Layout(margin="1em 0em 0em 0em")) self._widget = VBox([ self._html, self._info, Box( [self._build_label_button(label) for label in classes], layout=Layout(flex_flow="row wrap"), ), self._history, ])
def _init_ui(self) -> VBox: "Initialize the widget UI and return the UI." self._search_input = Text(placeholder="What images to search for?") self._count_input = BoundedIntText(placeholder="How many pics?", value=10, min=1, max=5000, step=1, layout=Layout(width='60px')) self._size_input = Dropdown(options= _img_sizes.keys(), value='>400*300', layout=Layout(width='120px')) self._download_button = Button(description="Search & Download", icon="download", layout=Layout(width='200px')) self._download_button.on_click(self.on_download_button_click) self._output = Output() self._controls_pane = HBox([self._search_input, self._count_input, self._size_input, self._download_button], layout=Layout(width='auto', height='40px')) self._heading = "" self._download_complete_heading = "<h3>Download complete. Here are a few images</h3>" self._preview_header = widgets.HTML(self._heading, layout=Layout(height='60px')) self._img_pane = Box(layout=Layout(display='inline')) return VBox([self._controls_pane, self._preview_header, self._img_pane])
def widget_box(): source = int(config.get_value(['set', 'data_source'])) sources = RadioButtons( options=[ ("JRC RESTful API.", 0), ("Direct access to database and object storage.", 1) ], value=source, layout={'width': 'max-content'} ) sources_box = Box([ Label(value="Data sources:"), sources] ) info_api = Label("RESTful API Settings.") info_direct = Label("Direct access settings") view_options = VBox([info_direct]) if source == 0: view_options.children = [info_api, rest_api()] elif source == 1: view_options.children = [info_direct, direct()] def on_source_change(change): view_options.children = [] if sources.value == 0: view_options.children = [info_api, rest_api()] elif sources.value == 1: view_options.children = [info_direct, direct()] config.update(['set', 'data_source'], str(sources.value)) sources.observe(on_source_change, 'value') wbox_sources = VBox([sources_box, view_options], layout=Layout(border='1px solid black')) info_general = Label(value="General settings:") wbox = VBox([wbox_sources, info_general, settings.widget_box()]) return wbox
def __init__(self, storage, setup): self.storage = storage self.setup = setup self.nans = None self.play = Play() self.step_slider = IntSlider() self.fps_slider = IntSlider(min=100, max=1000, description="1000/fps") self.plots = {} self.plots_box = Box( children=tuple(self.plots.values()), layout=Layout(display='flex', flex_flow='column') ) self.reinit({})