<jupyter_start><jupyter_text>Creating a toolbar button<jupyter_code>widget_width = "250px"
padding = "0px 0px 0px 5px"  # upper, right, bottom, left

toolbar_button = widgets.ToggleButton(
    value=False,
    tooltip="Toolbar",
    icon="wrench",
    layout=widgets.Layout(width="28px", height="28px", padding=padding),
)

close_button = widgets.ToggleButton(
    value=False,
    tooltip="Close the tool",
    icon="times",
    button_style="primary",
    layout=widgets.Layout(height="28px", width="28px", padding=padding),
)
toolbar = widgets.HBox([toolbar_button])
toolbar<jupyter_output><empty_output><jupyter_text>Adding toolbar event<jupyter_code>def toolbar_click(change):
    if change["new"]:
        toolbar.children = [toolbar_button, close_button]
    else:
        toolbar.children = [toolbar_button]
        
toolbar_button.observe(toolbar_click, "value")
def close_click(change):
    if change["new"]:
        toolbar_button.close()
        close_button.close()
        toolbar.close()
        
close_button.observe(close_click, "value")
toolbar<jupyter_output><empty_output><jupyter_text>Adding toolbar grid<jupyter_code>rows = 2
cols = 2
grid = widgets.GridspecLayout(rows, cols, grid_gap="0px", layout=widgets.Layout(width="62px"))<jupyter_output><empty_output><jupyter_text>icons: https://fontawesome.com/v4.7.0/icons/<jupyter_code>icons = ["folder-open", "map", "info", "question"]

for i in range(rows):
    for j in range(cols):
        grid[i, j] = widgets.Button(description="", button_style="primary", icon=icons[i*rows+j], 
                                    layout=widgets.Layout(width="28px", padding="0px"))
grid
toolbar = widgets.VBox([toolbar_button])
def toolbar_click(change):
    if change["new"]:
        toolbar.children = [widgets.HBox([close_button, toolbar_button]), grid]
    else:
        toolbar.children = [toolbar_button]
        
toolbar_button.observe(toolbar_click, "value")
toolbar<jupyter_output><empty_output><jupyter_text>Adding toolbar to ipyleaflet<jupyter_code>toolbar_ctrl = WidgetControl(widget=toolbar, position="topright")
m = nclpy.Map()
m.add_control(toolbar_ctrl)
m
output = widgets.Output()
output_ctrl = WidgetControl(widget=output, position="bottomright")
m.add_control(output_ctrl)
def tool_click(b):    
    with output:
        output.clear_output()
        print(f"You clicked the {b.icon} button")
for i in range(rows):
    for j in range(cols):
        tool = grid[i, j]
        tool.on_click(tool_click)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13562026326286397, 'fraction_numerical': 0.010370961308336658, 'mean_word_length': 4.712984054669704, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '250322', 'license': 'MIT', 'n_tokens_mistral': 868, 'n_tokens_neox': 829, 'n_words': 143, 'path': 'examples/toolbar.ipynb', 'repo_name': 'HJRubin/nclpy', 'size': '2507'}