Skip to content

Commit

Permalink
Fix ipywidget Output widget bug (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Jul 2, 2023
1 parent 461811c commit cce18bb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 104 deletions.
34 changes: 17 additions & 17 deletions geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def show_image(img_path, width=None, height=None):
out = widgets.Output()
# layout={'border': '1px solid black'})
# layout={'border': '1px solid black', 'width': str(width + 20) + 'px', 'height': str(height + 10) + 'px'},)
out.clear_output(wait=True)
out.outputs = ()
display(out)
with out:
if isinstance(img_path, str) and img_path.startswith("http"):
Expand Down Expand Up @@ -3489,7 +3489,7 @@ def show_youtube(id="h0pz3S6Tvx0"):
try:
out = widgets.Output(layout={"width": "815px"})
# layout={'border': '1px solid black', 'width': '815px'})
out.clear_output(wait=True)
out.outputs = ()
display(out)
with out:
display(YouTubeVideo(id, width=800, height=450))
Expand Down Expand Up @@ -4491,7 +4491,7 @@ def handle_click(event):
values = api_dict[name]

with output_widget:
output_widget.clear_output()
output_widget.outputs = ()
html_widget = widgets.HTML(value=values["html"])
display(html_widget)

Expand Down Expand Up @@ -4606,8 +4606,8 @@ def __init__(
def search_type_changed(change):
search_box.value = ""

output_widget.clear_output()
tree_widget.clear_output()
output_widget.outputs = ()
tree_widget.outputs = ()
if change["new"] == "Scripts":
search_box.placeholder = "Filter scripts..."
left_widget.children = [search_type, repo_tree]
Expand All @@ -4625,7 +4625,7 @@ def search_type_changed(change):
else:
ee_api_tree = flags.docs
with tree_widget:
tree_widget.clear_output()
tree_widget.outputs = ()
display(ee_api_tree)
right_widget.children = [output_widget]
search_box.value = ""
Expand All @@ -4643,7 +4643,7 @@ def search_type_changed(change):
flags.asset_import = asset_widget

with tree_widget:
tree_widget.clear_output()
tree_widget.outputs = ()
display(flags.assets)
right_widget.children = [flags.asset_import]
search_box.value = ""
Expand All @@ -4655,24 +4655,24 @@ def search_box_callback(text):
with tree_widget:
if text.value == "":
print("Loading...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
display(flags.docs)
else:
tree_widget.clear_output()
tree_widget.outputs = ()
print("Searching...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
sub_tree = search_api_tree(text.value, flags.docs_dict)
display(sub_tree)
elif search_type.value == "Assets":
with tree_widget:
if text.value == "":
print("Loading...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
display(flags.assets)
else:
tree_widget.clear_output()
tree_widget.outputs = ()
print("Searching...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
sub_tree = search_api_tree(text.value, flags.asset_dict)
display(sub_tree)

Expand Down Expand Up @@ -5041,12 +5041,12 @@ def search_box_callback(text):
with tree_widget:
if text.value == "":
print("Loading...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
display(tree)
else:
tree_widget.clear_output()
tree_widget.outputs = ()
print("Searching...")
tree_widget.clear_output(wait=True)
tree_widget.outputs = ()
sub_tree = search_api_tree(text.value, tree_dict)
display(sub_tree)

Expand Down Expand Up @@ -5139,7 +5139,7 @@ def handle_folder_click(event):
node.observe(handle_file_click, "selected")

with tree_widget:
tree_widget.clear_output()
tree_widget.outputs = ()
display(tree)

if return_sep_widgets:
Expand Down
24 changes: 12 additions & 12 deletions geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def __init__(self, **kwargs):

tool_output = widgets.Output()
self.tool_output = tool_output
tool_output.clear_output(wait=True)
tool_output.outputs = ()

if kwargs.get("toolbar_ctrl"):
self.add_toolbar()
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def plot(
if max_height is not None:
fig.layout.height = str(max_height) + "px"

plot_widget.clear_output(wait=True)
plot_widget.outputs = ()
if not overlay:
plt.clear()

Expand Down Expand Up @@ -1241,7 +1241,7 @@ def handle_interaction(**kwargs2):
except Exception as e:
if self.plot_widget is not None:
with self.plot_widget:
self.plot_widget.clear_output()
self.plot_widget.outputs = ()
print("No data for the clicked location.")
else:
print(e)
Expand Down Expand Up @@ -2037,7 +2037,7 @@ def add_colorbar(
transparent_bg=transparent_bg,
)
with output:
output.clear_output()
output.outputs = ()
plt.show()

self.colorbar = colormap_ctrl
Expand Down Expand Up @@ -2120,7 +2120,7 @@ def add_colorbar_branca(
**kwargs,
)
with output:
output.clear_output()
output.outputs = ()
display(colormap)

self.colorbar = colormap_ctrl
Expand Down Expand Up @@ -2888,7 +2888,7 @@ def classes_changed(change):

colorbar_output = self.colorbar_widget
with colorbar_output:
colorbar_output.clear_output()
colorbar_output.outputs = ()
plt.show()

if len(palette.value) > 0 and "," in palette.value:
Expand Down Expand Up @@ -3081,7 +3081,7 @@ def colormap_changed(change):

colorbar_output = self.colorbar_widget
with colorbar_output:
colorbar_output.clear_output()
colorbar_output.outputs = ()
plt.show()
# display(colorbar)

Expand Down Expand Up @@ -3208,7 +3208,7 @@ def apply_btn_clicked(b):
)
else:
if radio1.index == 0 and "palette" in vis:
self.colorbar_widget.clear_output()
self.colorbar_widget.outputs = ()
with self.colorbar_widget:
_, ax = plt.subplots(figsize=(6, 0.4))
colors = to_hex_colors(vis["palette"])
Expand Down Expand Up @@ -3313,7 +3313,7 @@ def legend_chk_changed(change):
[color.strip() for color in palette.value.split(",")]
)

self.colorbar_widget.clear_output()
self.colorbar_widget.outputs = ()
with self.colorbar_widget:
_, ax = plt.subplots(figsize=(6, 0.4))
cmap = mpl.colors.LinearSegmentedColormap.from_list(
Expand Down Expand Up @@ -3377,7 +3377,7 @@ def radio1_observer(sender):
if self.colorbar_ctrl not in self.controls:
self.add(self.colorbar_ctrl)

self.colorbar_widget.clear_output()
self.colorbar_widget.outputs = ()
with self.colorbar_widget:
plt.show()

Expand Down Expand Up @@ -3677,7 +3677,7 @@ def classes_changed(change):

colorbar_output = self.colorbar_widget
with colorbar_output:
colorbar_output.clear_output()
colorbar_output.outputs = ()
plt.show()

if len(palette.value) > 0 and "," in palette.value:
Expand Down Expand Up @@ -3724,7 +3724,7 @@ def colormap_changed(change):

colorbar_output = self.colorbar_widget
with colorbar_output:
colorbar_output.clear_output()
colorbar_output.outputs = ()
plt.show()
# display(colorbar)

Expand Down
Loading

0 comments on commit cce18bb

Please sign in to comment.