-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure toolbar buttons toggle widgets, and turn off when widgets are closed. #1763
Changes from 7 commits
1ac3fad
baf65f3
a085486
8f927be
6d0d9e2
ef22459
75ffea1
4ba90ca
c5d8197
6701c97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -765,25 +765,37 @@ def add_layer( | |
|
||
addLayer = add_layer | ||
|
||
def _open_help_page(self, host_map: MapInterface, selected: bool) -> None: | ||
def _open_help_page( | ||
self, host_map: MapInterface, selected: bool, item: toolbar.Toolbar.Item | ||
) -> None: | ||
del host_map # Unused. | ||
del item # Unused. | ||
if selected: | ||
common.open_url("https://geemap.org") | ||
|
||
def _toolbar_main_tools(self) -> List[toolbar.Toolbar.Item]: | ||
@toolbar._cleanup_toolbar_item | ||
def inspector_tool_callback(map, _, item): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could you add type annotations here + call del on the unused properties? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
map.add("inspector") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be a great addition to the API, but I'm less inclined to make the change in this PR. |
||
return map._inspector | ||
|
||
@toolbar._cleanup_toolbar_item | ||
def basemap_tool_callback(map, _, item): | ||
map.add("basemap_selector") | ||
return map._basemap_selector | ||
|
||
return [ | ||
toolbar.Toolbar.Item( | ||
icon="map", | ||
tooltip="Basemap selector", | ||
callback=lambda m, selected: m.add("basemap_selector") | ||
if selected | ||
else None, | ||
callback=basemap_tool_callback, | ||
reset=False, | ||
), | ||
toolbar.Toolbar.Item( | ||
icon="info", | ||
tooltip="Inspector", | ||
callback=lambda m, selected: m.add("inspector") if selected else None, | ||
callback=inspector_tool_callback, | ||
reset=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: |
||
), | ||
toolbar.Toolbar.Item( | ||
icon="question", tooltip="Get help", callback=self._open_help_page | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,6 +522,14 @@ def __init__( | |
children=[self.toolbar_header, self.inspector_checks, self.tree_output] | ||
) | ||
|
||
def cleanup(self): | ||
"""Removes the widget from the map and performs cleanup.""" | ||
if self._host_map: | ||
self._host_map.default_style = {"cursor": "default"} | ||
self._host_map.on_interaction(self._on_map_interaction, remove=True) | ||
if self.on_close is not None: | ||
self.on_close() | ||
|
||
def _create_checkbox(self, title, checked): | ||
layout = ipywidgets.Layout(width="auto", padding="0px 6px 0px 0px") | ||
return ipywidgets.Checkbox( | ||
|
@@ -578,11 +586,7 @@ def _on_toolbar_btn_click(self, change): | |
|
||
def _on_close_btn_click(self, change): | ||
if change["new"]: | ||
if self._host_map: | ||
self._host_map.default_style = {"cursor": "default"} | ||
self._host_map.on_interaction(self._on_map_interaction, remove=True) | ||
if self.on_close is not None: | ||
self.on_close() | ||
self.cleanup() | ||
|
||
def _get_visible_map_layers(self): | ||
layers = {} | ||
|
@@ -896,9 +900,14 @@ def _on_dropdown_click(self, change): | |
if self.on_basemap_changed and change["new"]: | ||
self.on_basemap_changed(self._dropdown.value) | ||
|
||
def _on_close_click(self, _): | ||
def cleanup(self): | ||
if self.on_close: | ||
self.on_close() | ||
if hasattr(self, 'toggle_off'): | ||
self.toggle_off() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
|
||
def _on_close_click(self, _): | ||
self.cleanup() | ||
|
||
|
||
@Theme.apply | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
del host_map, item # Unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.