Skip to content

Commit

Permalink
Fixed toolbar GUI reset button bug (gee-community#1584)
Browse files Browse the repository at this point in the history
* Fix toolbar GUI bug

* Prep for v0.23.1
  • Loading branch information
giswqs authored Jun 24, 2023
1 parent 3f8cad3 commit f0afa51
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v0.23.1 - Jun 24, 2023

**New Features**

- Added create_grid function for zonal stats (#1582)

**Improvement**

- Fixed toolbar GUI bug (#1584)

## v0.23.0 - Jun 22, 2023

**Improvement**
Expand Down
23 changes: 17 additions & 6 deletions geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2573,8 +2573,9 @@ def to_image(self, filename=None, monitor=1):
def toolbar_reset(self):
"""Reset the toolbar so that no tool is selected."""
toolbar_grid = self.toolbar
for tool in toolbar_grid.children:
tool.value = False
if toolbar_grid is not None:
for tool in toolbar_grid.children:
tool.value = False

def add_raster(
self,
Expand Down Expand Up @@ -6335,7 +6336,13 @@ def inspect(self, latlon):
return tree

def add_inspector(
self, names=None, visible=True, decimals=2, position="topright", opened=True
self,
names=None,
visible=True,
decimals=2,
position="topright",
opened=True,
show_close_button=True,
):
"""Add the Inspector GUI to the map.
Expand All @@ -6349,17 +6356,21 @@ def add_inspector(
"""
from .toolbar import ee_inspector_gui

ee_inspector_gui(self, names, visible, decimals, position, opened)
ee_inspector_gui(
self, names, visible, decimals, position, opened, show_close_button
)

def add_layer_manager(self, position="topright", opened=True):
def add_layer_manager(
self, position="topright", opened=True, show_close_button=True
):
"""Add the Layer Manager to the map.
Args:
position (str, optional): The position of the Layer Manager. Defaults to "topright".
"""
from .toolbar import layer_manager_gui

layer_manager_gui(self, position, opened)
layer_manager_gui(self, position, opened, show_close_button=show_close_button)

def update_layer_manager(self):
"""Update the Layer Manager."""
Expand Down
30 changes: 24 additions & 6 deletions geemap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def button_clicked(change):
return toolbar_widget


def tool_header_template(m=None, opened=True):
def tool_header_template(m=None, opened=True, show_close_button=True):
"""Create a toolbar widget.
Args:
Expand Down Expand Up @@ -244,7 +244,10 @@ def tool_header_template(m=None, opened=True):
toolbar_widget = widgets.VBox()
toolbar_widget.children = [toolbar_button]
toolbar_header = widgets.HBox()
toolbar_header.children = [close_button, toolbar_button]
if show_close_button:
toolbar_header.children = [close_button, toolbar_button]
else:
toolbar_header.children = [toolbar_button]
toolbar_footer = widgets.VBox()
toolbar_footer.children = [
buttons,
Expand Down Expand Up @@ -4618,7 +4621,13 @@ def handle_search_event(event):


def ee_inspector_gui(
m, names=None, visible=True, decimals=2, position="topright", opened=True
m,
names=None,
visible=True,
decimals=2,
position="topright",
opened=True,
show_close_button=True,
):
"""Earth Engine Inspector GUI.
Expand All @@ -4629,6 +4638,7 @@ def ee_inspector_gui(
decimals (int, optional): The number of decimal places to round the values. Defaults to 2.
position (str, optional): The position of the control. Defaults to "topright".
opened (bool, optional): Whether the control is opened. Defaults to True.
show_close_button (bool, optional): Whether to show the close button. Defaults to True.
"""
from ipytree import Tree
Expand Down Expand Up @@ -4714,7 +4724,10 @@ def expand_objects_changed(change):
display(inspector_checks)

toolbar_header = widgets.HBox()
toolbar_header.children = [close_button, toolbar_button]
if show_close_button:
toolbar_header.children = [close_button, toolbar_button]
else:
toolbar_header.children = [toolbar_button]
toolbar_footer = widgets.VBox()
toolbar_footer.children = [inspector_output]
toolbar_widget = widgets.VBox()
Expand Down Expand Up @@ -4800,7 +4813,9 @@ def close_btn_click(change):
return toolbar_widget


def layer_manager_gui(m, position="topright", opened=True, return_widget=False):
def layer_manager_gui(
m, position="topright", opened=True, return_widget=False, show_close_button=True
):
"""Creates a layer manager widget.
Args:
Expand Down Expand Up @@ -5000,7 +5015,10 @@ def layer_chk_changed(change):
layers_hbox.append(hbox)
m.layer_widget = layers_hbox

toolbar_header.children = [close_button, layers_button]
if show_close_button:
toolbar_header.children = [close_button, layers_button]
else:
toolbar_header.children = [layers_button]
toolbar_footer.children = layers_hbox

else:
Expand Down

0 comments on commit f0afa51

Please sign in to comment.