def create_new_grid(self): """ Creation of a new grid for the Trial representation. """ if self.has_time: hlabels = ['Dateiname', 'Zeit', 'Treffer links', 'Treffer rechts', 'Kommentare'] screen_width = (str(self.screen(0)-(0.05*self.screen(0))) + 'px') grid = GridspecLayout(len(self.table_rows)+2, len(hlabels), width=screen_width) for r in range(0, len(self.table_rows)+1): for c in range(0, len(hlabels)): if r == 0: grid[r,c] = widgets.Label(hlabels[c], layout=widgets.Layout(width='auto')) else: grid[r,c] = self.table_rows[r-1][c] else: hlabels = ['Dateiname', 'Kommentare'] grid = GridspecLayout(len(self.table_rows)+1, len(hlabels)) for r in range(0, len(self.table_rows)+1): for c in range(0, len(hlabels)): if r == 0: grid[r,c] = widgets.Label(hlabels[c]) else: grid[r,c] = self.table_rows[r-1][c] return grid
def __init__(self, *args): """ Constructs a Trial object. """ # Definition Stil des Fragebogens style = {'description_width':'initial'} # Fragen für Fragebogen self.druck = ["# Bewertung des wahrgenommenen Drucks", args[0], "Haben Sie während dem Gehen Druckstellen an den Unteren Extremitäten gespürt? Wenn ja, zeichnen Sie bitte den Ort/die Orte unten im Bild mit aufsteigenden Nummern ein und bewerten Sie den Druck auf einer Skala von 0-10 (siehe unten). Beim Feld Nummerierung können sie die Zahl zu der entsprechenden Druckstelle eintragen.", "Nummerierung (Anzahl empfundener Druckstellen, mit den Werten)", "Skala"] display(Markdown(self.druck[0])) display(Markdown("## " + self.druck[1])) display(Markdown(self.druck[2])) image1 = mpimg.imread("Druckstellen.png") plt.imshow(image1) plt.show() display(Markdown("## " + self.druck[3])) grid_num = GridspecLayout(2,15) for i in range(1,15): grid_num[0,i-1] = widgets.Label(value=str(i), style=style, layout=widgets.Layout(width='50px')) grid_num[1,i-1] = widgets.Text(value='', description='', disabled=False, style=style, layout=widgets.Layout(width='50px')) display(grid_num) self.druck_num = grid_num display(Markdown("## " + self.druck[4])) image2 = mpimg.imread("DruckSkala.png") plt.imshow(image2) plt.show()
def _make_grid(self) -> None: self.grid = GridspecLayout(40, 4, height="1200px", width="100Z%") self.grid[0:3, :] = self._make_url() self.grid[3:7, :] = self._make_req_param() self.grid[7:14, :] = self._make_auth() self.grid[14:21, :] = self._make_pag() self.grid[21:, :] = self._make_result()
def get_table(items): table = GridspecLayout(len(items), 2) for row_id, item in enumerate(items): table[row_id, 0] = widgets.HTML(item["name"]) table[row_id, 1] = widgets.HTML(fmt(item["value"])) return table
def show_board(self): # Show slider for move selection input_move_i = widgets.IntText(layout=Layout(width='auto')) slider_move_i = widgets.IntSlider(description=r"\(move[i]\)", min=0, max=len(self.board_history) - 1, continuous_update=False, layout=Layout(width='auto')) mylink = widgets.link((input_move_i, 'value'), (slider_move_i, 'value')) slider = VBox([ input_move_i, interactive(self.update_board_gridbox, move_i=slider_move_i) ]) get_state_button = Button(description='get board state') get_state_button.on_click(self.get_board_state) grid = GridspecLayout(4, 6) #, width='auto') #Left side grid[:3, :-3] = self.gridb grid[3, :-3] = slider #Right side grid[:-1, -3:] = self.output_section grid[-1, -3:] = get_state_button display(grid)
def initialize(self, paramnames, width): """Set up and display widget. Parameters ---------- paramnames: list of str Parameter names width: int number of html table columns. """ from ipywidgets import HTML, VBox, GridBox, Layout, GridspecLayout from IPython.display import display grid = GridspecLayout(len(paramnames), width + 3) self.laststatus = [] for a, paramname in enumerate(paramnames): self.laststatus.append('*' * width) htmlcode = "<div style='background-color:#6E6BF4;'> </div>" for b in range(width): grid[a, b + 2] = HTML(htmlcode, layout=Layout(margin="0")) htmlcode = "<div style='background-color:#FFB858; font-weight:bold; padding-right: 2em;'>%s</div>" grid[a, 0] = HTML(htmlcode % html_escape(paramname), layout=Layout(margin="0")) grid[a, 1] = HTML("...", layout=Layout(margin="0")) grid[a,-1] = HTML("...", layout=Layout(margin="0")) self.grid = grid self.label = HTML() box = VBox(children=[self.label, grid]) display(box)
def __plot_content_row(table, row_index, condition): column_count = len(table.columns) one_row_grid = GridspecLayout(1, column_count) for j, column in enumerate(table.columns): one_row_grid[0, j] = __plot_cell(str(table[column][row_index])) return one_row_grid
def interactive_selection(): from ipywidgets import Button, HBox, VBox, widgets, Layout, GridspecLayout from IPython.display import display ## Generate interactive grid d={} output = widgets.Output #output.clear_output global hold_selection hold_selection = [] #generate hold_key_matrix hold_key_matrix = generate_hold_key_matrix() def on_button_clicked(b): b.style.button_color = 'lightgreen' global hold_selection hold_selection.append(b.description) ##define grid for R in range(hold_key_matrix.shape[0]): hold = hold_key_matrix[R,:].tolist() #convert to list, start with "18" item = [Button(description=h) for h in hold] #list of buttons d['{}{}'.format('H_box',R)] = HBox(item) #store all Hboxes in dictionary #define buttons for C in range(hold_key_matrix.shape[1]): button = item[C] # button.on_click(on_button_clicked) whole_grid = VBox([d['H_box0'], d['H_box1'], d['H_box2'], d['H_box3'], d['H_box4'], d['H_box5'], d['H_box6'], d['H_box7'], d['H_box8'], d['H_box9'], d['H_box10'], d['H_box11'], d['H_box12'], d['H_box13'], d['H_box14'], d['H_box15'], d['H_box16'], d['H_box17']]) grid = GridspecLayout(18,11) grid[:,:] = whole_grid display(grid) #display(whole_grid) ## generate Termination buttons # predict grade button function def end_button_clicked(b): predict_grade_JF(hold_selection) #define reload_button.on_clicked def reload_on_clicked(b): global hold_selection for H in hold_selection: index_nd_array = np.where(hold_key_matrix==H) whole_grid.children[int(index_nd_array[0])].children[int(index_nd_array[1])].style.button_color = None hold_selection=[] ##display reload and predict grade button end_button = widgets.Button(description='Predict difficulty!', button_style='danger') end_button.on_click(end_button_clicked) reload_button = widgets.Button(description='Reload', button_style='primary') reload_button.on_click(reload_on_clicked) final_buttons = HBox([end_button, reload_button]) display(final_buttons)
def build_grid(self): grid = GridspecLayout(4, 6, height='400px') grid[0:1, 0:5] = self.input_widget grid[0:1, 5] = self.file_toggle grid[1:, 0:5] = self.textarea grid[1:3, 5] = self.control_buttons grid[3, 5] = self.plot_button return grid
def get_table(items): table = GridspecLayout(len(items), 3) for row_id, (label, progress, count) in enumerate(items): table[row_id, 0] = label table[row_id, 1] = progress table[row_id, 2] = count return VBox([table])
def create_grid_part(self): grid_part = GridspecLayout(len(self.part_info.participant_info_name), 1) for r in range(0, len(self.part_info.participant_info_name)): grid_part[r, 0] = self.part_rows[r][0] return grid_part
def __plot_non_expandable_table_content(table): column_count = len(table.columns) row_count = len(table) grid = GridspecLayout(row_count, column_count) for i in range(row_count): for j, column in enumerate(table.columns): grid[i, j] = __plot_cell(str(table[column][i])) vis = grid return vis
def get_table( items: List[Tuple[widgets.Label, widgets.FloatProgress, widgets.Label]] ) -> VBox: table = GridspecLayout(len(items), 3) for row_id, (label, progress, count) in enumerate(items): table[row_id, 0] = label table[row_id, 1] = progress table[row_id, 2] = count return VBox([table])
def render_snippet_results(modelnames, results): rows = [render_modelnames(modelnames)] num_results = len(results[modelnames[0]]) header_grid = render_modelnames(modelnames) grid = GridspecLayout(num_results, len(modelnames), height='1700px') for i in range(num_results): for j, name in enumerate(modelnames): grid[i, j] = render_snippet(i + 1, results[name][i]) return VBox([header_grid, grid])
def __init__(self, sp): assert isinstance(sp, spaces.Space) if isinstance(sp, spaces.Dict): it = list(sp.spaces.items()) info = GridspecLayout(len(it), 2) for i, v in enumerate(it): info[i, 0], info[i, 1] = widgets.Label(v[0]), widgets.Label( str(v[1])) else: info = widgets.Label(str(sp)) super().__init__([info])
def __plot_head_columns(columns): ''' This function plot the header column, which specifying the column name of the rest of the table rows. Argument: - columns: a list of column names. ''' header = GridspecLayout(1, len(columns)) for j, column in enumerate(columns): header[0, j] = __plot_cell(str(column), bold=True) return header
def create_new_grid(self): style = {'description_width':'initial'} for i, value in enumerate(self.part_info.participant_info_name): setattr(self, "participant%s" % (i), widgets.Text(value='', placeholder='', description=value, disabled=False, style=style, layout=widgets.Layout(width='500px'))) grid = GridspecLayout(len(self.part_info.participant_info_name),1) for r, value in enumerate(self.part_info.participant_info_name): grid[r,0] = getattr(self, "participant%s" % (r)) return grid
def create_grid_fersen(self): style = {'description_width':'initial'} for j, value in enumerate(self.part_info.participant_info_fersengang): setattr(self, "fersengang%s" % (j), widgets.Dropdown(options=[(' ', 0),('möglich', 1), ('unmöglich', 2)], value=0, description=value, style=style, layout=widgets.Layout(width='500px'))) grid_fersen = GridspecLayout(len(self.part_info.participant_info_fersengang),2) for s, value in enumerate(self.part_info.participant_info_fersengang): grid_fersen[s,0] = getattr(self, "fersengang%s" % (s)) return grid_fersen
def get_table(items: List[Dict[str, Any]]) -> GridspecLayout: table = GridspecLayout(len(items), 2) for row_id, item in enumerate(items): name = item["name"] value = item["value"] if "alert" in item and item["alert"]: name = fmt_color(name, "var(--jp-error-color1)") value = fmt_color(value, "var(--jp-error-color1)") table[row_id, 0] = widgets.HTML(name) table[row_id, 1] = widgets.HTML(value) return table
def _make_grid(self) -> None: self.grid = GridspecLayout( 32, 4, height="960px", width="800px", layout={"border": "1px solid black", "padding": "5px"}, ) self.grid[0:4, :] = self._make_url() self.grid[4:8, :] = self._make_req_param() self.grid[8:16, :] = self._make_auth() self.grid[16:24, :] = self._make_pag() self.grid[24:28, :] = self._make_generator_option() self.grid[28:32, :] = self._make_result()
def get_table(items): table = GridspecLayout(len(items), 2) fmt_mapping = get_fmt_mapping() for row_id, item in enumerate(items): name = item["name"] formatter = fmt_mapping[item["fmt"]] value = formatter(item["value"]) if "alert" in item and item["alert"]: name = fmt_color(name, "var(--jp-error-color1)") value = fmt_color(value, "var(--jp-error-color1)") table[row_id, 0] = widgets.HTML(name) table[row_id, 1] = widgets.HTML(value) return VBox([table])
def createDBCB(self,b): self.out_cp.clear_output() wd = [0]*self.ny for i in range(self.ny): for j in range(self.nx): wd[i] += int(self.pwTW[i][j].value) tpw = max(wd) lw = tpw+((self.nx-1)*self.gridGap)+(self.gridPad*2) self.topLabel.layout = {'width': 'auto'} gw = lw + (2*self.dbBorder) gap = str(self.gridGap)+'px' pd = str(self.gridPad) pad = pd+'px '+pd+'px '+pd+'px '+pd+'px' self.gridDB2 = GridspecLayout(self.ny,self.nx, layout={ 'scroll':'True', 'grid_gap':gap, 'padding':pad } ) ph = str(self.panelHeight[1])+'px' pb = str(self.panelBorder)+'px groove' for i in range(0,self.ny): for j in range(0,self.nx): pw = self.pwTW[i][j].value+'px' ph = self.phTW[i][j].value+'px' obj = self.objDict[self.objSW[i][j].value]() obj.pwdDict = self.pwdDict obj.spacer.layout={'width':pw} obj = obj.getCP() obj.layout={'overflow_x':'visible','overflow_y':'visible'} self.gridDB2[i,j] = HBox([obj],layout={'height': ph,'width': pw,'border':pb}) gp = str(self.gridPad)+'px' dbb = str(self.dbBorder)+'px groove' dbw = str(gw)+'px' self.cp = VBox([ VBox([self.topLabel,self.gridDB2],layout={'flex_flow':'column'}), HBox([self.reconfigDB],layout={'justify_content':'center','padding':gp}) ],layout={'border':dbb,'width':dbw} ) with self.out_cp: self.out_cp.clear_output() display(self.cp)
def create_board_gridbox(game, show_legal_moves, click_callback=None): h, w = game.height, game.width board_state = get_viz_board_state(game, show_legal_moves) grid_layout = GridspecLayout(n_rows=h, n_columns=w, grid_gap='2px 2px', width='480px', height='480px', justify_content='center') for r in range(h): for c in range(w): cell = create_cell(board_state[r][c], grid_loc=(r, c), click_callback=click_callback) grid_layout[r, c] = cell return grid_layout
def mdraw(self): # SECTION 4: Post process / output self.dlist = [ self.c.output, self.c.UTM_easting, self.c.UTM_northing, self.c.x, self.c.y, self.fd.stack["stab"], self.fd.stack["wdirn"] ] # create a 10x2 grid layout self.grid = GridspecLayout(10, 2) # fill it in with widgets self.grid[:, 0] = self.fd.h1 self.grid[0, 1] = self.fd.h1 self.grid[1, 1] = self.fd.h2 self.grid[2, 1] = self.fd.h3 # set the widget properties self.grid[:, 0].layout.height = 'auto' self.grid self.gpdraw.gpdraw(self.C1, self.img, self.dlist)
def create_new_grid(self): style = {'description_width':'initial'} # Set names of in-/exclusion criteria for i, value in enumerate(self.input_crit): setattr(self, "label%s" % (i), widgets.Label(value=value, layout=widgets.Layout(width='auto'))) setattr(self, "widget%s" % (i), widgets.Dropdown(options=[(' ', 0),('Ja', 1), ('Nein', 2)], value=1, description='', style=style, layout=widgets.Layout(width='80px'))) # Construct table for showing in-/exclusion criteria (number irrelevant) grid = GridspecLayout(len(self.input_crit), 2) for r in range(0, len(self.input_crit)): grid[r,0] = getattr(self, "label%s" % (r)) for c in range(0, len(self.input_crit)): grid[c,1] = getattr(self, "widget%s" % (c)) return grid
def create_new_grid(self): """ Creation of a new grid for the Trial representation. """ hlabels = ['Dateiname', 'Kommentare'] screen_width = (str(self.screen(0) - (0.05 * self.screen(0))) + 'px') grid = GridspecLayout(len(self.table_rows) + 1, len(hlabels), width=screen_width) for r in range(0, len(self.table_rows) + 1): for c in range(0, len(hlabels)): if r == 0: grid[r, c] = widgets.Label(hlabels[c]) else: grid[r, c] = self.table_rows[r - 1][c] return grid
def _experiment_widget(tab: Tab) -> GridspecLayout: """Show a `ipywidgets.GridspecLayout` with information about the loaded experiment. The clickable buttons can perform an action in ``tab``. """ header_names = [ "Run ID", "Name", "Experiment", "Coordinates", "Variables", "MSMT Time", "Notes", ] header = {n: button(n, "info") for n in header_names} rows = [header] for exp in qcodes.experiments(): tooltip = f"{exp.name}#{exp.sample_name}@{exp.path_to_db}" for ds in exp.data_sets(): coords, variables = _get_coords_and_vars(ds) row = {} row["Run ID"] = text(str(ds.run_id)) row["Name"] = text(ds.name) row["Experiment"] = button(f"#{exp.exp_id}", "warning", tooltip=tooltip) row["Notes"] = editable_metadata(ds) row["Coordinates"] = expandable_dict(coords, tab, ds) row["Variables"] = expandable_dict(variables, tab, ds) row["MSMT Time"] = text(ds.completed_timestamp() or "") rows.append(row) grid = GridspecLayout(n_rows=len(rows), n_columns=len(header_names)) empty_text = text("") for i, row in enumerate(rows): for j, name in enumerate(header_names): grid[i, j] = row.get(name, empty_text) grid.layout.grid_template_rows = "auto " * len(rows) grid.layout.grid_template_columns = "auto " * len(header_names) return grid
def _experiment_widget( data_sets: Iterable[DataSetProtocol], tab: Tab ) -> GridspecLayout: """Show a `ipywidgets.GridspecLayout` with information about the loaded experiment. The clickable buttons can perform an action in ``tab``. """ header_names = [ "Run ID", "Experiment", "Name", "Parameters", "MSMT Time", "Notes", "Snapshot", "Plot", ] header = {n: button(n, "info") for n in header_names} rows = [header] for ds in data_sets: row = {} row["Run ID"] = _get_run_id_button(ds) row["Experiment"] = _get_experiment_button(ds) row["Name"] = label(ds.name) row["Notes"] = editable_metadata(ds) row["Parameters"] = _get_parameters_button(ds) row["MSMT Time"] = _get_timestamp_button(ds) row["Snapshot"] = _get_snapshot_button(ds, tab) row["Plot"] = _get_plot_button(ds, tab) rows.append(row) grid = GridspecLayout(n_rows=len(rows), n_columns=len(header_names)) empty_label = label("") for i, row in enumerate(rows): for j, name in enumerate(header_names): grid[i, j] = row.get(name, empty_label) grid.layout.grid_template_rows = "auto " * len(rows) grid.layout.grid_template_columns = "auto " * len(header_names) return grid
def display_image_and_references(image_path: Path): """ display function of superintendent. display img_ndwi and all the other img_ndwi of the same location as reference to labeler :param image_path: image path :return: ipython display handle """ image_folder = image_path.parent other_images = [ f for f in image_folder.glob("img_ndwi*.png") if f.is_file() and f != image_path ] other_images.extend(image_folder.glob("bg_ndwi*.png")) n_col = 4 n_row = max(math.ceil(len(other_images) / n_col), 1) grid = GridspecLayout(n_row, n_col) for i in range(n_row): for j in range(n_col): img_index = i * n_col + j if img_index >= len(other_images): break image = other_images[img_index] grid[i, j] = widgets.VBox([ widgets.Label("Image {0}".format(image.name)), widgets.Image(value=transform_img_path(image), layout=widgets.Layout(width='200px', height='200px')), ]) image_display = widgets.VBox([ widgets.VBox([ widgets.Label("folder: {0}".format(image_folder)), widgets.Label("all other images of the same loc"), grid, widgets.Label("image to label: {0}".format(image_path.name)), widgets.Image(value=transform_img_path(image_path), object_fit='none', layout=widgets.Layout(width='300px', height='300px')) ]), ]) display(image_display)
def layout_grid(self): if self.debug: print("Setting Layout") # Organize Layout self.dg = GridspecLayout(13, 6, width=self.width, height=self.height) # Row 0 - Header self.dg[0, 2:4] = self.lbl_core #Row 1 - Chart Type and Title self.dg[1, 1] = self.drp_charts self.dg[1, 3] = self.lbl_title self.dg[1, 4] = self.txt_title # Row 2 and 3 - Data Frame Selection and chart height/width self.dg[2:4, 1] = self.sel_df self.dg[2, 3] = self.lbl_charth self.dg[2, 4] = self.txt_charth self.dg[3, 3] = self.lbl_chartw self.dg[3, 4] = self.txt_chartw # Rows, 4, 5, and 6 - Field chooser and buttons self.dg[4, 1] = self.lbl_fields self.dg[4, 2] = self.lbl_cols self.dg[4, 3] = self.chk_incidx self.dg[4, 4] = self.lbl_assigned self.dg[5:7, 1] = self.sel_fields self.dg[5:7, 2] = self.sel_cols self.dg[5:7, 4] = self.sel_assigned self.dg[5, 3] = self.btn_add self.dg[6, 3] = self.btn_rem # Row Generate code/clear buttons self.dg[7, 4] = self.btn_clear_assigned self.dg[7, 2:3] = self.btn_gen # Row 8 - Display for Full Chart and URL self.dg[8, 1:] = self.out_url # Row 8 - Display for formatted function self.dg[9:11, 1:] = self.out_func # Row 9 A Break (This is stupid) self.dg[11, :] = self.lbl_break # Row 10 - The actual output self.dg[12, :] = self.out_graph