Toolbar
In [1]:
Copied!
import geodemo
import ipywidgets as widgets
from ipyleaflet import WidgetControl
import geodemo
import ipywidgets as widgets
from ipyleaflet import WidgetControl
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import geodemo 2 import ipywidgets as widgets 3 from ipyleaflet import WidgetControl ModuleNotFoundError: No module named 'geodemo'
Creating a toolbar button¶
In [2]:
Copied!
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),
)
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),
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[2], line 4 1 widget_width = "250px" 2 padding = "0px 0px 0px 5px" # upper, right, bottom, left ----> 4 toolbar_button = widgets.ToggleButton( 5 value=False, 6 tooltip="Toolbar", 7 icon="wrench", 8 layout=widgets.Layout(width="28px", height="28px", padding=padding), 9 ) 11 close_button = widgets.ToggleButton( 12 value=False, 13 tooltip="Close the tool", (...) 16 layout=widgets.Layout(height="28px", width="28px", padding=padding), 17 ) NameError: name 'widgets' is not defined
In [3]:
Copied!
toolbar = widgets.HBox([toolbar_button])
toolbar
toolbar = widgets.HBox([toolbar_button])
toolbar
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 1 ----> 1 toolbar = widgets.HBox([toolbar_button]) 2 toolbar NameError: name 'widgets' is not defined
Adding toolbar event¶
In [4]:
Copied!
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 toolbar_click(change):
if change["new"]:
toolbar.children = [toolbar_button, close_button]
else:
toolbar.children = [toolbar_button]
toolbar_button.observe(toolbar_click, "value")
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 7 4 else: 5 toolbar.children = [toolbar_button] ----> 7 toolbar_button.observe(toolbar_click, "value") NameError: name 'toolbar_button' is not defined
In [5]:
Copied!
def close_click(change):
if change["new"]:
toolbar_button.close()
close_button.close()
toolbar.close()
close_button.observe(close_click, "value")
toolbar
def close_click(change):
if change["new"]:
toolbar_button.close()
close_button.close()
toolbar.close()
close_button.observe(close_click, "value")
toolbar
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 7 4 close_button.close() 5 toolbar.close() ----> 7 close_button.observe(close_click, "value") 8 toolbar NameError: name 'close_button' is not defined
Adding toolbar grid¶
In [6]:
Copied!
rows = 2
cols = 2
grid = widgets.GridspecLayout(rows, cols, grid_gap="0px", layout=widgets.Layout(width="62px"))
rows = 2
cols = 2
grid = widgets.GridspecLayout(rows, cols, grid_gap="0px", layout=widgets.Layout(width="62px"))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[6], line 3 1 rows = 2 2 cols = 2 ----> 3 grid = widgets.GridspecLayout(rows, cols, grid_gap="0px", layout=widgets.Layout(width="62px")) NameError: name 'widgets' is not defined
In [7]:
Copied!
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
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
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[7], line 5 3 for i in range(rows): 4 for j in range(cols): ----> 5 grid[i, j] = widgets.Button(description="", button_style="primary", icon=icons[i*rows+j], 6 layout=widgets.Layout(width="28px", padding="0px")) 7 grid NameError: name 'widgets' is not defined
In [8]:
Copied!
toolbar = widgets.VBox([toolbar_button])
toolbar = widgets.VBox([toolbar_button])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[8], line 1 ----> 1 toolbar = widgets.VBox([toolbar_button]) NameError: name 'widgets' is not defined
In [9]:
Copied!
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
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
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[9], line 7 4 else: 5 toolbar.children = [toolbar_button] ----> 7 toolbar_button.observe(toolbar_click, "value") 8 toolbar NameError: name 'toolbar_button' is not defined
Adding toolbar to ipyleaflet¶
In [10]:
Copied!
toolbar_ctrl = WidgetControl(widget=toolbar, position="topright")
toolbar_ctrl = WidgetControl(widget=toolbar, position="topright")
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[10], line 1 ----> 1 toolbar_ctrl = WidgetControl(widget=toolbar, position="topright") NameError: name 'WidgetControl' is not defined
In [11]:
Copied!
m = geodemo.Map()
m.add_control(toolbar_ctrl)
m
m = geodemo.Map()
m.add_control(toolbar_ctrl)
m
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[11], line 1 ----> 1 m = geodemo.Map() 2 m.add_control(toolbar_ctrl) 3 m NameError: name 'geodemo' is not defined
In [12]:
Copied!
output = widgets.Output()
output_ctrl = WidgetControl(widget=output, position="bottomright")
m.add_control(output_ctrl)
output = widgets.Output()
output_ctrl = WidgetControl(widget=output, position="bottomright")
m.add_control(output_ctrl)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[12], line 1 ----> 1 output = widgets.Output() 2 output_ctrl = WidgetControl(widget=output, position="bottomright") 3 m.add_control(output_ctrl) NameError: name 'widgets' is not defined
In [13]:
Copied!
def tool_click(b):
with output:
output.clear_output()
print(f"You clicked the {b.icon} button")
def tool_click(b):
with output:
output.clear_output()
print(f"You clicked the {b.icon} button")
In [14]:
Copied!
for i in range(rows):
for j in range(cols):
tool = grid[i, j]
tool.on_click(tool_click)
for i in range(rows):
for j in range(cols):
tool = grid[i, j]
tool.on_click(tool_click)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[14], line 3 1 for i in range(rows): 2 for j in range(cols): ----> 3 tool = grid[i, j] 4 tool.on_click(tool_click) NameError: name 'grid' is not defined
